Skip to content

Commit 0dc959a

Browse files
committed
Refactor: 서버 시간 기준으로 변경
1 parent 6759fe4 commit 0dc959a

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

back/src/main/java/com/back/domain/mentoring/slot/repository/MentorSlotRepository.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ List<MentorSlotDto> findMySlots(
5656
FROM MentorSlot ms
5757
WHERE ms.mentor.id = :mentorId
5858
AND ms.status = 'AVAILABLE'
59-
AND ms.startDateTime >= CURRENT_TIMESTAMP
59+
AND ms.startDateTime >= :now
6060
AND ms.startDateTime < :end
6161
AND ms.endDateTime >= :start
6262
ORDER BY ms.startDateTime ASC
6363
""")
6464
List<MentorSlotDto> findAvailableSlots(
6565
@Param("mentorId") Long mentorId,
6666
@Param("start") LocalDateTime start,
67-
@Param("end") LocalDateTime end
67+
@Param("end") LocalDateTime end,
68+
@Param("now") LocalDateTime now
6869
);
6970

7071
@Query("""

back/src/main/java/com/back/domain/mentoring/slot/service/MentorSlotService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public List<MentorSlotDto> getMyMentorSlots(Mentor mentor, LocalDateTime startDa
4343
public List<MentorSlotDto> getAvailableMentorSlots(Long mentorId, LocalDateTime startDate, LocalDateTime endDate) {
4444
DateTimeValidator.validateTime(startDate, endDate);
4545

46-
return mentorSlotRepository.findAvailableSlots(mentorId, startDate, endDate);
46+
LocalDateTime now = LocalDateTime.now();
47+
return mentorSlotRepository.findAvailableSlots(mentorId, startDate, endDate, now);
4748
}
4849

4950
@Transactional(readOnly = true)
@@ -163,7 +164,7 @@ public void expirePassedSlots() {
163164

164165
int updateCount = mentorSlotRepository.expirePassedSlots(now);
165166
if (updateCount > 0) {
166-
log.info("만료된 슬롯 {}개 업데이트 완료 at {}", now, updateCount);
167+
log.info("만료된 슬롯 {}개 업데이트 완료 at {}", updateCount, now);
167168
}
168169
}
169170

back/src/test/java/com/back/domain/mentoring/slot/service/MentorSlotServiceTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,17 @@ void getAvailableMentorSlots() {
174174
);
175175

176176
List<MentorSlotDto> availableSlots = List.of(slotDto1, slotDto2);
177+
LocalDateTime now = LocalDateTime.now();
177178

178-
when(mentorSlotRepository.findAvailableSlots(mentor1.getId(), startDate, endDate))
179+
when(mentorSlotRepository.findAvailableSlots(mentor1.getId(), startDate, endDate, now))
179180
.thenReturn(availableSlots);
180181

181182
// when
182183
List<MentorSlotDto> result = mentorSlotService.getAvailableMentorSlots(mentor1.getId(), startDate, endDate);
183184

184185
// then
185186
assertThat(result).hasSize(2);
186-
verify(mentorSlotRepository).findAvailableSlots(mentor1.getId(), startDate, endDate);
187+
verify(mentorSlotRepository).findAvailableSlots(mentor1.getId(), startDate, endDate, now);
187188
}
188189
}
189190

0 commit comments

Comments
 (0)