Skip to content

Commit

Permalink
feat-be: 평가 삭제 기능 (#950)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: HyungHoKim00 <[email protected]>
  • Loading branch information
github-actions[bot] and HyungHoKim00 authored Dec 17, 2024
1 parent 781d2b3 commit 1446b51
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/src/docs/asciidoc/evaluation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,4 +65,14 @@ public ResponseEntity<Void> update(
evaluationFacade.updateSingleEvaluation(request, evaluationId);
return ResponseEntity.ok().build();
}

@DeleteMapping("/{evaluationId}")
@ValidAuth
public ResponseEntity<Void> delete(
@RequireAuth(targetDomain = Evaluation.class) @PathVariable Long evaluationId,
LoginProfile loginProfile
) {
evaluationFacade.delete(evaluationId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 1446b51

Please sign in to comment.