-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 모임 홈 화면에서 유저가 참여중인 모임 방 조회 api #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fea2696
[feat] RoomGetHomeJoinedListQuery 작성 (#56)
hd0rable a2f7f4c
[feat]RoomGetHomeJoinedListResponse dto 작성 (#56)
hd0rable 922054a
[feat] RoomGetHomeJoinedListService 작성 (#56)
hd0rable 96ce09e
[feat] RoomGetHomeJoinedListUseCase.getHomeJoinedRoomList 작성 (#56)
hd0rable 89df7a3
[feat] RoomQueryController.getHomeJoinedRooms 작성 (#56)
hd0rable 0f12440
[feat] RoomQueryPersistenceAdapter.searchHomeJoinedRooms 작성 (#56)
hd0rable 385043b
[feat] RoomQueryPort.searchHomeJoinedRooms 작성 (#56)
hd0rable e8314c4
[feat] RoomQueryRepository.searchHomeJoinedRooms 작성 (#56)
hd0rable 1bd0d92
[feat] RoomQueryRepositoryImpl.searchHomeJoinedRooms 구현 (#56)
hd0rable 0a1b66c
[refactor] todo 작성 (#56)
hd0rable 5a1c7f6
[test] userRoom 생성 코드 추가 (#56)
hd0rable 489d095
[test] 컨트롤러 단위 테스트 코드 추가 (#56)
hd0rable 5de0951
[test] 모임 홈 참여중인 내 모임방 조회 api 통합 테스트 코드 작성 (#56)
hd0rable 23c03d3
[refactor] dto 빌더 패턴 도입 (#56)
hd0rable e91c869
[refactor] NPE 방지 기본값 세팅 (#56)
hd0rable 2b347de
[test] 안쓰는 객체 주입 삭제 (#56)
hd0rable e43ef53
Merge remote-tracking branch 'origin/develop' into feat/#56-get-home-…
hd0rable 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 hidden or 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
26 changes: 26 additions & 0 deletions
26
src/main/java/konkuk/thip/room/adapter/in/web/response/RoomGetHomeJoinedListResponse.java
This file contains hidden or 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,26 @@ | ||
| package konkuk.thip.room.adapter.in.web.response; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Builder | ||
| public record RoomGetHomeJoinedListResponse( | ||
| List<RoomSearchResult> roomList, | ||
| String nickname, | ||
| int page, // 현재 페이지 | ||
| int size, // 현재 페이지에 포함된 데이터 수 | ||
| boolean last, | ||
| boolean first | ||
| ) { | ||
|
|
||
|
|
||
| @Builder | ||
| public record RoomSearchResult( | ||
| Long roomId, | ||
| String bookImageUrl, | ||
| String bookTitle, | ||
| int memberCount, | ||
| int userPercentage | ||
| ) {} | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| //TODO 방에 이방에 참여중인 인원수 추가 | ||
| @Entity | ||
| @Table(name = "rooms") | ||
| @Getter | ||
|
|
||
This file contains hidden or 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
4 changes: 4 additions & 0 deletions
4
src/main/java/konkuk/thip/room/adapter/out/persistence/RoomQueryRepository.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,10 +1,14 @@ | ||
| package konkuk.thip.room.adapter.out.persistence; | ||
|
|
||
| import konkuk.thip.room.adapter.in.web.response.RoomGetHomeJoinedListResponse; | ||
| import konkuk.thip.room.adapter.in.web.response.RoomSearchResponse; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| public interface RoomQueryRepository { | ||
|
|
||
| Page<RoomSearchResponse.RoomSearchResult> searchRoom(String keyword, String category, Pageable pageable); | ||
| Page<RoomGetHomeJoinedListResponse.RoomSearchResult> searchHomeJoinedRooms(Long userId, LocalDate today, Pageable pageable); | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -6,9 +6,12 @@ | |
| import com.querydsl.core.types.OrderSpecifier; | ||
| import com.querydsl.core.types.dsl.CaseBuilder; | ||
| import com.querydsl.core.types.dsl.NumberExpression; | ||
| import com.querydsl.jpa.JPAExpressions; | ||
| import com.querydsl.jpa.JPQLQuery; | ||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import konkuk.thip.book.adapter.out.jpa.QBookJpaEntity; | ||
| import konkuk.thip.common.util.DateUtil; | ||
| import konkuk.thip.room.adapter.in.web.response.RoomGetHomeJoinedListResponse; | ||
| import konkuk.thip.room.adapter.in.web.response.RoomSearchResponse; | ||
| import konkuk.thip.room.adapter.out.jpa.QRoomJpaEntity; | ||
| import konkuk.thip.user.adapter.out.jpa.QUserRoomJpaEntity; | ||
|
|
@@ -21,6 +24,7 @@ | |
|
|
||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
|
|
@@ -31,6 +35,7 @@ public class RoomQueryRepositoryImpl implements RoomQueryRepository { | |
| private final QBookJpaEntity book = QBookJpaEntity.bookJpaEntity; | ||
| private final QUserRoomJpaEntity userRoom = QUserRoomJpaEntity.userRoomJpaEntity; | ||
|
|
||
|
|
||
| @Override | ||
| public Page<RoomSearchResponse.RoomSearchResult> searchRoom(String keyword, String category, Pageable pageable) { | ||
| // 1. 검색 조건(where) 조립 : 방이름 or 첵제목에 keyword 포함, category 필터 적용, 멤버 모집중인(= 활동 시작전인) 방만 검색 | ||
|
|
@@ -137,4 +142,78 @@ private OrderSpecifier<?> toOrderSpecifier(Sort sort, QRoomJpaEntity room, Numbe | |
| return room.startDate.asc(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Page<RoomGetHomeJoinedListResponse.RoomSearchResult> searchHomeJoinedRooms(Long userId, LocalDate date, Pageable pageable) { | ||
|
|
||
| QUserRoomJpaEntity userRoomSub = new QUserRoomJpaEntity("userRoomSub"); | ||
|
|
||
| // 1. 검색 조건(where) 조립 | ||
| // 유저가 참여한 방만: userId 조건 | ||
| // 활동 기간 중인 방만: startDate ≤ today ≤ endDate | ||
| BooleanBuilder where = new BooleanBuilder(); | ||
| where.and(userRoom.userJpaEntity.userId.eq(userId)); | ||
| where.and(room.startDate.loe(date)); | ||
| where.and(room.endDate.goe(date)); | ||
|
Comment on lines
+151
to
+157
Collaborator
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. LGTM |
||
|
|
||
| // TODO : Room 에 멤버 수 추가되면 로직 수정 | ||
| // 멤버 수 서브쿼리 | ||
| JPQLQuery<Long> memberCountSubQuery = JPAExpressions | ||
| .select(userRoomSub.count()) | ||
| .from(userRoomSub) | ||
| .where(userRoomSub.roomJpaEntity.roomId.eq(room.roomId)); | ||
|
|
||
| // 2. 페이징된 목록 조회 | ||
| List<Tuple> tuples = queryFactory | ||
| .select( | ||
| room.roomId, | ||
| book.imageUrl, | ||
| room.title, | ||
| memberCountSubQuery, | ||
| room.recruitCount, | ||
| room.startDate, | ||
| book.title, | ||
| userRoom.userPercentage | ||
| ) | ||
| .from(userRoom) | ||
| .join(userRoom.roomJpaEntity, room) | ||
| .join(room.bookJpaEntity, book) | ||
| .where(where) | ||
| .orderBy( | ||
| userRoom.userPercentage.desc(), // 진행률 높은 순(내림차순) | ||
| room.startDate.asc() // 진행률 같으면 활동 시작일 빠른 순 (오름차순) | ||
| ) | ||
|
Comment on lines
+182
to
+185
Collaborator
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. LGTM |
||
| .offset(pageable.getOffset()) | ||
| .limit(pageable.getPageSize()) | ||
| .fetch(); | ||
| // TODO : 추후에 오프셋 페이징이 아니라, 키셋 페이징 기법 도입 검토 | ||
|
|
||
| // 3. Tuple → DTO 매핑 | ||
| List<RoomGetHomeJoinedListResponse.RoomSearchResult> content = tuples.stream() | ||
| .map(t -> RoomGetHomeJoinedListResponse.RoomSearchResult.builder() | ||
| .roomId(t.get(room.roomId)) | ||
| .bookImageUrl(t.get(book.imageUrl)) | ||
| .bookTitle(t.get(book.title)) | ||
| .memberCount(Optional.ofNullable(t.get(memberCountSubQuery)).map(Number::intValue).orElse(1)) | ||
| .userPercentage(Optional.ofNullable(t.get(userRoom.userPercentage)) | ||
| .map(val -> ((Number) val).doubleValue()) | ||
| .map(Math::round) | ||
| .map(Long::intValue) | ||
| .orElse(0)) | ||
| .build() | ||
| ) | ||
| .toList(); | ||
|
|
||
| // 4. 전체 개수 조회 (페이징 정보 계산용) | ||
| Long totalCount = queryFactory | ||
| .select(userRoom.count()) | ||
| .from(userRoom) | ||
| .join(userRoom.roomJpaEntity, room) | ||
| .where(where) | ||
| .fetchOne(); | ||
| long total = (totalCount != null) ? totalCount : 0L; | ||
|
|
||
| // 5. PageImpl 생성하여 반환 | ||
| return new PageImpl<>(content, pageable, total); | ||
| } | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
src/main/java/konkuk/thip/room/application/port/in/RoomGetHomeJoinedListUseCase.java
This file contains hidden or 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,8 @@ | ||
| package konkuk.thip.room.application.port.in; | ||
|
|
||
| import konkuk.thip.room.adapter.in.web.response.RoomGetHomeJoinedListResponse; | ||
| import konkuk.thip.room.application.port.in.dto.RoomGetHomeJoinedListQuery; | ||
|
|
||
| public interface RoomGetHomeJoinedListUseCase { | ||
| RoomGetHomeJoinedListResponse getHomeJoinedRoomList(RoomGetHomeJoinedListQuery roomGetHomeJoinedListQuery); | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/konkuk/thip/room/application/port/in/dto/RoomGetHomeJoinedListQuery.java
This file contains hidden or 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,10 @@ | ||
| package konkuk.thip.room.application.port.in.dto; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record RoomGetHomeJoinedListQuery( | ||
| Long userId, | ||
| int page | ||
| ) { | ||
| } | ||
hd0rable marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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
62 changes: 62 additions & 0 deletions
62
src/main/java/konkuk/thip/room/application/service/RoomGetHomeJoinedListService.java
This file contains hidden or 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,62 @@ | ||
| package konkuk.thip.room.application.service; | ||
|
|
||
| import konkuk.thip.common.exception.InvalidStateException; | ||
| import konkuk.thip.common.exception.code.ErrorCode; | ||
| import konkuk.thip.room.adapter.in.web.response.RoomGetHomeJoinedListResponse; | ||
| import konkuk.thip.room.application.port.in.RoomGetHomeJoinedListUseCase; | ||
| import konkuk.thip.room.application.port.in.dto.RoomGetHomeJoinedListQuery; | ||
| import konkuk.thip.room.application.port.out.RoomQueryPort; | ||
| import konkuk.thip.user.application.port.out.UserCommandPort; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class RoomGetHomeJoinedListService implements RoomGetHomeJoinedListUseCase { | ||
|
|
||
| private static final int DEFAULT_PAGE_SIZE = 10; | ||
|
|
||
| private final RoomQueryPort roomQueryPort; | ||
| private final UserCommandPort userCommandPort; | ||
|
|
||
| @Override | ||
| @Transactional(readOnly = true) | ||
| public RoomGetHomeJoinedListResponse getHomeJoinedRoomList(RoomGetHomeJoinedListQuery query) { | ||
|
|
||
| // 1. page 값 검증 | ||
| validatePage(query.page()); | ||
|
|
||
| // 2. 유저 닉네임 조회 | ||
| String nickname = userCommandPort.findById(query.userId()).getNickname(); | ||
|
|
||
| // 3. Pageable 생성 | ||
| int pageIndex = query.page() > 0 ? query.page() - 1 : 0; | ||
| Pageable pageable = PageRequest.of(pageIndex, DEFAULT_PAGE_SIZE); | ||
|
|
||
| // 4. 모임 홈에서 참여중인 모임 방 검색 | ||
| Page<RoomGetHomeJoinedListResponse.RoomSearchResult> result = roomQueryPort.searchHomeJoinedRooms(query.userId(), LocalDate.now(), pageable); | ||
|
|
||
| // 5. response 구성 | ||
| return RoomGetHomeJoinedListResponse.builder() | ||
| .roomList(result.getContent()) | ||
| .nickname(nickname) | ||
| .page(query.page()) | ||
| .size(result.getNumberOfElements()) | ||
| .last(result.isLast()) | ||
| .first(result.isFirst()) | ||
| .build(); | ||
| } | ||
|
|
||
| private void validatePage(int page) { | ||
| if(page< 1) { | ||
| throw new InvalidStateException(ErrorCode.API_INVALID_PARAM, new IllegalArgumentException("page은 1 이상의 값이어야 합니다.")); | ||
| } | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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.
👍🏻