-
Notifications
You must be signed in to change notification settings - Fork 0
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
[✨ feat] 그룹 정보 보기 API 구현 #58
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
1afc706
chore(QueryDsl) : QueryDSL 의존성 추가
jsoonworld 166dd61
refactor(GroupCreateResponse) : 패키지 구조 변경
jsoonworld d74b7e3
refactor(GroupCreateInternalResponse) : 패키지 구조 변경
jsoonworld e4b5ec8
refactor(GroupInternalRetrieveResponse) : 패키지 구조 변경
jsoonworld 2cabe89
refactor(GroupRetrieveResponse) : 패키지 구조 변경
jsoonworld c4a4575
refactor(GroupsRetrieveResponse) : 패키지 구조 변경
jsoonworld 461ed9e
feat(QueryDslConfig) : QueryDSL 설정 구현
jsoonworld 5070cf4
feat(GroupController) : 그룹 정보 조회 엔드포인트 추가
jsoonworld 57b49ab
refactor(GroupService) : DTO 패키지 변경 반영
jsoonworld 44f1064
feat(GroupInfoService) : 그룹 정보 조회 서비스 인터페이스 추가
jsoonworld 4b325d5
feat(GroupInfoServiceImpl) : 그룹 정보 조회 서비스 구현
jsoonworld 48b59c4
refactor(GroupRetrieveServiceImpl) : 그룹 조회 로직 개선 및 패키지 변경 반영
jsoonworld 32c36f1
feat(GroupService) : 그룹 정보 조회 기능 추가
jsoonworld 184591c
feat(GroupErrorCode) : 멤버 조회 실패 예외 코드 추가
jsoonworld 00ef6a3
feat(GroupSuccessCode) : 그룹 정보 조회 성공 코드 추가
jsoonworld 7801ce9
feat(GroupInfoResponse) : 그룹 정보 응답 DTO 추가
jsoonworld fd90e9f
feat(GroupMemberInfoResponse) : 그룹 멤버 정보 응답 DTO 추가
jsoonworld 380e6e2
feat(GroupSummaryResponse) : 그룹 요약 정보 응답 DTO 추가
jsoonworld 0504517
refactor(MemberGroupRepository) : 커스텀 리포지토리 인터페이스 추가
jsoonworld 9802aa8
feat(MemberGroupRepositoryCustom) : 커스텀 리포지토리 인터페이스 추가
jsoonworld 9b4f01a
feat(MemberGroupRepositoryImpl) : 커스텀 리포지토리 구현 추가
jsoonworld 1d72ed6
test(GroupInfoServiceImplTest) : 그룹 정보 조회 서비스 테스트 작성
jsoonworld 372a1df
test(MemberGroupRepositoryTest) : 커스텀 리포지토리 메서드 테스트 구현
jsoonworld 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
19 changes: 19 additions & 0 deletions
19
src/main/java/org/noostak/global/config/QueryDslConfig.java
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,19 @@ | ||
package org.noostak.global.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class QueryDslConfig { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/main/java/org/noostak/group/application/GroupCreateService.java
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
7 changes: 7 additions & 0 deletions
7
src/main/java/org/noostak/group/application/GroupInfoService.java
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,7 @@ | ||
package org.noostak.group.application; | ||
|
||
import org.noostak.group.dto.response.info.GroupInfoResponse; | ||
|
||
public interface GroupInfoService { | ||
GroupInfoResponse getGroupInfo(Long memberId, Long groupId); | ||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/org/noostak/group/application/GroupInfoServiceImpl.java
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,91 @@ | ||
package org.noostak.group.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.noostak.group.common.exception.GroupErrorCode; | ||
import org.noostak.group.common.exception.GroupException; | ||
import org.noostak.group.domain.Group; | ||
import org.noostak.group.domain.GroupRepository; | ||
import org.noostak.group.dto.response.info.GroupInfoResponse; | ||
import org.noostak.group.dto.response.info.GroupMemberInfoResponse; | ||
import org.noostak.group.dto.response.info.GroupSummaryResponse; | ||
import org.noostak.infra.S3Service; | ||
import org.noostak.member.domain.Member; | ||
import org.noostak.membergroup.domain.MemberGroupRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GroupInfoServiceImpl implements GroupInfoService { | ||
|
||
private final GroupRepository groupRepository; | ||
private final MemberGroupRepository memberGroupRepository; | ||
private final S3Service s3Service; | ||
|
||
@Override | ||
public GroupInfoResponse getGroupInfo(final Long memberId, final Long groupId) { | ||
Group group = findGroupById(groupId); | ||
|
||
Member member = findMemberInGroup(memberId, groupId); | ||
GroupMemberInfoResponse myInfoResponse = convertToGroupMemberInfo(member); | ||
|
||
|
||
GroupMemberInfoResponse groupHostInfo = findGroupHost(groupId); | ||
|
||
List<GroupMemberInfoResponse> groupMembersInfo = findGroupMembers(groupId); | ||
|
||
GroupSummaryResponse groupSummaryResponse = convertToGroupSummaryResponse(group, groupHostInfo, groupMembersInfo); | ||
|
||
return GroupInfoResponse.of(myInfoResponse, groupSummaryResponse); | ||
} | ||
|
||
private Member findMemberInGroup(Long memberId, Long groupId) { | ||
return memberGroupRepository.findMembersByGroupId(groupId).stream() | ||
.filter(m -> m.getMemberId().equals(memberId)) | ||
.findFirst() | ||
.orElseThrow(() -> new GroupException(GroupErrorCode.MEMBER_NOT_FOUND)); | ||
} | ||
|
||
private Group findGroupById(Long groupId) { | ||
return groupRepository.findById(groupId) | ||
.orElseThrow(() -> new GroupException(GroupErrorCode.GROUP_NOT_FOUND)); | ||
} | ||
|
||
private GroupMemberInfoResponse findGroupHost(Long groupId) { | ||
Member host = memberGroupRepository.findGroupHostByGroupId(groupId); | ||
if (host == null) throw new GroupException(GroupErrorCode.GROUP_MEMBER_NOT_FOUND); | ||
|
||
return convertToGroupMemberInfo(host); | ||
} | ||
|
||
private List<GroupMemberInfoResponse> findGroupMembers(Long groupId) { | ||
return memberGroupRepository.findMembersByGroupId(groupId).stream() | ||
.map(this::convertToGroupMemberInfo) | ||
.toList(); | ||
} | ||
|
||
private GroupMemberInfoResponse convertToGroupMemberInfo(Member member) { | ||
return GroupMemberInfoResponse.of( | ||
member.getName().value(), | ||
s3Service.getImageUrl(member.getKey().value()) | ||
); | ||
} | ||
|
||
private GroupSummaryResponse convertToGroupSummaryResponse(Group group, GroupMemberInfoResponse hostInfo, List<GroupMemberInfoResponse> membersInfo) { | ||
String groupProfileImageUrl = getGroupProfileImageUrl(group); | ||
|
||
return GroupSummaryResponse.of( | ||
hostInfo, | ||
group.getName().value(), | ||
groupProfileImageUrl, | ||
group.getCount().value(), | ||
group.getCode().value(), | ||
membersInfo | ||
); | ||
} | ||
|
||
private String getGroupProfileImageUrl(Group group) { | ||
return s3Service.getImageUrl(group.getKey().value()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/org/noostak/group/application/GroupRetrieveService.java
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
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
2 changes: 1 addition & 1 deletion
2
...response/GroupCreateInternalResponse.java → ...e/create/GroupCreateInternalResponse.java
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
2 changes: 1 addition & 1 deletion
2
...oup/dto/response/GroupCreateResponse.java → .../response/create/GroupCreateResponse.java
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
10 changes: 10 additions & 0 deletions
10
src/main/java/org/noostak/group/dto/response/info/GroupInfoResponse.java
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,10 @@ | ||
package org.noostak.group.dto.response.info; | ||
|
||
public record GroupInfoResponse( | ||
GroupMemberInfoResponse myInfo, | ||
GroupSummaryResponse groupInfo | ||
) { | ||
public static GroupInfoResponse of(final GroupMemberInfoResponse myInfo, final GroupSummaryResponse groupInfo) { | ||
return new GroupInfoResponse(myInfo, groupInfo); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/noostak/group/dto/response/info/GroupMemberInfoResponse.java
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,10 @@ | ||
package org.noostak.group.dto.response.info; | ||
|
||
public record GroupMemberInfoResponse( | ||
String memberName, | ||
String memberProfileImageUrl | ||
) { | ||
public static GroupMemberInfoResponse of(final String memberName, final String memberProfileImageUrl) { | ||
return new GroupMemberInfoResponse(memberName, memberProfileImageUrl); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/noostak/group/dto/response/info/GroupSummaryResponse.java
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,15 @@ | ||
package org.noostak.group.dto.response.info; | ||
|
||
import java.util.List; | ||
|
||
public record GroupSummaryResponse( | ||
GroupMemberInfoResponse groupHostInfo, | ||
String groupName, | ||
String groupProfileImageUrl, | ||
Long groupMemberCount, | ||
String groupInvitationCode, | ||
List<GroupMemberInfoResponse> groupMemberInfo | ||
) { | ||
public static GroupSummaryResponse of(final GroupMemberInfoResponse groupHostInfo, final String groupName, final String groupProfileImageUrl, final Long groupMemberCount, final String groupInvitationCode, final List<GroupMemberInfoResponse> groupMemberInfo) { | ||
return new GroupSummaryResponse(groupHostInfo, groupName, groupProfileImageUrl, groupMemberCount, groupInvitationCode, groupMemberInfo);} | ||
} |
2 changes: 1 addition & 1 deletion
2
...sponse/GroupInternalRetrieveResponse.java → ...trieve/GroupInternalRetrieveResponse.java
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
2 changes: 1 addition & 1 deletion
2
...p/dto/response/GroupRetrieveResponse.java → ...ponse/retrieve/GroupRetrieveResponse.java
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
2 changes: 1 addition & 1 deletion
2
.../dto/response/GroupsRetrieveResponse.java → ...onse/retrieve/GroupsRetrieveResponse.java
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.noostak.group.dto.response; | ||
package org.noostak.group.dto.response.retrieve; | ||
|
||
import java.util.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.
findMembersByGroupId
->findMemberByGroupIdAndMemberId
처럼 WHERE 조건 절에 MemberId와 GroupId가 일치하는 확인하는 방법으로 해결할 수 없을까요?조건부 연산을 DBMS에서 수행할 수 있으면, DBMS에서 넘어오는 데이터에 대한 Bandwidth의 부담을 줄일 수 있습니다!
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.
피드백 감사합니다! 😊
현재
findMembersByGroupId(groupId)
를 호출한 후 Java 스트림을 이용해memberId
를 필터링하고 있는데, QueryDSL으로 구현된 로직을 개선하면 해당 필터링을 DB에서 직접 수행할 수 있을 것 같습니다.제안해주신 대로
findMemberByGroupIdAndMemberId(groupId, memberId)
와 같은 형태로 WHERE 조건을 적용하면, 불필요한 데이터를 애플리케이션으로 가져오지 않고 DBMS가 직접 필터링을 수행하여 네트워크 및 메모리 사용량을 줄일 수 있을 것 같습니다.예를 들어, 현재
findMembersByGroupId(groupId)
는 다음과 같이 모든 멤버를 가져옵니다:이후 Java 스트림을 사용하여 필터링하고 있는데, QueryDSL에서 직접 처리하는 방식으로 변경하면 더 효율적일 것입니다:
이렇게 하면 DB에서 직접
groupId
와memberId
조건을 적용해 검색하므로 불필요한 데이터 전송을 방지할 수 있을 것 같아요!따라서
findMemberInGroup
메서드를 다음과 같이 변경하는 것이 더 적절할 것 같습니다:이렇게 하면 전체 데이터를 불러온 후 필터링하는 것이 아니라, DB에서 직접 원하는 데이터를 가져오기 때문에 성능상 더 유리겠어요!
이 부분은 이슈로 등록하고 개선하겠습니다!
좋은 피드백 감사합니다! 🙌 🚀