From 3efe53119ee213f372927eb4b5fe77dd2514604c Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Sat, 23 Nov 2024 14:38:52 +0900 Subject: [PATCH 01/17] =?UTF-8?q?feat:=20=EA=B7=B8=EB=A3=B9=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=B0=B8=EC=97=AC=EC=9E=90=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20(#163)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group/dto/response/GroupTotalResponse.java | 11 +++++------ .../group/mapper/GroupResponseMapper.java | 8 -------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/group/dto/response/GroupTotalResponse.java b/src/main/java/org/ioteatime/meonghanyangserver/group/dto/response/GroupTotalResponse.java index 3d578468..72b2be35 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/group/dto/response/GroupTotalResponse.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/group/dto/response/GroupTotalResponse.java @@ -6,12 +6,11 @@ import java.time.LocalDateTime; import java.util.List; import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoResponse; -import org.ioteatime.meonghanyangserver.groupmember.dto.response.GroupMemberInfoResponse; @Schema(description = "그룹 통합 정보 응답") public record GroupTotalResponse( - @NotNull Long groupId, - @NotBlank String groupName, - @NotNull LocalDateTime createdAt, - List member, - List cctv) {} + @NotNull @Schema(description = "그룹 ID", example = "1") Long groupId, + @NotBlank @Schema(description = "그룹 이름", example = "멍하냥 그룹") String groupName, + @NotNull @Schema(description = "그룹 생성 시간", example = "2024-10-10 15:00") + LocalDateTime createdAt, + @Schema(description = "그룹의 CCTV 정보 목록") List cctv) {} diff --git a/src/main/java/org/ioteatime/meonghanyangserver/group/mapper/GroupResponseMapper.java b/src/main/java/org/ioteatime/meonghanyangserver/group/mapper/GroupResponseMapper.java index 75ae1668..c1ac4b08 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/group/mapper/GroupResponseMapper.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/group/mapper/GroupResponseMapper.java @@ -7,8 +7,6 @@ import org.ioteatime.meonghanyangserver.group.dto.response.CreateGroupResponse; import org.ioteatime.meonghanyangserver.group.dto.response.GroupTotalResponse; import org.ioteatime.meonghanyangserver.group.dto.response.UpdateNicknameAndGroupNameResponse; -import org.ioteatime.meonghanyangserver.groupmember.dto.response.GroupMemberInfoResponse; -import org.ioteatime.meonghanyangserver.groupmember.mapper.GroupMemberResponseMapper; public class GroupResponseMapper { public static CreateGroupResponse from(GroupEntity groupEntity) { @@ -17,11 +15,6 @@ public static CreateGroupResponse from(GroupEntity groupEntity) { } public static GroupTotalResponse fromGroupTotal(GroupEntity groupEntity) { - List deviceInfoResponseList = - groupEntity.getGroupMemberEntities().stream() - .map(GroupMemberResponseMapper::from) - .toList(); - List cctvInfoResponseList = groupEntity.getCctvEntities().stream().map(CctvResponseMapper::from).toList(); @@ -29,7 +22,6 @@ public static GroupTotalResponse fromGroupTotal(GroupEntity groupEntity) { groupEntity.getId(), groupEntity.getGroupName(), groupEntity.getCreatedAt(), - deviceInfoResponseList, cctvInfoResponseList); } From d60180c3c97f001ff0ce375ef97d3f78c61b92a0 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Sat, 23 Nov 2024 14:49:22 +0900 Subject: [PATCH 02/17] =?UTF-8?q?feat:=20MASTER=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20(#165)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cctv/mapper/CctvResponseMapper.java | 6 ++++ .../cctv/service/CctvService.java | 29 ++++++++++++------- .../common/type/GroupErrorType.java | 3 +- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/mapper/CctvResponseMapper.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/mapper/CctvResponseMapper.java index 059051e3..91bf9ae0 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/cctv/mapper/CctvResponseMapper.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/mapper/CctvResponseMapper.java @@ -1,6 +1,8 @@ package org.ioteatime.meonghanyangserver.cctv.mapper; +import java.util.List; import org.ioteatime.meonghanyangserver.cctv.domain.CctvEntity; +import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoListResponse; import org.ioteatime.meonghanyangserver.cctv.dto.response.CctvInfoResponse; public class CctvResponseMapper { @@ -11,4 +13,8 @@ public static CctvInfoResponse from(CctvEntity cctvEntity) { cctvEntity.getThingId(), cctvEntity.getKvsChannelName()); } + + public static CctvInfoListResponse from(List cctvInfoResponseList) { + return new CctvInfoListResponse(cctvInfoResponseList); + } } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java index a3527021..78f0c991 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java @@ -18,6 +18,8 @@ import org.ioteatime.meonghanyangserver.common.type.GroupErrorType; import org.ioteatime.meonghanyangserver.group.domain.GroupEntity; import org.ioteatime.meonghanyangserver.group.repository.GroupRepository; +import org.ioteatime.meonghanyangserver.groupmember.doamin.GroupMemberEntity; +import org.ioteatime.meonghanyangserver.groupmember.doamin.enums.GroupMemberRole; import org.ioteatime.meonghanyangserver.groupmember.repository.GroupMemberRepository; import org.springframework.stereotype.Service; @@ -82,29 +84,36 @@ public CctvInfoResponse cctvInfo(Long cctvId) { } public CctvInfoListResponse cctvInfoList(Long memberId, Long groupId) { - if (!groupMemberRepository.existsByMemberIdAndGroupId(memberId, groupId)) { - throw new BadRequestException(GroupErrorType.GROUP_MEMBER_NOT_FOUND); - } + validateMaster(memberId, groupId); List cctvEntityList = cctvRepository.findByGroupId(groupId); List cctvInfoResponseList = cctvEntityList.stream().map(CctvResponseMapper::from).toList(); - CctvInfoListResponse cctvInfoListResponse = new CctvInfoListResponse(cctvInfoResponseList); - return cctvInfoListResponse; + return CctvResponseMapper.from(cctvInfoResponseList); } @Transactional public CctvInfoResponse updateNickname(Long memberId, UpdateCctvNickname request) { - // cctvId로 cctv 객체 찾기 + // CctvId로 cctv 객체 찾기 CctvEntity cctvEntity = cctvRepository .findById(request.cctvId()) .orElseThrow(() -> new NotFoundException(CctvErrorType.NOT_FOUND)); - // groupId와 memberId로 groupMember가 존재하는지 확인 -> 아니면 에러 - groupMemberRepository - .findByGroupIdAndMemberId(cctvEntity.getGroup().getId(), memberId) - .orElseThrow(() -> new NotFoundException(GroupErrorType.GROUP_MEMBER_NOT_FOUND)); + validateMaster(memberId, cctvEntity.getGroup().getId()); // cctv 이름 변경 cctvEntity = cctvEntity.updateNickname(request.cctvNickname()); return CctvResponseMapper.from(cctvEntity); } + + private void validateMaster(Long memberId, Long groupId) { + // GroupId와 memberId로 groupMember가 존재하는지 확인 -> 아니면 에러 + GroupMemberEntity groupMemberEntity = + groupMemberRepository + .findByGroupIdAndMemberId(groupId, memberId) + .orElseThrow( + () -> new NotFoundException(GroupErrorType.GROUP_MEMBER_NOT_FOUND)); + // Member가 Master인지 확인 -> 아니면 에러 + if (groupMemberEntity.getRole() != GroupMemberRole.ROLE_MASTER) { + throw new BadRequestException(GroupErrorType.ONLY_MASTER_UPDATE_CCTV_NICKNAME); + } + } } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/common/type/GroupErrorType.java b/src/main/java/org/ioteatime/meonghanyangserver/common/type/GroupErrorType.java index 4dc3d973..d96904fb 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/common/type/GroupErrorType.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/common/type/GroupErrorType.java @@ -7,7 +7,8 @@ public enum GroupErrorType implements ErrorTypeCode { ONLY_MASTER_REMOVE_GROUP_MEMBER("BAD REQUEST", "방장만 그룹에서 참여자를 제외시킬 수 있습니다."), ONLY_MASTER_REMOVE_GROUP_MASTER("BAD REQUEST", "방장은 자신을 제외시킬 수 있습니다."), GROUP_MEMBER_NOT_FOUND("GROUP MEMBER NOT FOUND", "그룹 회원 정보를 찾을 수 없습니다."), - ONLY_MASTER_GET_GROUP_MEMBER_INFO("BAD REQUEST", "방장만 그룹 참여자 정보를 받을 수 있습니다."); + ONLY_MASTER_GET_GROUP_MEMBER_INFO("BAD REQUEST", "방장만 그룹 참여자 정보를 받을 수 있습니다."), + ONLY_MASTER_UPDATE_CCTV_NICKNAME("BAD REQUEST", "방장만 그룹의 CCTV 이름을 변경할 수 있습니다."); private final String message; private final String description; From 7f762588649d14dc1a9e0e065820f445dd86bbc8 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Sat, 23 Nov 2024 15:02:00 +0900 Subject: [PATCH 03/17] =?UTF-8?q?feat:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20url=20=EA=B0=92=20=EB=B0=9B=EC=95=84=EC=98=A4?= =?UTF-8?q?=EC=A7=80=20=EB=AA=BB=ED=95=98=EB=8A=94=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#165)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meonghanyangserver/cctv/controller/CctvController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvController.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvController.java index 0ae974b0..521aff9e 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvController.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvController.java @@ -24,7 +24,7 @@ public Api out(@LoginMember Long userId, @PathVariable("cctvId") Long cctvId) @GetMapping("/list/{groupId}") public Api cctvInfoList( - @LoginMember Long memberId, @PathVariable Long groupId) { + @LoginMember Long memberId, @PathVariable("groupId") Long groupId) { CctvInfoListResponse cctvInfoListResponse = cctvService.cctvInfoList(memberId, groupId); return Api.success(CctvSuccessType.GET_CCTV_DETAIL_LIST, cctvInfoListResponse); } From 5b0b61ef6e6a8cebe5ccbbbdd4dd7e632941f0e1 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Sat, 23 Nov 2024 15:06:51 +0900 Subject: [PATCH 04/17] =?UTF-8?q?fix:=20=EC=97=90=EB=9F=AC=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EC=9D=BC=EB=B0=98=ED=99=94=ED=95=98=EC=97=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#165)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ioteatime/meonghanyangserver/cctv/service/CctvService.java | 2 +- .../meonghanyangserver/common/type/GroupErrorType.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java b/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java index 78f0c991..aad01c00 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/cctv/service/CctvService.java @@ -113,7 +113,7 @@ private void validateMaster(Long memberId, Long groupId) { () -> new NotFoundException(GroupErrorType.GROUP_MEMBER_NOT_FOUND)); // Member가 Master인지 확인 -> 아니면 에러 if (groupMemberEntity.getRole() != GroupMemberRole.ROLE_MASTER) { - throw new BadRequestException(GroupErrorType.ONLY_MASTER_UPDATE_CCTV_NICKNAME); + throw new BadRequestException(GroupErrorType.ONLY_MASTER); } } } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/common/type/GroupErrorType.java b/src/main/java/org/ioteatime/meonghanyangserver/common/type/GroupErrorType.java index d96904fb..ea699c1e 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/common/type/GroupErrorType.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/common/type/GroupErrorType.java @@ -8,7 +8,8 @@ public enum GroupErrorType implements ErrorTypeCode { ONLY_MASTER_REMOVE_GROUP_MASTER("BAD REQUEST", "방장은 자신을 제외시킬 수 있습니다."), GROUP_MEMBER_NOT_FOUND("GROUP MEMBER NOT FOUND", "그룹 회원 정보를 찾을 수 없습니다."), ONLY_MASTER_GET_GROUP_MEMBER_INFO("BAD REQUEST", "방장만 그룹 참여자 정보를 받을 수 있습니다."), - ONLY_MASTER_UPDATE_CCTV_NICKNAME("BAD REQUEST", "방장만 그룹의 CCTV 이름을 변경할 수 있습니다."); + ONLY_MASTER_UPDATE_CCTV_NICKNAME("BAD REQUEST", "방장만 그룹의 CCTV 이름을 변경할 수 있습니다."), + ONLY_MASTER("BAD REQUEST", "방장 권한이 없습니다."); private final String message; private final String description; From 4d0c6d71718ea0e8183934535e80f7ddd386d4f0 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Sat, 23 Nov 2024 20:50:57 +0900 Subject: [PATCH 05/17] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=EA=B7=B8=EB=A3=B9=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=A5=BC=20join=ED=95=98=EB=8A=94=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=EC=99=80=20=EA=B0=9D=EC=B2=B4=20=EA=B5=AC=ED=98=84=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/dto/db/LoginWithMemberInfo.java | 10 +++++++++ .../member/repository/MemberRepository.java | 3 +++ .../repository/MemberRepositoryImpl.java | 22 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/main/java/org/ioteatime/meonghanyangserver/auth/dto/db/LoginWithMemberInfo.java diff --git a/src/main/java/org/ioteatime/meonghanyangserver/auth/dto/db/LoginWithMemberInfo.java b/src/main/java/org/ioteatime/meonghanyangserver/auth/dto/db/LoginWithMemberInfo.java new file mode 100644 index 00000000..0c3641d3 --- /dev/null +++ b/src/main/java/org/ioteatime/meonghanyangserver/auth/dto/db/LoginWithMemberInfo.java @@ -0,0 +1,10 @@ +package org.ioteatime.meonghanyangserver.auth.dto.db; + +import org.ioteatime.meonghanyangserver.groupmember.doamin.enums.GroupMemberRole; + +public record LoginWithMemberInfo( + Long memberId, + String nickname, + String password, + boolean isGroupMember, + GroupMemberRole role) {} diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/repository/MemberRepository.java b/src/main/java/org/ioteatime/meonghanyangserver/member/repository/MemberRepository.java index 7ea7004d..56c2fd4b 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/member/repository/MemberRepository.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/repository/MemberRepository.java @@ -1,6 +1,7 @@ package org.ioteatime.meonghanyangserver.member.repository; import java.util.Optional; +import org.ioteatime.meonghanyangserver.auth.dto.db.LoginWithMemberInfo; import org.ioteatime.meonghanyangserver.member.domain.MemberEntity; public interface MemberRepository { @@ -13,4 +14,6 @@ public interface MemberRepository { MemberEntity save(MemberEntity MemberEntity); Optional updateFcmTokenById(Long memberId, String token); + + Optional findGroupMemberInfoByEmail(String email); } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/repository/MemberRepositoryImpl.java b/src/main/java/org/ioteatime/meonghanyangserver/member/repository/MemberRepositoryImpl.java index fa48f9a1..461280d6 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/member/repository/MemberRepositoryImpl.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/repository/MemberRepositoryImpl.java @@ -1,10 +1,13 @@ package org.ioteatime.meonghanyangserver.member.repository; +import static org.ioteatime.meonghanyangserver.groupmember.doamin.QGroupMemberEntity.groupMemberEntity; import static org.ioteatime.meonghanyangserver.member.domain.QMemberEntity.memberEntity; +import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import java.util.Optional; import lombok.RequiredArgsConstructor; +import org.ioteatime.meonghanyangserver.auth.dto.db.LoginWithMemberInfo; import org.ioteatime.meonghanyangserver.member.domain.MemberEntity; import org.springframework.stereotype.Repository; @@ -38,4 +41,23 @@ public MemberEntity save(MemberEntity memberEntity) { public Optional updateFcmTokenById(Long memberId, String token) { return jpaMemberRepository.findById(memberId).map(entity -> entity.updateFcmToken(token)); } + + @Override + public Optional findGroupMemberInfoByEmail(String email) { + return Optional.ofNullable( + queryFactory + .select( + Projections.constructor( + LoginWithMemberInfo.class, + memberEntity.id.as("memberId"), + memberEntity.nickname.as("nickname"), + memberEntity.password.as("password"), + groupMemberEntity.id.isNotNull().as("isGroupMember"), + groupMemberEntity.role.as("role"))) + .from(memberEntity) + .leftJoin(groupMemberEntity) + .on(groupMemberEntity.member.eq(memberEntity)) + .where(memberEntity.email.eq(email)) + .fetchOne()); + } } From 22b294a9658dcab545ee671b0508180401a3b732 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Sat, 23 Nov 2024 20:51:37 +0900 Subject: [PATCH 06/17] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=EA=B7=B8=EB=A3=B9=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=ED=95=A8=EA=BB=98=20=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/mapper/AuthResponseMapper.java | 8 ++++++-- .../auth/service/AuthService.java | 17 ++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/auth/mapper/AuthResponseMapper.java b/src/main/java/org/ioteatime/meonghanyangserver/auth/mapper/AuthResponseMapper.java index ae590d7c..9189ebef 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/auth/mapper/AuthResponseMapper.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/auth/mapper/AuthResponseMapper.java @@ -1,5 +1,6 @@ package org.ioteatime.meonghanyangserver.auth.mapper; +import org.ioteatime.meonghanyangserver.auth.dto.db.LoginWithMemberInfo; import org.ioteatime.meonghanyangserver.auth.dto.reponse.LoginResponse; import org.ioteatime.meonghanyangserver.auth.dto.reponse.RefreshResponse; import org.ioteatime.meonghanyangserver.member.dto.response.MemberSimpleResponse; @@ -9,11 +10,14 @@ public static MemberSimpleResponse from(Long id, String email) { return new MemberSimpleResponse(id, email); } - public static LoginResponse from(Long id, String accessToken, String refreshToken) { + public static LoginResponse from( + LoginWithMemberInfo memberInfo, String accessToken, String refreshToken) { return LoginResponse.builder() - .memberId(id) + .memberId(memberInfo.memberId()) .accessToken(accessToken) .refreshToken(refreshToken) + .isGroupMember(memberInfo.isGroupMember()) + .role(memberInfo.role()) .build(); } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/auth/service/AuthService.java b/src/main/java/org/ioteatime/meonghanyangserver/auth/service/AuthService.java index b00dfa57..1d2a7f91 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/auth/service/AuthService.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/auth/service/AuthService.java @@ -5,6 +5,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.ThreadLocalRandom; import lombok.RequiredArgsConstructor; +import org.ioteatime.meonghanyangserver.auth.dto.db.LoginWithMemberInfo; import org.ioteatime.meonghanyangserver.auth.dto.reponse.LoginResponse; import org.ioteatime.meonghanyangserver.auth.dto.request.LoginRequest; import org.ioteatime.meonghanyangserver.auth.mapper.AuthEntityMapper; @@ -39,26 +40,28 @@ public class AuthService { private final RefreshTokenRepository refreshTokenRepository; public LoginResponse login(LoginRequest loginRequest) { - MemberEntity memberEntity = + LoginWithMemberInfo memberInfo = memberRepository - .findByEmail(loginRequest.email()) + .findGroupMemberInfoByEmail(loginRequest.email()) .orElseThrow(() -> new NotFoundException(AuthErrorType.NOT_FOUND)); boolean passwordMatch = - bCryptPasswordEncoder.matches(loginRequest.password(), memberEntity.getPassword()); + bCryptPasswordEncoder.matches(loginRequest.password(), memberInfo.password()); if (!passwordMatch) { throw new BadRequestException(AuthErrorType.PASSWORD_NOT_MATCH); } - String accessToken = jwtUtils.generateAccessToken(memberEntity); - String refreshToken = jwtUtils.generateRefreshToken(memberEntity); + String accessToken = + jwtUtils.generateAccessToken(memberInfo.nickname(), memberInfo.memberId()); + String refreshToken = + jwtUtils.generateRefreshToken(memberInfo.nickname(), memberInfo.memberId()); if (accessToken.isEmpty() || refreshToken.isEmpty()) { throw new NotFoundException(AuthErrorType.TOKEN_NOT_FOUND); } RefreshToken refreshTokenEntity = RefreshToken.builder() - .memberId(memberEntity.getId()) + .memberId(memberInfo.memberId()) .refreshToken(refreshToken) .build(); @@ -66,7 +69,7 @@ public LoginResponse login(LoginRequest loginRequest) { accessToken = jwtUtils.includeBearer(accessToken); refreshToken = jwtUtils.includeBearer(refreshToken); - return AuthResponseMapper.from(memberEntity.getId(), accessToken, refreshToken); + return AuthResponseMapper.from(memberInfo, accessToken, refreshToken); } public MemberSimpleResponse joinProcess(JoinRequest userDto) { From 257e2671321722b69faa9f44f074634dccb7b553 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Sat, 23 Nov 2024 20:51:45 +0900 Subject: [PATCH 07/17] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=EA=B7=B8=EB=A3=B9=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=ED=95=A8=EA=BB=98=20=EC=A1=B0=ED=9A=8C=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=20=EC=8A=A4=ED=8E=99=20=EC=88=98=EC=A0=95=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/dto/reponse/LoginResponse.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/auth/dto/reponse/LoginResponse.java b/src/main/java/org/ioteatime/meonghanyangserver/auth/dto/reponse/LoginResponse.java index 26d46cf4..dbc324aa 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/auth/dto/reponse/LoginResponse.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/auth/dto/reponse/LoginResponse.java @@ -1,21 +1,34 @@ package org.ioteatime.meonghanyangserver.auth.dto.reponse; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.Builder; +import org.ioteatime.meonghanyangserver.groupmember.doamin.enums.GroupMemberRole; +@JsonInclude(JsonInclude.Include.NON_NULL) public record LoginResponse( @NotNull @Schema(description = "회원 ID", example = "1") Long memberId, @NotBlank @Schema(description = "회원 AccessToken", example = "Bearer abcd...") String accessToken, @NotBlank @Schema(description = "회원 RefreshToken", example = "Bearer abcd...") - String refreshToken) { + String refreshToken, + @NotNull @Schema(description = "회원이 가입한 그룹이 있는지 여부", example = "true") + Boolean isGroupMember, + @Schema(description = "회원의 그룹 역할", example = "MASTER") GroupMemberRole role) { @Builder - public LoginResponse(Long memberId, String accessToken, String refreshToken) { + public LoginResponse( + Long memberId, + String accessToken, + String refreshToken, + Boolean isGroupMember, + GroupMemberRole role) { this.memberId = memberId; this.accessToken = accessToken; this.refreshToken = refreshToken; + this.isGroupMember = isGroupMember; + this.role = role; } } From 673757c7f9c1484388798d731a24e4bfa214d2be Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Sat, 23 Nov 2024 20:52:01 +0900 Subject: [PATCH 08/17] =?UTF-8?q?feat:=20Jwt=20=ED=86=A0=ED=81=B0=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=8B=9C=20=EA=B0=9D=EC=B2=B4=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=ED=95=84=EB=93=9C=EB=A5=BC=20=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meonghanyangserver/common/utils/JwtUtils.java | 12 ++++++------ .../member/service/MemberService.java | 2 +- .../cctv/controller/CctvControllerTest.java | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/common/utils/JwtUtils.java b/src/main/java/org/ioteatime/meonghanyangserver/common/utils/JwtUtils.java index b1c6aae5..bb1fa372 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/common/utils/JwtUtils.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/common/utils/JwtUtils.java @@ -28,14 +28,14 @@ public JwtUtils(Environment env, AccessTokenRepository accessTokenRepository) { this.key = Keys.hmacShaKeyFor(decodedKey); } - public String generateAccessToken(MemberEntity memberEntity) { + public String generateAccessToken(String nickname, Long memberId) { Date nowDate = new Date(); Date expiration = new Date(nowDate.getTime() + Duration.ofHours(2).toMillis()); String jwtToken = Jwts.builder() - .claim("name", memberEntity.getNickname()) + .claim("name", nickname) .claim("sub", "meong-ha-nyang") - .claim("jti", String.valueOf(memberEntity.getId())) + .claim("jti", String.valueOf(memberId)) .claim("iat", nowDate) .claim("exp", expiration) .signWith(key) @@ -44,14 +44,14 @@ public String generateAccessToken(MemberEntity memberEntity) { return jwtToken; } - public String generateRefreshToken(MemberEntity memberEntity) { + public String generateRefreshToken(String nickname, Long memberId) { Date nowDate = new Date(); Date expiration = new Date(nowDate.getTime() + Duration.ofDays(30).toMillis()); String jwtToken = Jwts.builder() - .claim("name", memberEntity.getNickname()) + .claim("name", nickname) .claim("sub", "meong-ha-nyang") - .claim("jti", String.valueOf(memberEntity.getId())) + .claim("jti", String.valueOf(memberId)) .claim("iat", nowDate) .claim("exp", expiration) .signWith(key) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java b/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java index 56f4098d..366dea67 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java @@ -148,7 +148,7 @@ public RefreshResponse reissueAccessToken(String authorizationHeader) { throw new BadRequestException(AuthErrorType.TOKEN_NOT_EQUALS); } - String newAccessToken = jwtUtils.generateAccessToken(memberEntity); + String newAccessToken = jwtUtils.generateAccessToken(memberEntity.getNickname(), memberId); newAccessToken = jwtUtils.includeBearer(newAccessToken); return AuthResponseMapper.from(newAccessToken); diff --git a/src/test/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvControllerTest.java b/src/test/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvControllerTest.java index 893cdf26..5b9d0cf0 100644 --- a/src/test/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvControllerTest.java +++ b/src/test/java/org/ioteatime/meonghanyangserver/cctv/controller/CctvControllerTest.java @@ -47,7 +47,9 @@ public void beforeEach() { .password("testpassword") .build(); memberRepository.save(member); - accessToken = jwtUtils.includeBearer(jwtUtils.generateAccessToken(member)); + accessToken = + jwtUtils.includeBearer( + jwtUtils.generateAccessToken(member.getNickname(), member.getId())); } @Test From 45d7437e47511abba40b49e5c477e70bc4067546 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Sat, 23 Nov 2024 21:04:10 +0900 Subject: [PATCH 09/17] =?UTF-8?q?fix:=20API=20=EB=AC=B8=EC=84=9C=20?= =?UTF-8?q?=EB=AC=B8=EA=B5=AC=20=EC=88=98=EC=A0=95=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../groupmember/controller/GroupMemberApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/groupmember/controller/GroupMemberApi.java b/src/main/java/org/ioteatime/meonghanyangserver/groupmember/controller/GroupMemberApi.java index 0b982ae1..e8221402 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/groupmember/controller/GroupMemberApi.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/groupmember/controller/GroupMemberApi.java @@ -24,7 +24,7 @@ public Api deleteMasterGroupMember( @PathVariable Long groupId, @PathVariable Long groupMemberId); - @Operation(summary = "그룹에서 참여자를 제외합니다.", description = "담당자: 최민석") + @Operation(summary = "그룹에서 참여자가 스스로 퇴장합니다.", description = "담당자: 최민석") public Api deleteGroupMember(@LoginMember Long memberId, @PathVariable Long groupId); @Operation(summary = "그룹 참여자들의 정보를 조회합니다.", description = "담당자: 최민석") From bd289698d639fa5a66e43067e8fe8b9f64ead703 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AF=BC=EC=84=9D?= <47300870+seok019283501@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:40:04 +0900 Subject: [PATCH 10/17] empty commit to redeploy staging From b955cfd73f512032f586408050a5638e9c1bc3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=80=EC=9D=B8?= Date: Tue, 26 Nov 2024 15:09:41 +0900 Subject: [PATCH 11/17] empty commit for re-release From 070bededdf1edd15913567d9f0015f81b5aae4d9 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Tue, 26 Nov 2024 21:55:05 +0900 Subject: [PATCH 12/17] =?UTF-8?q?fix:=20RT=20=EC=9C=A0=ED=9A=A8=20?= =?UTF-8?q?=EA=B8=B0=EA=B0=84=20=EC=B6=95=EC=86=8C=20(#175)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ioteatime/meonghanyangserver/redis/RefreshToken.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/redis/RefreshToken.java b/src/main/java/org/ioteatime/meonghanyangserver/redis/RefreshToken.java index 4289c2f8..d138b428 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/redis/RefreshToken.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/redis/RefreshToken.java @@ -10,7 +10,7 @@ @Getter @AllArgsConstructor @Builder -@RedisHash(value = "refreshToken", timeToLive = 60 * 60 * 24 * 30) +@RedisHash(value = "refreshToken", timeToLive = 60 * 60 * 24 * 14) public class RefreshToken { @Id private Long id; From fa0c2b4b0fc60c3d1aca6776c4c809d8ade5387c Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Tue, 26 Nov 2024 21:55:31 +0900 Subject: [PATCH 13/17] =?UTF-8?q?fix:=20Redis=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=97=86=EC=9D=B4=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20(#175)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ioteatime/meonghanyangserver/config/RedisConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java b/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java index 4d5fa606..f2fa3416 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java @@ -27,7 +27,7 @@ public RedisConnectionFactory redisConnectionFactory() { RedisStandaloneConfiguration redisConfiguration = new RedisStandaloneConfiguration(); redisConfiguration.setHostName(host); redisConfiguration.setPort(Integer.parseInt(port)); - redisConfiguration.setPassword(password); +// redisConfiguration.setPassword(password); return new LettuceConnectionFactory(redisConfiguration); } } From d15b80668c7ed78d2b2482508c7e3ceed981179b Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Tue, 26 Nov 2024 22:09:22 +0900 Subject: [PATCH 14/17] =?UTF-8?q?chore:=20Spotless=20=EC=A0=81=EC=9A=A9=20?= =?UTF-8?q?(#175)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ioteatime/meonghanyangserver/config/RedisConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java b/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java index f2fa3416..8f6e04c4 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java @@ -27,7 +27,7 @@ public RedisConnectionFactory redisConnectionFactory() { RedisStandaloneConfiguration redisConfiguration = new RedisStandaloneConfiguration(); redisConfiguration.setHostName(host); redisConfiguration.setPort(Integer.parseInt(port)); -// redisConfiguration.setPassword(password); + // redisConfiguration.setPassword(password); return new LettuceConnectionFactory(redisConfiguration); } } From be8ff682fce371d8dcf4fd9910fd0b2c8da28bca Mon Sep 17 00:00:00 2001 From: Wonchae Yang <79977182+ywonchae1@users.noreply.github.com> Date: Tue, 26 Nov 2024 22:49:40 +0900 Subject: [PATCH 15/17] =?UTF-8?q?fix:=20ElastiCache=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20(#179)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: ElastiCache 설정 추가 (#175) * fix: Redis 설정 복구 테스트 (#175) * fix: CICD 파이프라인 복구 (#175) --- .../org/ioteatime/meonghanyangserver/config/RedisConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java b/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java index 8f6e04c4..97bf673b 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/config/RedisConfig.java @@ -11,7 +11,8 @@ @Configuration @EnableRedisRepositories( - enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP) + enableKeyspaceEvents = RedisKeyValueAdapter.EnableKeyspaceEvents.ON_STARTUP, + keyspaceNotificationsConfigParameter = "") public class RedisConfig { @Value("${spring.data.redis.host}") private String host; @@ -27,7 +28,7 @@ public RedisConnectionFactory redisConnectionFactory() { RedisStandaloneConfiguration redisConfiguration = new RedisStandaloneConfiguration(); redisConfiguration.setHostName(host); redisConfiguration.setPort(Integer.parseInt(port)); - // redisConfiguration.setPassword(password); + redisConfiguration.setPassword(password); return new LettuceConnectionFactory(redisConfiguration); } } From b7c8f8939cbfde78103a969a704d6edce26de931 Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Wed, 27 Nov 2024 10:12:24 +0900 Subject: [PATCH 16/17] =?UTF-8?q?refactor:=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=8B=9C=20=EA=B7=B8=EB=A3=B9=20=EC=A0=95=EB=B3=B4=EB=8F=84=20?= =?UTF-8?q?=ED=95=A8=EA=BB=98=20=EC=A1=B0=ED=9A=8C=20(#181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberApi.java | 7 ++----- .../member/controller/MemberController.java | 7 ++++--- .../member/dto/response/GroupDetailResponse.java | 14 ++++++++++++++ .../response/MemberWithGroupDetailResponse.java | 16 ++++++++++++++++ .../member/mapper/MemberResponseMapper.java | 16 +++++++++++++--- .../member/service/MemberService.java | 13 ++++++++++--- 6 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/ioteatime/meonghanyangserver/member/dto/response/GroupDetailResponse.java create mode 100644 src/main/java/org/ioteatime/meonghanyangserver/member/dto/response/MemberWithGroupDetailResponse.java diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/controller/MemberApi.java b/src/main/java/org/ioteatime/meonghanyangserver/member/controller/MemberApi.java index f55eb980..2662b326 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/member/controller/MemberApi.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/controller/MemberApi.java @@ -8,7 +8,7 @@ import org.ioteatime.meonghanyangserver.group.dto.response.UpdateNicknameAndGroupNameResponse; import org.ioteatime.meonghanyangserver.member.dto.request.ChangePasswordRequest; import org.ioteatime.meonghanyangserver.member.dto.request.UpdateNicknameAndGroupNameRequest; -import org.ioteatime.meonghanyangserver.member.dto.response.MemberDetailResponse; +import org.ioteatime.meonghanyangserver.member.dto.response.MemberWithGroupDetailResponse; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; @@ -17,7 +17,7 @@ public interface MemberApi { @Operation(summary = "회원 상세 정보를 조회합니다.", description = "담당자: 임지인") - Api getMemberDetail(@PathVariable("memberId") Long memberId); + Api getMemberDetail(@PathVariable("memberId") Long memberId); @Operation(summary = "회원 정보를 삭제합니다.", description = "담당자: 임지인") Api deleteMember(@LoginMember Long memberId); @@ -35,7 +35,4 @@ Api changeMemberPassword( "담당자: 양원채\n\n닉네임 또는 그룹명을 갱신할 수 있으며, 한꺼번에 갱신도 가능합니다.\n\n갱신하고 싶지 않은 필드는 아예 적지 않거나 null로 담아 요청하시면 됩니다. 응답으로는 변경된 사항만 응답합니다.") Api updateNicknameAndGroupName( @LoginMember Long memberId, @RequestBody UpdateNicknameAndGroupNameRequest request); - - @Operation(summary = "로그아웃을 진행합니다.", description = "담당자: 최민석") - Api logout(); } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/controller/MemberController.java b/src/main/java/org/ioteatime/meonghanyangserver/member/controller/MemberController.java index 7052a6a0..d2c39a50 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/member/controller/MemberController.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/controller/MemberController.java @@ -10,7 +10,7 @@ import org.ioteatime.meonghanyangserver.group.dto.response.UpdateNicknameAndGroupNameResponse; import org.ioteatime.meonghanyangserver.member.dto.request.ChangePasswordRequest; import org.ioteatime.meonghanyangserver.member.dto.request.UpdateNicknameAndGroupNameRequest; -import org.ioteatime.meonghanyangserver.member.dto.response.MemberDetailResponse; +import org.ioteatime.meonghanyangserver.member.dto.response.MemberWithGroupDetailResponse; import org.ioteatime.meonghanyangserver.member.service.MemberService; import org.springframework.web.bind.annotation.*; @@ -21,8 +21,9 @@ public class MemberController implements MemberApi { private final MemberService memberService; @GetMapping("/{memberId}") - public Api getMemberDetail(@PathVariable("memberId") Long memberId) { - MemberDetailResponse userDto = memberService.getMemberDetail(memberId); + public Api getMemberDetail( + @PathVariable("memberId") Long memberId) { + MemberWithGroupDetailResponse userDto = memberService.getMemberDetail(memberId); return Api.success(AuthSuccessType.GET_USER_DETAIL, userDto); } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/dto/response/GroupDetailResponse.java b/src/main/java/org/ioteatime/meonghanyangserver/member/dto/response/GroupDetailResponse.java new file mode 100644 index 00000000..c85523cc --- /dev/null +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/dto/response/GroupDetailResponse.java @@ -0,0 +1,14 @@ +package org.ioteatime.meonghanyangserver.member.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import org.ioteatime.meonghanyangserver.group.domain.GroupEntity; + +@Schema(description = "그룹의 상세 정보 조회") +public record GroupDetailResponse( + @NotNull @Schema(description = "그룹 ID", example = "1") Long id, + @NotNull @Schema(description = "그룹 이름", example = "멍하냥 그룹") String groupName) { + public static GroupDetailResponse from(GroupEntity group) { + return new GroupDetailResponse(group.getId(), group.getGroupName()); + } +} diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/dto/response/MemberWithGroupDetailResponse.java b/src/main/java/org/ioteatime/meonghanyangserver/member/dto/response/MemberWithGroupDetailResponse.java new file mode 100644 index 00000000..d9dd7194 --- /dev/null +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/dto/response/MemberWithGroupDetailResponse.java @@ -0,0 +1,16 @@ +package org.ioteatime.meonghanyangserver.member.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.Builder; + +@Schema(description = "회원 및 그룹 정보 조회") +public record MemberWithGroupDetailResponse( + @NotNull @Schema(description = "회원 정보") MemberDetailResponse member, + @Schema(description = "그룹 정보") GroupDetailResponse group) { + @Builder + public MemberWithGroupDetailResponse(MemberDetailResponse member, GroupDetailResponse group) { + this.member = member; + this.group = group; + } +} diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/mapper/MemberResponseMapper.java b/src/main/java/org/ioteatime/meonghanyangserver/member/mapper/MemberResponseMapper.java index c2814fbb..92d823ba 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/member/mapper/MemberResponseMapper.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/mapper/MemberResponseMapper.java @@ -1,11 +1,21 @@ package org.ioteatime.meonghanyangserver.member.mapper; +import org.ioteatime.meonghanyangserver.group.domain.GroupEntity; import org.ioteatime.meonghanyangserver.member.domain.MemberEntity; +import org.ioteatime.meonghanyangserver.member.dto.response.GroupDetailResponse; import org.ioteatime.meonghanyangserver.member.dto.response.MemberDetailResponse; +import org.ioteatime.meonghanyangserver.member.dto.response.MemberWithGroupDetailResponse; public class MemberResponseMapper { - public static MemberDetailResponse from(MemberEntity member) { - return new MemberDetailResponse( - member.getId(), member.getEmail(), member.getProfileImgUrl(), member.getNickname()); + public static MemberWithGroupDetailResponse from(MemberEntity member, GroupEntity group) { + MemberDetailResponse memberDetail = MemberDetailResponse.from(member); + if (group != null) { + GroupDetailResponse groupDetail = GroupDetailResponse.from(group); + return MemberWithGroupDetailResponse.builder() + .member(memberDetail) + .group(groupDetail) + .build(); + } + return MemberWithGroupDetailResponse.builder().member(memberDetail).build(); } } diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java b/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java index 366dea67..ef50135f 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java @@ -23,7 +23,7 @@ import org.ioteatime.meonghanyangserver.member.domain.MemberEntity; import org.ioteatime.meonghanyangserver.member.dto.request.ChangePasswordRequest; import org.ioteatime.meonghanyangserver.member.dto.request.UpdateNicknameAndGroupNameRequest; -import org.ioteatime.meonghanyangserver.member.dto.response.MemberDetailResponse; +import org.ioteatime.meonghanyangserver.member.dto.response.MemberWithGroupDetailResponse; import org.ioteatime.meonghanyangserver.member.mapper.MemberResponseMapper; import org.ioteatime.meonghanyangserver.member.repository.MemberRepository; import org.ioteatime.meonghanyangserver.redis.AccessTokenRepository; @@ -51,13 +51,20 @@ public class MemberService { private final RefreshTokenRepository refreshTokenRepository; private final AccessTokenRepository accessTokenRepository; - public MemberDetailResponse getMemberDetail(Long memberId) { + public MemberWithGroupDetailResponse getMemberDetail(Long memberId) { MemberEntity memberEntity = memberRepository .findById(memberId) .orElseThrow(() -> new NotFoundException(AuthErrorType.NOT_FOUND)); - return MemberResponseMapper.from(memberEntity); + GroupMemberEntity groupMemberEntity = + groupMemberRepository.findByMemberId(memberId).orElse(null); + GroupEntity groupEntity = null; + if (groupMemberEntity != null) { + groupEntity = groupMemberEntity.getGroup(); + } + + return MemberResponseMapper.from(memberEntity, groupEntity); } // NOTE. From fe8218bac509e4feeed0fb2e1e7f8c770784d3bf Mon Sep 17 00:00:00 2001 From: ywonchae1 Date: Wed, 27 Nov 2024 10:17:00 +0900 Subject: [PATCH 17/17] =?UTF-8?q?fix:=20Optional=20=ED=99=9C=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20(#181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meonghanyangserver/member/service/MemberService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java b/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java index ef50135f..487087c3 100644 --- a/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java +++ b/src/main/java/org/ioteatime/meonghanyangserver/member/service/MemberService.java @@ -1,6 +1,7 @@ package org.ioteatime.meonghanyangserver.member.service; import java.util.List; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ioteatime.meonghanyangserver.auth.dto.reponse.RefreshResponse; import org.ioteatime.meonghanyangserver.auth.mapper.AuthResponseMapper; @@ -57,11 +58,11 @@ public MemberWithGroupDetailResponse getMemberDetail(Long memberId) { .findById(memberId) .orElseThrow(() -> new NotFoundException(AuthErrorType.NOT_FOUND)); - GroupMemberEntity groupMemberEntity = - groupMemberRepository.findByMemberId(memberId).orElse(null); + Optional groupMemberEntity = + groupMemberRepository.findByMemberId(memberId); GroupEntity groupEntity = null; - if (groupMemberEntity != null) { - groupEntity = groupMemberEntity.getGroup(); + if (groupMemberEntity.isPresent()) { + groupEntity = groupMemberEntity.get().getGroup(); } return MemberResponseMapper.from(memberEntity, groupEntity);