-
Notifications
You must be signed in to change notification settings - Fork 2
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
#317 [feat] 엔티티 변경으로 인한 종합 일정 시간표 로직 리팩토링 #324
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e394dac
#317 [chore] register dto 폴더 변경
sohyundoh bb6d9ef
#317 [chore] register dto 폴더 변경
sohyundoh cf40a1e
#317 [feat] Response Dto Class -> record
sohyundoh 35c0204
#317 [feat] retrieve dto 정의
sohyundoh fce20b5
#317 [feat] 종합 일정 시간표 로직 구현
sohyundoh 9e40ecf
#317 [test] 종합 일정 시간표 test 코드 작성
sohyundoh 4d6a61b
#317 [fix] weight 반영 안됨 오류 해결
sohyundoh e051ed4
#317 [chore] register dto 폴더 변경
sohyundoh cf752a8
#317 [test] 테스트 코드 수정
sohyundoh 1773755
#317 [refactor] TimeSlotRetrieve -> TimeBlock으로 변경
sohyundoh a5824c4
#317 [feat] 회의 참여자 조회 방식 변경
sohyundoh 45813c3
#317 [test] 불필요 stub 제거
sohyundoh f8b661e
#317 [feat] 미사용 메서드 제거
sohyundoh 2402bcb
#317 [refactor] 미사용 메서드 제거
sohyundoh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,22 @@ | |
import com.asap.server.service.meeting.dto.UserDto; | ||
import com.asap.server.service.time.MeetingTimeRecommendService; | ||
import com.asap.server.service.time.UserMeetingScheduleService; | ||
import com.asap.server.service.time.dto.retrieve.AvailableDatesRetrieveDto; | ||
import com.asap.server.service.time.dto.retrieve.TimeSlotRetrieveDto; | ||
import com.asap.server.service.time.dto.retrieve.TimeTableRetrieveDto; | ||
import com.asap.server.service.time.vo.BestMeetingTimeVo; | ||
import com.asap.server.service.time.vo.BestMeetingTimeWithUsers; | ||
import com.asap.server.service.time.vo.TimeBlockVo; | ||
import com.asap.server.service.user.UserRetrieveService; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
|
@@ -81,4 +89,67 @@ private BestMeetingTimeWithUsers mapToBestMeetingTimeWithUsers( | |
userDtos | ||
); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public TimeTableRetrieveDto getTimeTable(final Long meetingId, final Long userId) { | ||
Meeting meeting = meetingRepository.findById(meetingId) | ||
.orElseThrow(() -> new NotFoundException(Error.MEETING_NOT_FOUND_EXCEPTION)); | ||
|
||
if (!meeting.authenticateHost(userId)) { | ||
throw new UnauthorizedException(Error.INVALID_MEETING_HOST_EXCEPTION); | ||
} | ||
if (meeting.isConfirmedMeeting()) { | ||
throw new ConflictException(MEETING_VALIDATION_FAILED_EXCEPTION); | ||
} | ||
|
||
List<String> userNames = userRetrieveService.getUsersFromMeetingId(meetingId).stream().map(User::getName).toList(); | ||
|
||
return TimeTableRetrieveDto.of(userNames, getAvailableDatesDto(meetingId, userNames.size())); | ||
|
||
} | ||
|
||
private List<AvailableDatesRetrieveDto> getAvailableDatesDto(final Long meetingId, final int totalUserCount) { | ||
List<TimeBlockVo> timeBlockVos = userMeetingScheduleService.getTimeBlocks(meetingId); | ||
|
||
Map<LocalDate, List<TimeSlotRetrieveDto>> timeSlotDtoMappedByDate = getTimeTableMapFromTimeBlockVo(timeBlockVos, totalUserCount); | ||
|
||
return timeSlotDtoMappedByDate.keySet().stream().map( | ||
date -> AvailableDatesRetrieveDto.of( | ||
date, | ||
timeSlotDtoMappedByDate.get(date) | ||
) | ||
).toList(); | ||
} | ||
|
||
private Map<LocalDate, List<TimeSlotRetrieveDto>> getTimeTableMapFromTimeBlockVo(final List<TimeBlockVo> timeBlockVo, final int totalUserCount) { | ||
return timeBlockVo.stream() | ||
.collect(Collectors.groupingBy( | ||
TimeBlockVo::availableDate, | ||
Collectors.mapping(t -> new TimeSlotRetrieveDto( | ||
t.timeSlot().getTime(), | ||
userRetrieveService.getUserNamesFromId(t.userIds()), | ||
setColorLevel(totalUserCount, t.userIds().size()) | ||
), | ||
Collectors.toList() | ||
) | ||
)); | ||
} | ||
|
||
public int setColorLevel(final int memberCount, final int availableUserCount) { | ||
double ratio = (double) availableUserCount / memberCount; | ||
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. p2 접근자가 public입니다! 해당 클래스에서만 사용하는 것 같으니 private으로 바꿔주세요! |
||
|
||
if (ratio <= 0.2) { | ||
return 1; | ||
} else if (ratio <= 0.4) { | ||
return 2; | ||
} else if (ratio <= 0.6) { | ||
return 3; | ||
} else if (ratio <= 0.8) { | ||
return 4; | ||
} else if (ratio <= 1.0) { | ||
return 5; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
P3
timeBlock 별로
userRetrieveService.getUserNamesFromId(t.userIds()),
을 한다면,timeBlock 별로 쿼리가 발생해서
최대 266개의 쿼리가 발생하지 않을까 우려가 됩니다..!
그래서 저는 일전에 최적의 회의 시간 로직 리팩토링할 때, 유저를 전체 조회한 후 Map<Long, User>을 통해서 user정보를 가지고 왔었습니다..!
혹시 쿼리가 얼마나 생기는지 알 수 있을까요??
userNames
를 구할 때, 영속성의 도움을 받아서 해당 쿼리가 발생하지 않는 것인가? 란 추측도 하는 중인데.. 실행해보지 않아서 모르겠네요..!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.
꼼꼼히 봐주셔서 감사합니다!! 쿼리문이 최대 252개가 나갈 수 있는 상황이었더라고요! 저도 원용님 방식으로 수정하였습니다!
그런데, Map을 사용할경우 정렬이 보장이 되지 않아 테스트를 통과하지 않아서 이를 받아와 sorted하는 방식을 사용했습니다! 리뷰 부탁드립니다!