Skip to content

Commit ebf0f90

Browse files
committed
refactor: trainee의 모든 수업 가져오도록 수정
1 parent d908e00 commit ebf0f90

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/main/java/com/tnt/application/pt/PtService.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,17 @@ private void validateLessonTime(PtTrainerTrainee ptTrainerTrainee, LocalDateTime
362362
}
363363

364364
private int validateAndGetNextSession(PtTrainerTrainee ptTrainerTrainee, LocalDateTime start) {
365-
List<PtLesson> notCompletedLessons =
366-
ptLessonRepository.findAllByPtTrainerTraineeAndIsCompletedIsFalseAndDeletedAtIsNull(ptTrainerTrainee);
365+
List<PtLesson> lessonsForTrainee =
366+
ptLessonRepository.findAllByPtTrainerTraineeAndDeletedAtIsNull(ptTrainerTrainee);
367367

368368
int temp = 0;
369369

370-
if (!notCompletedLessons.isEmpty()) {
371-
if (Objects.equals(notCompletedLessons.getLast().getSession(), ptTrainerTrainee.getTotalPtCount())) {
370+
if (!lessonsForTrainee.isEmpty()) {
371+
if (Objects.equals(lessonsForTrainee.getLast().getSession(), ptTrainerTrainee.getTotalPtCount())) {
372372
throw new ConflictException(PT_LESSON_OVERFLOW);
373373
}
374374

375-
for (PtLesson toCompare : notCompletedLessons) {
375+
for (PtLesson toCompare : lessonsForTrainee) {
376376
if (toCompare.getLessonStart().isBefore(start)) {
377377
temp += 1;
378378
} else {
@@ -381,8 +381,8 @@ private int validateAndGetNextSession(PtTrainerTrainee ptTrainerTrainee, LocalDa
381381
}
382382

383383
// 뒤에 있는 수업 회차 다시 +1 update
384-
for (int i = temp; i < notCompletedLessons.size(); i++) {
385-
PtLesson lesson = notCompletedLessons.get(i);
384+
for (int i = temp; i < lessonsForTrainee.size(); i++) {
385+
PtLesson lesson = lessonsForTrainee.get(i);
386386
lesson.increaseSession();
387387
}
388388
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.tnt.infrastructure.mysql.repository.pt;
22

33
import java.util.List;
4-
import java.util.Optional;
54

65
import org.springframework.data.jpa.repository.JpaRepository;
76

@@ -11,8 +10,4 @@
1110
public interface PtLessonRepository extends JpaRepository<PtLesson, Long> {
1211

1312
List<PtLesson> findAllByPtTrainerTraineeAndDeletedAtIsNull(PtTrainerTrainee ptTrainerTrainee);
14-
15-
Optional<PtLesson> findByIdAndDeletedAtIsNull(Long id);
16-
17-
List<PtLesson> findAllByPtTrainerTraineeAndIsCompletedIsFalseAndDeletedAtIsNull(PtTrainerTrainee ptTrainerTrainee);
1813
}

0 commit comments

Comments
 (0)