Skip to content

Commit 62ba7e5

Browse files
committed
fix:conflict 해결
1 parent 7657354 commit 62ba7e5

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/java/com/threestar/trainus/domain/lesson/teacher/repository/LessonRepository.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
import org.springframework.data.domain.Page;
88
import org.springframework.data.domain.Pageable;
99
import org.springframework.data.jpa.repository.JpaRepository;
10+
import org.springframework.data.jpa.repository.Lock;
1011
import org.springframework.data.jpa.repository.Query;
1112
import org.springframework.data.repository.query.Param;
1213

1314
import com.threestar.trainus.domain.lesson.teacher.entity.Category;
1415
import com.threestar.trainus.domain.lesson.teacher.entity.Lesson;
1516
import com.threestar.trainus.domain.lesson.teacher.entity.LessonStatus;
1617

18+
import jakarta.persistence.LockModeType;
19+
1720
public 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
}

src/main/java/com/threestar/trainus/domain/lesson/teacher/service/AdminLessonService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)