-
Notifications
You must be signed in to change notification settings - Fork 2
[feat] 크루 상세, 리스트 조회 API 기능 구현 #25
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
6 commits
Select commit
Hold shift + click to select a range
08acd93
[feat] 크루 리스트 조회 API 기능 구현 및 테스트코드 리팩토링 (#4)
pparkjs 5341113
[feat] 크루 상세 조회 API 기능 구현 (#4)
pparkjs 094e96b
feat: 스웨거 추가 작업 (#24)
xjvmdutl 938c5db
[fix] 크루 상세 조회 API 코드리뷰 반영 (#4)
pparkjs d3a480c
[fix] 단위테스트 SpringBootTest -> DataJpaTest 사용하도록 수정 (#4)
pparkjs c61cd7d
Merge branch 'develop' into feature-4/look-up-crew
pparkjs 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
40 changes: 38 additions & 2 deletions
40
src/main/java/com/retrip/crew/application/in/CrewService.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,24 +1,60 @@ | ||
| package com.retrip.crew.application.in; | ||
|
|
||
| import com.retrip.crew.application.in.request.CrewCreateRequest; | ||
| import com.retrip.crew.application.in.request.CrewOrder; | ||
| import com.retrip.crew.application.in.response.CrewCreateResponse; | ||
| import com.retrip.crew.application.in.response.CrewDetailResponse; | ||
| import com.retrip.crew.application.in.response.CrewListResponse; | ||
| import com.retrip.crew.application.in.usecase.CreateCrewUseCase; | ||
| import com.retrip.crew.application.in.usecase.GetCrewUseCase; | ||
| import com.retrip.crew.application.out.repository.CrewMemberRepository; | ||
| import com.retrip.crew.application.out.repository.CrewQueryRepository; | ||
| import com.retrip.crew.application.out.repository.CrewRepository; | ||
| import com.retrip.crew.domain.entity.Crew; | ||
| import jakarta.transaction.Transactional; | ||
| import com.retrip.crew.domain.exception.CrewNotFoundException; | ||
| import com.retrip.crew.infra.adapter.in.presentation.rest.common.ScrollPageResponse; | ||
| import com.retrip.crew.infra.util.PaginationUtils; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Slice; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @Transactional | ||
| @RequiredArgsConstructor | ||
| public class CrewService implements CreateCrewUseCase { | ||
| public class CrewService implements CreateCrewUseCase, GetCrewUseCase { | ||
| private final CrewRepository crewRepository; | ||
| private final CrewMemberRepository crewMemberRepository; | ||
| private final CrewQueryRepository crewQueryRepository; | ||
|
|
||
| @Override | ||
| public CrewCreateResponse createCrew(CrewCreateRequest request) { | ||
| Crew crew = crewRepository.save(request.to(request.leader())); | ||
|
|
||
| return CrewCreateResponse.of(crew); | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional(readOnly = true) | ||
| public ScrollPageResponse<CrewListResponse> getCrews(Pageable pageable, String keyword, CrewOrder order, String sort) { | ||
| Pageable orderPageable = PaginationUtils.createPageRequest(pageable, order.getField(), sort); | ||
| Slice<CrewListResponse> result = crewQueryRepository.getCrews(orderPageable, keyword); | ||
| Long totalCount = crewQueryRepository.getCrewCount(keyword); | ||
| return ScrollPageResponse.of(totalCount, result.hasNext(), result.getContent()); | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional(readOnly = true) | ||
| public CrewDetailResponse getCrewDetail(UUID crewId) { | ||
| Crew crew = findById(crewId); | ||
| int memberCount = crewMemberRepository.countByCrewId(crewId); | ||
| return CrewDetailResponse.of(crew, memberCount); | ||
| } | ||
|
|
||
| private Crew findById(UUID crewId){ | ||
| return crewRepository.findById(crewId) | ||
| .orElseThrow(CrewNotFoundException::new); | ||
| } | ||
| } |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/retrip/crew/application/in/request/CrewOrder.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,12 @@ | ||
| package com.retrip.crew.application.in.request; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum CrewOrder { | ||
| DATE("createdAt"); | ||
|
|
||
| private final String field; | ||
| } |
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
77 changes: 77 additions & 0 deletions
77
src/main/java/com/retrip/crew/application/in/response/CrewDetailResponse.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,77 @@ | ||
| package com.retrip.crew.application.in.response; | ||
|
|
||
| import com.retrip.crew.domain.entity.Crew; | ||
| import com.retrip.crew.domain.entity.CrewMember; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import lombok.Builder; | ||
|
|
||
| @Schema | ||
| @Builder | ||
| public record CrewDetailResponse( | ||
| @Schema(description = "크루 ID") | ||
| UUID id, | ||
|
|
||
| @Schema(description = "크루 타이틀") | ||
| String title, | ||
|
|
||
| @Schema(description = "크루 설명") | ||
| String description, | ||
|
|
||
| @Schema(description = "크루 리더 ID") | ||
| UUID leaderId, | ||
|
|
||
| @Schema(description = "크루원 현재 인원수") | ||
| Integer memberCount, | ||
|
|
||
| @Schema(description = "크루원 수용가능한 최대 인원수") | ||
| Integer maxMemberCount, | ||
|
|
||
| @Schema(description = "크루원 리스트") | ||
| List<CrewMemberResponse> members | ||
| ) { | ||
|
|
||
| public static CrewDetailResponse of(Crew crew, int memberCount){ | ||
| return CrewDetailResponse.builder() | ||
| .id(crew.getId()) | ||
| .title(crew.getTitle().getValue()) | ||
| .description(crew.getDescription()) | ||
| .leaderId(crew.getLeader().getMemberId()) | ||
| .memberCount(memberCount) | ||
| .maxMemberCount(crew.getMaxMembers()) | ||
| .members(toList(crew.getCrewMembers().getValues())) | ||
| .build(); | ||
| } | ||
|
|
||
| public static List<CrewMemberResponse> toList(List<CrewMember> crewMembers){ | ||
| return crewMembers.stream() | ||
| .map(CrewMemberResponse::from) | ||
| .toList(); | ||
| } | ||
|
|
||
| @Schema | ||
| public record CrewMemberResponse( | ||
|
|
||
| @Schema(description = "크루 멤버 고유 ID") | ||
| UUID id, | ||
|
|
||
| @Schema(description = "크루원 ID") | ||
| UUID memberId, | ||
|
|
||
| @Schema(description = "크루원 역할코드") | ||
| String roleCode, | ||
|
|
||
| @Schema(description = "크루원 역할명") | ||
| String roleName | ||
| ){ | ||
| public static CrewMemberResponse from(CrewMember crewMember){ | ||
| return new CrewMemberResponse( | ||
| crewMember.getId(), | ||
| crewMember.getMemberId(), | ||
| crewMember.getCrewMemberRole().getCode(), | ||
| crewMember.getCrewMemberRole().getViewName() | ||
| ); | ||
| } | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/retrip/crew/application/in/response/CrewListResponse.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,23 @@ | ||
| package com.retrip.crew.application.in.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import java.util.UUID; | ||
|
|
||
| @Schema(description = "크루 리스트 조회 Response") | ||
| public record CrewListResponse( | ||
| @Schema(description = "크루 ID") | ||
| UUID id, | ||
|
|
||
| @Schema(description = "크루 타이틀") | ||
| String title, | ||
|
|
||
| @Schema(description = "크루 리더 ID") | ||
| UUID leaderId, | ||
|
|
||
| @Schema(description = "크루원 현재 인원수") | ||
| Long memberCount, | ||
|
|
||
| @Schema(description = "크루원 수용가능한 최대 인원수") | ||
| Integer maxMemberCount | ||
| ) { | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/retrip/crew/application/in/usecase/GetCrewUseCase.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,14 @@ | ||
| package com.retrip.crew.application.in.usecase; | ||
|
|
||
| import com.retrip.crew.application.in.request.CrewOrder; | ||
| import com.retrip.crew.application.in.response.CrewDetailResponse; | ||
| import com.retrip.crew.application.in.response.CrewListResponse; | ||
| import com.retrip.crew.infra.adapter.in.presentation.rest.common.ScrollPageResponse; | ||
| import java.util.UUID; | ||
| import org.springframework.data.domain.Pageable; | ||
|
|
||
| public interface GetCrewUseCase { | ||
| ScrollPageResponse<CrewListResponse> getCrews(Pageable pageable, String keyword, CrewOrder order, String sort); | ||
|
|
||
| CrewDetailResponse getCrewDetail(UUID crewId); | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/retrip/crew/application/out/repository/CrewMemberRepository.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,9 @@ | ||
| package com.retrip.crew.application.out.repository; | ||
|
|
||
| import com.retrip.crew.domain.entity.CrewMember; | ||
| import java.util.UUID; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface CrewMemberRepository extends JpaRepository<CrewMember, UUID> { | ||
| int countByCrewId(UUID crewId); | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/retrip/crew/application/out/repository/CrewQueryRepository.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 com.retrip.crew.application.out.repository; | ||
|
|
||
| import com.retrip.crew.application.in.response.CrewListResponse; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.domain.Slice; | ||
|
|
||
| public interface CrewQueryRepository { | ||
| Slice<CrewListResponse> getCrews(Pageable pageable, String keyword); | ||
| Long getCrewCount(String keyword); | ||
| } |
1 change: 0 additions & 1 deletion
1
src/main/java/com/retrip/crew/application/out/repository/CrewRepository.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
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
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
18 changes: 18 additions & 0 deletions
18
...in/java/com/retrip/crew/infra/adapter/in/presentation/rest/common/ScrollPageResponse.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,18 @@ | ||
| package com.retrip.crew.infra.adapter.in.presentation.rest.common; | ||
|
|
||
| import java.util.List; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class ScrollPageResponse<T> { | ||
| private Long totalCount; | ||
| private boolean hasNext; | ||
| private List<T> list; | ||
|
|
||
| public static <T> ScrollPageResponse<T> of(Long totalCount, boolean hasNext, List<T> list) { | ||
| return new ScrollPageResponse<>(totalCount, hasNext, list); | ||
| } | ||
| } |
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.
해당 필드를 이 이슈에서 추가한 이유가 있을까요??
작업 내용에는 없는것 같아서.. 만약 추가된다면 작업 내용에 스토리 적는게 좋을거 같습니다.
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.
크루도 최대 받을수 있는 인원이 정해져있는데 크루 리스트 조회할때 사용자가 최대인원과 현재 가입되어있는 인원 ex ) 2/10 이렇게 보여야하기에 필요해서 추가했습니다