From 4c44b843ae11836b63d86014dee971a5fa394d7d Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 2 Oct 2024 11:27:25 +0200 Subject: [PATCH] refactor: simplify project deletion logic in action class --- .../szut/lf8_starter/project/action/RemoveProjectAction.java | 3 +-- .../integration/project/DeleteProjectActionTest.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/szut/lf8_starter/project/action/RemoveProjectAction.java b/src/main/java/de/szut/lf8_starter/project/action/RemoveProjectAction.java index 4d93a28..767c22d 100644 --- a/src/main/java/de/szut/lf8_starter/project/action/RemoveProjectAction.java +++ b/src/main/java/de/szut/lf8_starter/project/action/RemoveProjectAction.java @@ -33,12 +33,11 @@ public class RemoveProjectAction { @DeleteMapping("/{id}") public ResponseEntity findArticleById(@PathVariable Long id) { Optional project = this.projectService.findById(id); - if (project.isEmpty()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - this.projectService.delete(project.get().getId()); + this.projectService.delete(id); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } } diff --git a/src/test/java/de/szut/lf8_starter/integration/project/DeleteProjectActionTest.java b/src/test/java/de/szut/lf8_starter/integration/project/DeleteProjectActionTest.java index 070fbe9..6d9ee5b 100644 --- a/src/test/java/de/szut/lf8_starter/integration/project/DeleteProjectActionTest.java +++ b/src/test/java/de/szut/lf8_starter/integration/project/DeleteProjectActionTest.java @@ -26,7 +26,6 @@ public class DeleteProjectActionTest { @Test void deleteProjectTest() throws Exception { var project = new ProjectEntity(); - project.setId(20); project.setComment("comment"); project.setContractor(1); project.setContractorName("contractorName"); @@ -37,7 +36,7 @@ public class DeleteProjectActionTest { project.setEmployees(List.of(1L, 2L, 3L)); this.projectRepository.save(project); - this.mockMvc.perform(delete("/projects/20")) + this.mockMvc.perform(delete("/projects/" + project.getId())) .andExpect(status().isNoContent()); }