refactor: simplify project deletion logic in action class
This commit is contained in:
parent
4abce554e5
commit
4c44b843ae
@ -33,12 +33,11 @@ public class RemoveProjectAction {
|
|||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public ResponseEntity<GetProjectDto> findArticleById(@PathVariable Long id) {
|
public ResponseEntity<GetProjectDto> findArticleById(@PathVariable Long id) {
|
||||||
Optional<ProjectEntity> project = this.projectService.findById(id);
|
Optional<ProjectEntity> project = this.projectService.findById(id);
|
||||||
|
|
||||||
if (project.isEmpty()) {
|
if (project.isEmpty()) {
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.projectService.delete(project.get().getId());
|
this.projectService.delete(id);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ public class DeleteProjectActionTest {
|
|||||||
@Test
|
@Test
|
||||||
void deleteProjectTest() throws Exception {
|
void deleteProjectTest() throws Exception {
|
||||||
var project = new ProjectEntity();
|
var project = new ProjectEntity();
|
||||||
project.setId(20);
|
|
||||||
project.setComment("comment");
|
project.setComment("comment");
|
||||||
project.setContractor(1);
|
project.setContractor(1);
|
||||||
project.setContractorName("contractorName");
|
project.setContractorName("contractorName");
|
||||||
@ -37,7 +36,7 @@ public class DeleteProjectActionTest {
|
|||||||
project.setEmployees(List.of(1L, 2L, 3L));
|
project.setEmployees(List.of(1L, 2L, 3L));
|
||||||
this.projectRepository.save(project);
|
this.projectRepository.save(project);
|
||||||
|
|
||||||
this.mockMvc.perform(delete("/projects/20"))
|
this.mockMvc.perform(delete("/projects/" + project.getId()))
|
||||||
.andExpect(status().isNoContent());
|
.andExpect(status().isNoContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user