-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[✨ feat] 그룹 정보 보기 API 구현
- Loading branch information
Showing
27 changed files
with
493 additions
and
64 deletions.
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.