-
Notifications
You must be signed in to change notification settings - Fork 1
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
[Refactor] 모임 일정 시간 페이징 처리 및 베스트 타임 API #126
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ffb4cd8
feat: 페이징 응답 객체 생성
f1v3-dev 35ff952
Merge branch 'develop' into refactor/#121-meeting
f1v3-dev 1c6496e
chore: docker-compose 추가
f1v3-dev 576f1c4
refactor: 모임 일정 시간 조회 - 페이징 처리
f1v3-dev 0a2e0f8
refactor: 모임 일정 시간 조회 - 페이징 처리
f1v3-dev cba57bd
refactor: 모임의 최적의 시간 API (#123)
f1v3-dev 67eaeb6
refactor: 일정 수정 - assignedAt 변경하지 않음
f1v3-dev a89f502
test: API 수정에 따른 테스트코드 변경
f1v3-dev f89a68f
Merge branch 'develop' into refactor/#121-meeting
f1v3-dev 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
services: | ||
mysql: | ||
image: mysql:8.0 | ||
container_name: jjakkak-mysql | ||
restart: always | ||
ports: | ||
- "3306:3306" | ||
environment: | ||
MYSQL_DATABASE: jjakkak | ||
MYSQL_ROOT_PASSWORD: 1234 | ||
TZ: Asia/Seoul | ||
command: | ||
- --character-set-server=utf8mb4 | ||
|
||
redis: | ||
image: redis:latest | ||
container_name: jjakkak-redis | ||
restart: always | ||
ports: | ||
- "6379:6379" |
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
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 |
---|---|---|
|
@@ -8,14 +8,19 @@ | |
import com.dnd.jjakkak.domain.meeting.dto.response.MeetingTimeResponseDto; | ||
import com.dnd.jjakkak.domain.meeting.entity.Meeting; | ||
import com.dnd.jjakkak.domain.meeting.entity.QMeeting; | ||
import com.dnd.jjakkak.domain.meeting.enums.MeetingSort; | ||
import com.dnd.jjakkak.domain.meeting.exception.MeetingNotFoundException; | ||
import com.dnd.jjakkak.domain.meetingcategory.entity.QMeetingCategory; | ||
import com.dnd.jjakkak.domain.member.entity.QMember; | ||
import com.dnd.jjakkak.domain.schedule.entity.QSchedule; | ||
import com.dnd.jjakkak.global.common.PageInfo; | ||
import com.dnd.jjakkak.global.common.PagedResponse; | ||
import com.querydsl.core.types.OrderSpecifier; | ||
import com.querydsl.core.types.Projections; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
|
@@ -103,48 +108,87 @@ public MeetingInfoResponseDto getMeetingInfo(String uuid) { | |
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public MeetingTimeResponseDto getMeetingTimes(String uuid, MeetingSort sort) { | ||
public PagedResponse<MeetingTimeResponseDto> getMeetingTimes(String uuid, Pageable pageable, LocalDateTime requestTime) { | ||
|
||
// TODO : 성능 개선 필요해보임 | ||
QMeeting meeting = QMeeting.meeting; | ||
QSchedule schedule = QSchedule.schedule; | ||
QDateOfSchedule dateOfSchedule = QDateOfSchedule.dateOfSchedule; | ||
|
||
List<OrderSpecifier<?>> orderSpecifier = switch (sort) { | ||
case COUNT -> List.of(dateOfSchedule.dateOfScheduleRank.count().desc(), | ||
dateOfSchedule.dateOfScheduleRank.avg().asc(), | ||
dateOfSchedule.dateOfScheduleStart.asc(), | ||
dateOfSchedule.dateOfScheduleEnd.asc()); | ||
case LATEST -> List.of(dateOfSchedule.dateOfScheduleStart.asc()); | ||
}; | ||
|
||
// 우선순위 순으로 최적 시간 조회 | ||
// 1. order by 설정 | ||
List<OrderSpecifier<?>> orderSpecifiers = new ArrayList<>(); | ||
|
||
pageable.getSort().stream() | ||
.forEach(sort -> { | ||
switch (sort.getProperty()) { | ||
case "count" -> orderSpecifiers.addAll( | ||
List.of( | ||
dateOfSchedule.dateOfScheduleRank.count().desc(), | ||
dateOfSchedule.dateOfScheduleRank.avg().asc(), | ||
dateOfSchedule.dateOfScheduleStart.asc(), | ||
dateOfSchedule.dateOfScheduleEnd.asc() | ||
) | ||
); | ||
case "latest" -> orderSpecifiers.add(dateOfSchedule.dateOfScheduleStart.asc()); | ||
default -> throw new MeetingNotFoundException(); | ||
} | ||
}); | ||
|
||
|
||
// 2. 페이징 데이터 및 전체 요소 수 조회 | ||
List<MeetingTime> meetingTimeList = from(dateOfSchedule) | ||
.join(dateOfSchedule.schedule, schedule) | ||
.join(schedule.meeting, meeting) | ||
.where(meeting.meetingUuid.eq(uuid)) | ||
.where(meeting.meetingUuid.eq(uuid) | ||
.and(schedule.assignedAt.loe(requestTime))) | ||
Comment on lines
+142
to
+143
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. 굳 |
||
.groupBy(dateOfSchedule.dateOfScheduleStart, dateOfSchedule.dateOfScheduleEnd) | ||
.orderBy(orderSpecifier.toArray(new OrderSpecifier[0])) | ||
.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()])) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.select(Projections.constructor(MeetingTime.class, | ||
dateOfSchedule.dateOfScheduleStart, | ||
dateOfSchedule.dateOfScheduleEnd, | ||
dateOfSchedule.dateOfScheduleRank.avg() | ||
)) | ||
.fetch(); | ||
|
||
|
||
long totalElements = from(dateOfSchedule) | ||
.join(dateOfSchedule.schedule, schedule) | ||
.join(schedule.meeting, meeting) | ||
.where(meeting.meetingUuid.eq(uuid) | ||
.and(schedule.assignedAt.isNotNull()) | ||
.and(schedule.assignedAt.loe(requestTime))) | ||
.groupBy(dateOfSchedule.dateOfScheduleStart, dateOfSchedule.dateOfScheduleEnd) | ||
.select(dateOfSchedule.dateOfScheduleRank.count()) | ||
.fetchCount(); | ||
|
||
|
||
// 3. 닉네임 조회 | ||
for (MeetingTime meetingTime : meetingTimeList) { | ||
List<String> nicknames = from(dateOfSchedule) | ||
.join(dateOfSchedule.schedule, schedule) | ||
.join(schedule.meeting, meeting) | ||
.where(meeting.meetingUuid.eq(uuid) | ||
.and(dateOfSchedule.dateOfScheduleStart.eq(meetingTime.getStartTime())) | ||
.and(dateOfSchedule.dateOfScheduleEnd.eq(meetingTime.getEndTime()))) | ||
.and(dateOfSchedule.dateOfScheduleEnd.eq(meetingTime.getEndTime())) | ||
.and(schedule.assignedAt.loe(requestTime))) | ||
.select(schedule.scheduleNickname) | ||
.fetch(); | ||
|
||
meetingTime.addMemberNames(nicknames); | ||
} | ||
|
||
// 4. PageInfo 생성 | ||
int totalPages = (int) Math.ceil((double) totalElements / pageable.getPageSize()); | ||
PageInfo pageInfo = PageInfo.builder() | ||
.page(pageable.getPageNumber()) | ||
.size(pageable.getPageSize()) | ||
.totalElements((int) totalElements) | ||
.totalPages(totalPages) | ||
.build(); | ||
|
||
// 5. 응답 DTO 생성 | ||
MeetingTimeResponseDto responseDto = from(meeting) | ||
.where(meeting.meetingUuid.eq(uuid)) | ||
.select(Projections.constructor(MeetingTimeResponseDto.class, | ||
|
@@ -157,7 +201,7 @@ public MeetingTimeResponseDto getMeetingTimes(String uuid, MeetingSort sort) { | |
|
||
responseDto.addMeetingTimeList(meetingTimeList); | ||
|
||
return responseDto; | ||
return new PagedResponse<>(responseDto, pageInfo); | ||
} | ||
|
||
|
||
|
@@ -209,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(); | ||
} | ||
} |
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
Oops, something went wrong.
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.
이 부분은 프론트에서 API 최초 요청 시간을 보내는 건가요?
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.
엇 네 맞습니다.
시나리오를 생각해보면,
requestTime
을 추가하여 프론트가 요청한 시간을 보내줌일정 할당 시간 <= 요청 시간
)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.
그러면 API의 최초 요청 시간은 파라미터에 request_time를 빼고 전송할 때 갱신되는건가요?
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.
네 맞아요! 그 부분을 조금 주의해서 요청을 해야해요
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.
아하 알겠습니다. 머지하셔도 될 것 같습니다.