From ef99f196e397de722e91fc3763f0775ed30ed9dc Mon Sep 17 00:00:00 2001 From: Jonas Honecker Date: Sat, 29 Jun 2024 14:29:30 +0200 Subject: [PATCH] Renamed `NewTicket` and `UpdateTicket` to `...DTO` --- .../backend/ticket/TicketController.java | 12 ++++++------ .../backend/ticket/TicketService.java | 18 +++++++++--------- .../{NewTicket.java => NewTicketDTO.java} | 2 +- ...{UpdateTicket.java => UpdateTicketDTO.java} | 2 +- .../backend/ticket/TicketServiceTest.java | 12 ++++++------ 5 files changed, 23 insertions(+), 23 deletions(-) rename backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/{NewTicket.java => NewTicketDTO.java} (90%) rename backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/{UpdateTicket.java => UpdateTicketDTO.java} (91%) diff --git a/backend/src/main/java/com/github/jonashonecker/backend/ticket/TicketController.java b/backend/src/main/java/com/github/jonashonecker/backend/ticket/TicketController.java index 4566acb..5592e8d 100644 --- a/backend/src/main/java/com/github/jonashonecker/backend/ticket/TicketController.java +++ b/backend/src/main/java/com/github/jonashonecker/backend/ticket/TicketController.java @@ -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.*; @@ -23,12 +23,12 @@ public List 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); } } diff --git a/backend/src/main/java/com/github/jonashonecker/backend/ticket/TicketService.java b/backend/src/main/java/com/github/jonashonecker/backend/ticket/TicketService.java index 57a16c1..84ed6bd 100644 --- a/backend/src/main/java/com/github/jonashonecker/backend/ticket/TicketService.java +++ b/backend/src/main/java/com/github/jonashonecker/backend/ticket/TicketService.java @@ -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; @@ -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() )); diff --git a/backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/NewTicket.java b/backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/NewTicketDTO.java similarity index 90% rename from backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/NewTicket.java rename to backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/NewTicketDTO.java index 620c9a9..9a4bdef 100644 --- a/backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/NewTicket.java +++ b/backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/NewTicketDTO.java @@ -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") diff --git a/backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/UpdateTicket.java b/backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/UpdateTicketDTO.java similarity index 91% rename from backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/UpdateTicket.java rename to backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/UpdateTicketDTO.java index ea560d5..78fc2e0 100644 --- a/backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/UpdateTicket.java +++ b/backend/src/main/java/com/github/jonashonecker/backend/ticket/domain/UpdateTicketDTO.java @@ -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") diff --git a/backend/src/test/java/com/github/jonashonecker/backend/ticket/TicketServiceTest.java b/backend/src/test/java/com/github/jonashonecker/backend/ticket/TicketServiceTest.java index 0dd807c..c93e51f 100644 --- a/backend/src/test/java/com/github/jonashonecker/backend/ticket/TicketServiceTest.java +++ b/backend/src/test/java/com/github/jonashonecker/backend/ticket/TicketServiceTest.java @@ -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; @@ -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" ); @@ -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); @@ -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", @@ -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);