Skip to content

Commit

Permalink
✨ 중복 피드백 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
rilac1 committed Feb 19, 2023
1 parent 89ab2c5 commit 44153c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import yapp.allround3.feedback.domain.Feedback;
import yapp.allround3.participant.domain.Participant;
import yapp.allround3.task.domain.Task;

import java.util.List;
import java.util.Optional;

@Repository
public interface FeedbackRepository extends JpaRepository<Feedback,Long> {
List<Feedback> findByTask(Task task);

Optional<Feedback> findByTaskAndParticipant(Task task, Participant participant);
}
10 changes: 10 additions & 0 deletions src/main/java/yapp/allround3/feedback/service/FeedbackService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public void saveFeedback(FeedbackRequest feedbackRequest) {
throw new CustomException("자신의 업무는 피드백 할 수 없습니다.");
}

if (existFeedbackHistory(task, participant)) {
throw new CustomException("이미 피드백을 제출하였습니다.");
}


List<Integer> checklist = feedbackRequest.getChecklist();

for (Integer templateId : checklist) {
Expand Down Expand Up @@ -77,4 +82,9 @@ public CustomResponse<FeedbackResponse> findFeedbacks(Long taskId) {

return CustomResponse.success(result);
}

private boolean existFeedbackHistory(Task task, Participant participant) {
return feedbackRepository.findByTaskAndParticipant(task, participant)
.isPresent();
}
}

0 comments on commit 44153c3

Please sign in to comment.