Skip to content

Commit

Permalink
refactor: 모임의 최적의 시간 API (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
f1v3-dev committed Sep 30, 2024
1 parent 0a2e0f8 commit cba57bd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ResponseEntity<MeetingInfoResponseDto> getMeetingInfo(@PathVariable("meet
/**
* 모임 시간을 조회하는 메서드입니다.
*
* @param uuid 조회할 모임 UUID
* @param uuid 조회할 모임 UUID
* @param pageable 페이징 정보 (default: page = 0, size = 10, sort = count)
* @return 200 (OK), body: 모임 시간 응답 DTO
*/
Expand All @@ -85,6 +85,17 @@ public ResponseEntity<PagedResponse<MeetingTimeResponseDto>> getMeetingTimes(
return ResponseEntity.ok(responseDto);
}

/**
* 모임의 최적 시간을 조회하는 메서드입니다.
*
* @param uuid 조회할 모임 UUID
* @return 200 (OK), body: 최적 시간
*/
@GetMapping("/{meetingUuid}/best-time")
public ResponseEntity<LocalDateTime> getBestTime(@PathVariable("meetingUuid") String uuid) {
return ResponseEntity.ok(meetingService.getBestTime(uuid));
}

/**
* 모임의 참여자를 조회하는 메서드입니다.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,12 @@ public interface MeetingRepositoryCustom {
* @return 모임 일정 할당 여부
*/
boolean existsByMemberIdAndMeetingUuid(Long memberId, String meetingUuid);

/**
* 모임 UUID로 최적의 시간을 조회합니다.
*
* @param uuid 모임 UUID
* @return 최적의 시간
*/
LocalDateTime getBestTime(String uuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,23 @@ public boolean existsByMemberIdAndMeetingUuid(Long memberId, String meetingUuid)
.fetchCount() > 0;

}

@Override
public LocalDateTime getBestTime(String uuid) {

QMeeting meeting = QMeeting.meeting;
QSchedule schedule = QSchedule.schedule;
QDateOfSchedule dateOfSchedule = QDateOfSchedule.dateOfSchedule;

return from(dateOfSchedule)
.join(dateOfSchedule.schedule, schedule)
.join(schedule.meeting, meeting)
.where(meeting.meetingUuid.eq(uuid))
.groupBy(dateOfSchedule.dateOfScheduleStart, dateOfSchedule.dateOfScheduleEnd)
.orderBy(dateOfSchedule.dateOfScheduleRank.count().desc(),
dateOfSchedule.dateOfScheduleRank.avg().asc(),
dateOfSchedule.dateOfScheduleStart.asc())
.select(dateOfSchedule.dateOfScheduleStart)
.fetchFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public MeetingParticipantResponseDto getParticipants(String uuid) {
return meetingRepository.getParticipant(uuid);
}

@Transactional(readOnly = true)
public LocalDateTime getBestTime(String uuid) {
return meetingRepository.getBestTime(uuid);
}

/**
* UUID를 생성하는 메서드입니다.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SecurityEndpointPaths {
"/api/v1/meetings/*/participants",
"/api/v1/meetings/*/schedules/guests/**",
"/api/v1/meetings/*/schedules/*",
"/api/v1/meetings/*/best-time",
};

public static final String[] USER_LIST = {
Expand Down

0 comments on commit cba57bd

Please sign in to comment.