Skip to content

Commit c46862d

Browse files
committed
Feat: 멘토의 모든 일정 목록 조회
1 parent b629ab2 commit c46862d

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

back/src/main/java/com/back/domain/mentoring/slot/controller/MentorSlotController.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ public class MentorSlotController {
2828
private final MentorSlotService mentorSlotService;
2929
private final Rq rq;
3030

31+
@GetMapping
32+
@PreAuthorize("hasRole('MENTOR')")
33+
@Operation(summary = "멘토의 모든 슬롯 목록 조회", description = "멘토가 본인의 모든 슬롯(예약된 슬롯 포함) 목록을 조회합니다.")
34+
public RsData<List<MentorSlotDto>> getMyMentorSlots(
35+
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
36+
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate
37+
) {
38+
Member member = rq.getActor();
39+
40+
LocalDateTime startDateTime = startDate.atStartOfDay();
41+
LocalDateTime endDateTime = endDate.atStartOfDay();
42+
43+
List<MentorSlotDto> resDtoList = mentorSlotService.getMyMentorSlots(member, startDateTime, endDateTime);
44+
45+
return new RsData<>(
46+
"200",
47+
"나의 모든 일정 목록을 조회하였습니다.",
48+
resDtoList
49+
);
50+
}
51+
52+
3153
@GetMapping("/available/{mentorId}")
3254
@Operation(summary = "멘토의 예약 가능한 슬롯 목록 조회", description = "멘티가 특정 멘토의 예약 가능한 슬롯 목록을 조회합니다.")
3355
public RsData<List<MentorSlotDto>> getAvailableMentorSlots(

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ public interface MentorSlotRepository extends JpaRepository<MentorSlot, Long> {
1616
long countByMentorId(Long mentorId);
1717
void deleteAllByMentorId(Long mentorId);
1818

19+
@Query("""
20+
SELECT ms
21+
FROM MentorSlot ms
22+
WHERE ms.mentor.id = :mentorId
23+
AND ms.startDateTime < :end
24+
AND ms.endDateTime >= :start
25+
ORDER BY ms.startDateTime ASC
26+
""")
27+
List<MentorSlot> findMySlots(
28+
@Param("mentorId") Long mentorId,
29+
@Param("start") LocalDateTime start,
30+
@Param("end") LocalDateTime end
31+
);
32+
1933
@Query("""
2034
SELECT ms
2135
FROM MentorSlot ms

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ public class MentorSlotService {
3030
private final MentoringRepository mentoringRepository;
3131
private final ReservationRepository reservationRepository;
3232

33+
@Transactional(readOnly = true)
34+
public List<MentorSlotDto> getMyMentorSlots(Member member, LocalDateTime startDate, LocalDateTime endDate) {
35+
Mentor mentor = findMentorByMember(member);
36+
37+
DateTimeValidator.validateTime(startDate, endDate);
38+
39+
List<MentorSlot> availableSlots = mentorSlotRepository.findMySlots(mentor.getId(), startDate, endDate);
40+
41+
return availableSlots.stream()
42+
.map(MentorSlotDto::from)
43+
.toList();
44+
}
45+
3346
@Transactional(readOnly = true)
3447
public List<MentorSlotDto> getAvailableMentorSlots(Long mentorId, LocalDateTime startDate, LocalDateTime endDate) {
3548
validateMentorExists(mentorId);

back/src/test/java/com/back/domain/mentoring/slot/controller/MentorSlotControllerTest.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,38 @@ void setUp() {
7373
mentorSlots = mentoringFixture.createMentorSlots(mentor, baseDateTime, 2, 3);
7474
}
7575

76-
// ===== 슬롯 상세 조회 =====
76+
// ===== 슬롯 목록 조회 =====
77+
@Test
78+
@DisplayName("멘토가 본인의 모든 슬롯 목록 조회 성공")
79+
void getMyMentorSlotsSuccess() throws Exception {
80+
// 캘린더 기준 (월)
81+
LocalDateTime startDate = LocalDateTime.of(2025, 8, 31, 0, 0);
82+
LocalDateTime endDate = LocalDateTime.of(2025, 10, 5, 0, 0);
83+
84+
// 경계값
85+
mentoringFixture.createMentorSlot(mentor, endDate.minusMinutes(1), endDate.plusMinutes(10));
86+
mentoringFixture.createMentorSlot(mentor, startDate.minusMinutes(10), startDate);
87+
88+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
89+
90+
ResultActions resultActions = mvc.perform(
91+
get(MENTOR_SLOT_URL)
92+
.cookie(new Cookie(TOKEN, mentorToken))
93+
.param("startDate", startDate.format(formatter))
94+
.param("endDate", endDate.format(formatter))
95+
)
96+
.andDo(print());
97+
98+
resultActions
99+
.andExpect(status().isOk())
100+
.andExpect(handler().handlerType(MentorSlotController.class))
101+
.andExpect(handler().methodName("getMyMentorSlots"))
102+
.andExpect(jsonPath("$.resultCode").value("200"))
103+
.andExpect(jsonPath("$.msg").value("나의 모든 일정 목록을 조회하였습니다."))
104+
.andExpect(jsonPath("$.data").isArray())
105+
.andExpect(jsonPath("$.data.length()").value(8));
106+
}
107+
77108
@Test
78109
@DisplayName("멘토의 예약 가능한 슬롯 목록 조회(멘티) 성공")
79110
void getAvailableMentorSlotsSuccess() throws Exception {

0 commit comments

Comments
 (0)