-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 최소 시간을 보장하는 추천 로직 추가 #404
Changes from all commits
e600aea
621ed1a
42065aa
46e4631
d7b0449
f3c7c29
ab70b8d
f5955fd
c848d79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,9 +10,7 @@ | |||||
import kr.momo.domain.schedule.DateTimeInterval; | ||||||
import kr.momo.domain.schedule.RecommendInterval; | ||||||
|
||||||
public record CandidateSchedule( | ||||||
RecommendInterval dateTimeInterval, AttendeeGroup attendeeGroup | ||||||
) { | ||||||
public record CandidateSchedule(RecommendInterval dateTimeInterval, AttendeeGroup attendeeGroup) { | ||||||
|
||||||
public static CandidateSchedule of( | ||||||
LocalDateTime startDateTime, LocalDateTime endDateTime, AttendeeGroup attendeeGroup | ||||||
|
@@ -22,7 +20,8 @@ public static CandidateSchedule of( | |||||
|
||||||
public static List<CandidateSchedule> mergeContinuous( | ||||||
List<CandidateSchedule> sortedSchedules, | ||||||
BiPredicate<CandidateSchedule, CandidateSchedule> isContinuous | ||||||
BiPredicate<CandidateSchedule, CandidateSchedule> isContinuous, | ||||||
int minSize | ||||||
) { | ||||||
List<CandidateSchedule> mergedSchedules = new ArrayList<>(); | ||||||
int idx = 0; | ||||||
|
@@ -32,12 +31,20 @@ public static List<CandidateSchedule> mergeContinuous( | |||||
.takeWhile(i -> i == headIdx || isSequential(i, sortedSchedules, isContinuous)) | ||||||
.map(sortedSchedules::get) | ||||||
.toList(); | ||||||
addIfLongerThanOrEqualToMinTime(subList, mergedSchedules, minSize); | ||||||
idx += subList.size(); | ||||||
} | ||||||
return mergedSchedules; | ||||||
} | ||||||
|
||||||
private static void addIfLongerThanOrEqualToMinTime( | ||||||
List<CandidateSchedule> subList, List<CandidateSchedule> mergedSchedules, int minSize | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
일반적으로 사용되는 메서드 명명법을 따라 볼까요? 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오호 이 부분은 흥미롭네요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음.. 별도로 레퍼런스가 있다기보다는 보통 영문에서 자바 계열에서는 JUnit의 검증 메서드 명명법을 참고하기는 합니다. 저 메서드 보자마자 JUnit의 |
||||||
) { | ||||||
if (minSize <= subList.size()) { | ||||||
subList.stream() | ||||||
.reduce(CandidateSchedule::merge) | ||||||
.ifPresent(mergedSchedules::add); | ||||||
idx += subList.size(); | ||||||
} | ||||||
return mergedSchedules; | ||||||
} | ||||||
|
||||||
private static boolean isSequential( | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,7 +122,9 @@ public AttendeeScheduleResponse findMySchedule(String uuid, long attendeeId) { | |
} | ||
|
||
@Transactional(readOnly = true) | ||
public RecommendedSchedulesResponse recommendSchedules(String uuid, String recommendType, List<String> names) { | ||
public RecommendedSchedulesResponse recommendSchedules( | ||
String uuid, String recommendType, List<String> names, int minimumTime | ||
) { | ||
Meeting meeting = meetingRepository.findByUuid(uuid) | ||
.orElseThrow(() -> new MomoException(MeetingErrorCode.NOT_FOUND_MEETING)); | ||
AttendeeGroup attendeeGroup = new AttendeeGroup(attendeeRepository.findAllByMeeting(meeting)); | ||
|
@@ -131,11 +133,13 @@ public RecommendedSchedulesResponse recommendSchedules(String uuid, String recom | |
ScheduleRecommender recommender = scheduleRecommenderFactory.getRecommenderOf( | ||
attendeeGroup, filteredGroup | ||
); | ||
List<CandidateSchedule> recommendedResult = recommender.recommend(filteredGroup, recommendType, | ||
meeting.getType()); | ||
List<CandidateSchedule> recommendedResult = recommender.recommend( | ||
filteredGroup, recommendType, meeting.getType(), minimumTime | ||
); | ||
|
||
List<RecommendedScheduleResponse> scheduleResponses = RecommendedScheduleResponse.fromCandidateSchedules( | ||
recommendedResult); | ||
recommendedResult | ||
); | ||
Comment on lines
+141
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다온이 만든 코드는 아니지만 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 작업은 리팩토링 이슈로 분리하여 다뤄봐도 좋을 것 같네요 |
||
return RecommendedSchedulesResponse.of(meeting.getType(), scheduleResponses); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package kr.momo.service.schedule.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import java.util.List; | ||
|
||
@Schema(description = "일정 추천 요청") | ||
public record ScheduleRecommendRequest( | ||
|
||
@NotEmpty | ||
@Schema(description = "추천 기준(이른 시간 순 / 길게 볼 수 있는 순)", example = "earliest") | ||
String recommendType, | ||
|
||
@NotEmpty | ||
@Schema(description = "추천 대상 참여자 이름", example = "페드로, 재즈, 모모") | ||
List<String> attendeeNames, | ||
|
||
@Schema(description = "최소 만남 시간(시간 단위)", example = "0, 1, 2, 3") | ||
@Min(value = 0, message = "최소 시간은 0보다 작을 수 없습니다.") | ||
Integer minTime | ||
) { | ||
|
||
public ScheduleRecommendRequest { | ||
if (minTime == null) { | ||
minTime = 0; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기본값 설정👍