File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
src/main/java/com/threestar/trainus/domain/lesson/teacher Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 77import org .springframework .data .domain .Page ;
88import org .springframework .data .domain .Pageable ;
99import org .springframework .data .jpa .repository .JpaRepository ;
10+ import org .springframework .data .jpa .repository .Lock ;
1011import org .springframework .data .jpa .repository .Query ;
1112import org .springframework .data .repository .query .Param ;
1213
1314import com .threestar .trainus .domain .lesson .teacher .entity .Category ;
1415import com .threestar .trainus .domain .lesson .teacher .entity .Lesson ;
1516import com .threestar .trainus .domain .lesson .teacher .entity .LessonStatus ;
1617
18+ import jakarta .persistence .LockModeType ;
19+
1720public interface LessonRepository extends JpaRepository <Lesson , Long > {
1821 //삭제되지 않은 레슨만 조회
1922 Optional <Lesson > findByIdAndDeletedAtIsNull (Long lessonId );
@@ -107,4 +110,8 @@ WHERE l.status IN (
107110 AND l.deletedAt IS NULL
108111 """ )
109112 List <Lesson > findLessonsToComplete (@ Param ("now" ) LocalDateTime now );
113+
114+ @ Lock (LockModeType .PESSIMISTIC_WRITE ) // 비관적 락 적용
115+ @ Query ("SELECT l FROM Lesson l WHERE l.id = :lessonId" )
116+ Optional <Lesson > findByIdWithLock (@ Param ("lessonId" ) Long lessonId );
110117}
Original file line number Diff line number Diff line change @@ -458,6 +458,12 @@ public Lesson findLessonById(Long lessonId) {
458458 .orElseThrow (() -> new BusinessException (ErrorCode .LESSON_NOT_FOUND ));
459459 }
460460
461+ // develop 브랜치에서 추가된 메서드 - Lock 기능 추가
462+ public Lesson findLessonByIdWithLock (Long lessonId ) {
463+ return lessonRepository .findByIdWithLock (lessonId )
464+ .orElseThrow (() -> new BusinessException (ErrorCode .LESSON_NOT_FOUND ));
465+ }
466+
461467 //레슨 신청 조회
462468 public LessonApplication findApplicationById (Long applicationId ) {
463469 return lessonApplicationRepository .findById (applicationId )
You can’t perform that action at this time.
0 commit comments