diff --git a/backend/src/docs/asciidoc/evaluation.adoc b/backend/src/docs/asciidoc/evaluation.adoc index 0a125b5f0..f034a2128 100644 --- a/backend/src/docs/asciidoc/evaluation.adoc +++ b/backend/src/docs/asciidoc/evaluation.adoc @@ -45,3 +45,9 @@ operation::evaluation/update-fail/evaluation-not-found[snippets="http-request,re ==== 실패: 조건에 맞지 않는 평가 점수 operation::evaluation/update-fail/invalid-score[snippets="http-request,request-cookies,path-parameters,request-fields,http-response"] + +=== 평가 삭제 + +==== 성공 + +operation::evaluation/delete[snippets="http-request,request-cookies,path-parameters,http-response"] diff --git a/backend/src/main/java/com/cruru/applicant/controller/EvaluationController.java b/backend/src/main/java/com/cruru/applicant/controller/EvaluationController.java index 59b4c87a6..7f06f2875 100644 --- a/backend/src/main/java/com/cruru/applicant/controller/EvaluationController.java +++ b/backend/src/main/java/com/cruru/applicant/controller/EvaluationController.java @@ -14,6 +14,7 @@ import java.net.URI; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -64,4 +65,14 @@ public ResponseEntity update( evaluationFacade.updateSingleEvaluation(request, evaluationId); return ResponseEntity.ok().build(); } + + @DeleteMapping("/{evaluationId}") + @ValidAuth + public ResponseEntity delete( + @RequireAuth(targetDomain = Evaluation.class) @PathVariable Long evaluationId, + LoginProfile loginProfile + ) { + evaluationFacade.delete(evaluationId); + return ResponseEntity.noContent().build(); + } } diff --git a/backend/src/main/java/com/cruru/applicant/facade/EvaluationFacade.java b/backend/src/main/java/com/cruru/applicant/facade/EvaluationFacade.java index e8a41d6b1..0a48bc2bb 100644 --- a/backend/src/main/java/com/cruru/applicant/facade/EvaluationFacade.java +++ b/backend/src/main/java/com/cruru/applicant/facade/EvaluationFacade.java @@ -61,4 +61,9 @@ public void updateSingleEvaluation(EvaluationUpdateRequest request, Long evaluat Evaluation evaluation = evaluationService.findById(evaluationId); evaluationService.update(request, evaluation); } + + @Transactional + public void delete(long evaluationId) { + evaluationService.delete(evaluationId); + } } diff --git a/backend/src/main/java/com/cruru/applicant/service/EvaluationService.java b/backend/src/main/java/com/cruru/applicant/service/EvaluationService.java index ef4b43600..42079a8fa 100644 --- a/backend/src/main/java/com/cruru/applicant/service/EvaluationService.java +++ b/backend/src/main/java/com/cruru/applicant/service/EvaluationService.java @@ -52,6 +52,11 @@ private boolean changeExists(EvaluationUpdateRequest request, Evaluation evaluat return !(evaluation.getContent().equals(request.content()) && evaluation.getScore().equals(request.score())); } + @Transactional + public void delete(long evaluationId) { + evaluationRepository.deleteById(evaluationId); + } + @Transactional public void deleteByProcess(long processId) { evaluationRepository.deleteByProcessId(processId); diff --git a/backend/src/test/java/com/cruru/applicant/controller/EvaluationControllerTest.java b/backend/src/test/java/com/cruru/applicant/controller/EvaluationControllerTest.java index 18a824625..c85aeef40 100644 --- a/backend/src/test/java/com/cruru/applicant/controller/EvaluationControllerTest.java +++ b/backend/src/test/java/com/cruru/applicant/controller/EvaluationControllerTest.java @@ -359,4 +359,22 @@ void update_invalidScore() { .when().patch("/v1/evaluations/{evaluationId}", evaluation.getId()) .then().log().all().statusCode(400); } + + @DisplayName("평가 삭제 시 204를 응답한다.") + @Test + void delete() { + // given + Evaluation evaluation = evaluationRepository.save(EvaluationFixture.fivePoints()); + + // when&then + RestAssured.given(spec).log().all() + .cookie("accessToken", token) + .filter(document( + "evaluation/delete", + requestCookies(cookieWithName("accessToken").description("사용자 토큰")), + pathParameters(parameterWithName("evaluationId").description("삭제할 평가 id")) + )) + .when().delete("/v1/evaluations/{evaluationId}", evaluation.getId()) + .then().log().all().statusCode(204); + } } diff --git a/backend/src/test/java/com/cruru/applicant/facade/EvaluationFacadeTest.java b/backend/src/test/java/com/cruru/applicant/facade/EvaluationFacadeTest.java index 5e52debf5..b9352210e 100644 --- a/backend/src/test/java/com/cruru/applicant/facade/EvaluationFacadeTest.java +++ b/backend/src/test/java/com/cruru/applicant/facade/EvaluationFacadeTest.java @@ -103,4 +103,17 @@ void readEvaluationsOfApplicantInProcess() { ); } + + @DisplayName("평가를 삭제한다.") + @Test + void delete() { + // given + Evaluation evaluation = evaluationRepository.save(EvaluationFixture.fivePoints()); + + // when + evaluationFacade.delete(evaluation.getId()); + + // then + assertThat(evaluationRepository.findById(evaluation.getId())).isEmpty(); + } } diff --git a/backend/src/test/java/com/cruru/applicant/service/EvaluationServiceTest.java b/backend/src/test/java/com/cruru/applicant/service/EvaluationServiceTest.java index 8b1756edb..8258894ce 100644 --- a/backend/src/test/java/com/cruru/applicant/service/EvaluationServiceTest.java +++ b/backend/src/test/java/com/cruru/applicant/service/EvaluationServiceTest.java @@ -151,4 +151,17 @@ void deleteAllByProcesses() { assertThat(evaluationRepository.findAll()).contains(evaluation3) .doesNotContain(evaluation1, evaluation2); } + + @DisplayName("평가를 삭제한다.") + @Test + void delete() { + // given + Evaluation evaluation = evaluationRepository.save(EvaluationFixture.fivePoints()); + + // when + evaluationService.delete(evaluation.getId()); + + // then + assertThat(evaluationRepository.findById(evaluation.getId())).isEmpty(); + } }