Skip to content

Commit

Permalink
fix: 업데이트를 위한 포인트 조회와 일반 조회를 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
dongchandev committed Aug 20, 2024
1 parent eaeb520 commit 88b1877
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Response cancel(Integer id) {
Point point = pointService.getPointBy(id);
PointReason reason = point.getReason();
Student student = point.getStudent();
PointScore score = pointService.getScoreBy(student);
PointScore score = pointService.getScoreByStudentForUpdate(student);
score.cancel(reason);

pointService.delete(point);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface PointScoreRepository extends JpaRepository<PointScore, Integer>
@Query("SELECT ps FROM PointScore ps WHERE ps.student = :student")
Optional<PointScore> findByStudentWithPessimisticLock(Student student);

Optional<PointScore> findByStudent(Student student);

@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("SELECT ps FROM PointScore ps WHERE ps.student IN :students")
List<PointScore> findByStudentInWithPessimisticLock(List<Student> students);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public List<Point> getPointsBy(Student student, PointType type) {
}

public PointScore getScoreBy(Student student) {
return scoreRepository.findByStudent(student)
.orElseThrow(PointScoreNotFoundException::new);
}

public PointScore getScoreByStudentForUpdate(Student student) {
return scoreRepository.findByStudentWithPessimisticLock(student)
.orElseThrow(PointScoreNotFoundException::new);
}
Expand Down

0 comments on commit 88b1877

Please sign in to comment.