Skip to content

Commit

Permalink
Renamed NewTicket and UpdateTicket to ...DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashonecker committed Jun 29, 2024
1 parent c7214ca commit ef99f19
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.jonashonecker.backend.ticket;

import com.github.jonashonecker.backend.ticket.domain.NewTicket;
import com.github.jonashonecker.backend.ticket.domain.NewTicketDTO;
import com.github.jonashonecker.backend.ticket.domain.Ticket;
import com.github.jonashonecker.backend.ticket.domain.UpdateTicket;
import com.github.jonashonecker.backend.ticket.domain.UpdateTicketDTO;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

Expand All @@ -23,12 +23,12 @@ public List<Ticket> getAllTickets() {
}

@PostMapping
public Ticket createTicket(@Valid @RequestBody NewTicket newTicket) {
return ticketService.createTicket(newTicket);
public Ticket createTicket(@Valid @RequestBody NewTicketDTO newTicketDTO) {
return ticketService.createTicket(newTicketDTO);
}

@PutMapping
public Ticket updateTicket(@Valid @RequestBody UpdateTicket updateTicket) {
return ticketService.updateTicket(updateTicket);
public Ticket updateTicket(@Valid @RequestBody UpdateTicketDTO updateTicketDTO) {
return ticketService.updateTicket(updateTicketDTO);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.jonashonecker.backend.ticket;

import com.github.jonashonecker.backend.ticket.domain.NewTicket;
import com.github.jonashonecker.backend.ticket.domain.NewTicketDTO;
import com.github.jonashonecker.backend.ticket.domain.Status;
import com.github.jonashonecker.backend.ticket.domain.Ticket;
import com.github.jonashonecker.backend.ticket.domain.UpdateTicket;
import com.github.jonashonecker.backend.ticket.domain.UpdateTicketDTO;
import com.github.jonashonecker.backend.ticket.exception.NoSuchTicketException;
import com.github.jonashonecker.backend.user.UserService;
import org.springframework.stereotype.Service;
Expand All @@ -30,26 +30,26 @@ public Ticket getTicketById(String id) {
return ticketRepository.findById(id).orElseThrow(() -> new NoSuchTicketException("Could not find ticket with id: " + id));
}

public Ticket createTicket(NewTicket newTicket) {
public Ticket createTicket(NewTicketDTO newTicketDTO) {
String defaultProjectName = "Default Project";
Status defaultStatus = Status.OPEN;
return ticketRepository.insert(new Ticket(
idService.getUUID(),
defaultProjectName,
newTicket.title(),
newTicket.description(),
newTicketDTO.title(),
newTicketDTO.description(),
defaultStatus,
userService.getCurrentUser()
));
}

public Ticket updateTicket(UpdateTicket updateTicket) {
Ticket existingTicket = getTicketById(updateTicket.id());
public Ticket updateTicket(UpdateTicketDTO updateTicketDTO) {
Ticket existingTicket = getTicketById(updateTicketDTO.id());
return ticketRepository.save(new Ticket(
existingTicket.id(),
existingTicket.projectName(),
updateTicket.title(),
updateTicket.description(),
updateTicketDTO.title(),
updateTicketDTO.description(),
existingTicket.status(),
existingTicket.author()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jakarta.validation.constraints.NotBlank;

public record NewTicket(
public record NewTicketDTO(
@NotBlank(message = "Title must not be empty")
String title,
@NotBlank(message = "Description must not be empty")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jakarta.validation.constraints.NotBlank;

public record UpdateTicket(
public record UpdateTicketDTO(
@NotBlank(message = "Id must not be empty")
String id,
@NotBlank(message = "Title must not be empty")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.jonashonecker.backend.ticket;

import com.github.jonashonecker.backend.ticket.domain.NewTicket;
import com.github.jonashonecker.backend.ticket.domain.NewTicketDTO;
import com.github.jonashonecker.backend.ticket.domain.Status;
import com.github.jonashonecker.backend.ticket.domain.Ticket;
import com.github.jonashonecker.backend.ticket.domain.UpdateTicket;
import com.github.jonashonecker.backend.ticket.domain.UpdateTicketDTO;
import com.github.jonashonecker.backend.ticket.exception.NoSuchTicketException;
import com.github.jonashonecker.backend.user.UserService;
import com.github.jonashonecker.backend.user.domain.TicketScoutUser;
Expand Down Expand Up @@ -98,7 +98,7 @@ void createTicket_whenNewTicket_thenReturnsTicketWithDefaultProjectAndStatus() {
String defaultProject = "Default Project";
Status defaultStatus = Status.OPEN;
TicketScoutUser ticketScoutUser = new TicketScoutUser("test-name", "test-avatarUrl");
NewTicket newTicket = new NewTicket(
NewTicketDTO newTicketDTO = new NewTicketDTO(
"test-title",
"test-description"
);
Expand All @@ -117,7 +117,7 @@ void createTicket_whenNewTicket_thenReturnsTicketWithDefaultProjectAndStatus() {
when(ticketRepository.insert(any(Ticket.class))).thenReturn(expected);

//WHEN
Ticket actual = ticketService.createTicket(newTicket);
Ticket actual = ticketService.createTicket(newTicketDTO);

//THEN
verify(ticketRepository, times(1)).insert(expected);
Expand All @@ -131,7 +131,7 @@ void updateTicket_whenUpdateTicketTitle_returnTicketWithUpdatedTitle() {
//GIVEN
String id = "test-id";
String description = "test-description";
UpdateTicket updateTicket = new UpdateTicket(id, "new-updated-title", description);
UpdateTicketDTO updateTicketDTO = new UpdateTicketDTO(id, "new-updated-title", description);
Ticket ticketInDb = new Ticket(
id,
"test-projectName",
Expand All @@ -152,7 +152,7 @@ void updateTicket_whenUpdateTicketTitle_returnTicketWithUpdatedTitle() {
when(ticketRepository.save(expected)).thenReturn(expected);

//WHEN
Ticket actual = ticketService.updateTicket(updateTicket);
Ticket actual = ticketService.updateTicket(updateTicketDTO);

//THEN
verify(ticketRepository, times(1)).save(expected);
Expand Down

0 comments on commit ef99f19

Please sign in to comment.