From c9e569d0b66e0fc3b0c19d2414311014a3d6bf20 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 31 May 2023 22:40:55 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[refactor]=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EB=8B=89=EB=84=A4=EC=9E=84=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=20#162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/kr/co/wingle/member/service/AuthService.java | 7 ++++++- .../main/java/kr/co/wingle/profile/ProfileService.java | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java b/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java index 2abe8016..5d522372 100644 --- a/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java +++ b/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java @@ -87,7 +87,12 @@ public SignupResponseDto signup(SignupRequestDto request) { getTermAndSaveTermMember(member, TermCode.TERMS_OF_PROMOTION, request.isTermsOfPromotion()); // save profile - Profile profile = Profile.createProfile(member, request.getNickname(), request.isGender(), request.getNation()); + if (profileService.isDuplicatedNickname(request.getNickname())) { + throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME); + } + + Profile profile = Profile.createProfile(member, request.getNickname(), request.isGender(), + request.getNation()); profileRepository.save(profile); return SignupResponseDto.of(member.getId(), member.getName(), profile.getNickname()); diff --git a/wingle/src/main/java/kr/co/wingle/profile/ProfileService.java b/wingle/src/main/java/kr/co/wingle/profile/ProfileService.java index cb6e610f..1c960476 100644 --- a/wingle/src/main/java/kr/co/wingle/profile/ProfileService.java +++ b/wingle/src/main/java/kr/co/wingle/profile/ProfileService.java @@ -57,7 +57,7 @@ public ProfileResponseDto saveProfile(ProfileRequestDto request) { Profile profile = getProfile(member); if (!profile.getNickname().equals(request.getNickname()) && - profileRepository.existsByNickname(request.getNickname())) { + isDuplicatedNickname(request.getNickname())) { throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME); } @@ -222,4 +222,12 @@ public ProfileGetResponseDto getUserProfile(String id) throws return response; } + + public boolean isDuplicatedNickname(String newNickname) { + if (profileRepository.existsByNickname(newNickname)) { + throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME); + } + + return false; + } } From 8d0c39749cd3213174ae823586d1320d4f4cbcbc Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 31 May 2023 22:41:01 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[feat]=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=9C=A0=EC=A0=80=EC=95=84=EC=9D=B4=EB=94=94=20?= =?UTF-8?q?=EC=95=94=ED=98=B8=ED=99=94=20#162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/kr/co/wingle/member/dto/SignupResponseDto.java | 4 ++-- .../main/java/kr/co/wingle/member/service/AuthService.java | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/wingle/src/main/java/kr/co/wingle/member/dto/SignupResponseDto.java b/wingle/src/main/java/kr/co/wingle/member/dto/SignupResponseDto.java index 198e28ef..698fb16c 100644 --- a/wingle/src/main/java/kr/co/wingle/member/dto/SignupResponseDto.java +++ b/wingle/src/main/java/kr/co/wingle/member/dto/SignupResponseDto.java @@ -7,11 +7,11 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class SignupResponseDto { - private Long id; + private String id; private String name; private String nickname; - public static SignupResponseDto of(Long id, String name, String nickname) { + public static SignupResponseDto of(String id, String name, String nickname) { SignupResponseDto responseDto = new SignupResponseDto(); responseDto.id = id; responseDto.name = name; diff --git a/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java b/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java index 5d522372..4e57334d 100644 --- a/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java +++ b/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java @@ -18,6 +18,7 @@ import kr.co.wingle.common.exception.NotFoundException; import kr.co.wingle.common.jwt.TokenInfo; import kr.co.wingle.common.jwt.TokenProvider; +import kr.co.wingle.common.util.AES256Util; import kr.co.wingle.common.util.RedisUtil; import kr.co.wingle.common.util.S3Util; import kr.co.wingle.common.util.SecurityUtil; @@ -50,6 +51,7 @@ import kr.co.wingle.member.mailVo.CodeMail; import kr.co.wingle.member.mailVo.RejectionMail; import kr.co.wingle.profile.ProfileRepository; +import kr.co.wingle.profile.ProfileService; import kr.co.wingle.profile.entity.Profile; import lombok.RequiredArgsConstructor; @@ -67,6 +69,8 @@ public class AuthService { private final RedisUtil redisUtil; private final MailService mailService; private final MemberService memberService; + private final ProfileService profileService; + private final AES256Util aes; @Transactional public SignupResponseDto signup(SignupRequestDto request) { @@ -95,7 +99,8 @@ public SignupResponseDto signup(SignupRequestDto request) { request.getNation()); profileRepository.save(profile); - return SignupResponseDto.of(member.getId(), member.getName(), profile.getNickname()); + // encrypt and return + return SignupResponseDto.of(aes.encrypt(member.getId().toString()), member.getName(), profile.getNickname()); } @Transactional From 3ea95e7cf1342d9dd595a49360220995c453d449 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 31 May 2023 22:47:20 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=20[feat]=20=EB=A9=94=EB=AA=A8=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EC=9C=A0=EC=A0=80=EC=95=84=EC=9D=B4=EB=94=94=20?= =?UTF-8?q?=EC=95=94=ED=98=B8=ED=99=94=20#162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/kr/co/wingle/member/dto/MemoRequestDto.java | 2 +- .../main/java/kr/co/wingle/member/service/MemberService.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/wingle/src/main/java/kr/co/wingle/member/dto/MemoRequestDto.java b/wingle/src/main/java/kr/co/wingle/member/dto/MemoRequestDto.java index 2fd2c986..088213c5 100644 --- a/wingle/src/main/java/kr/co/wingle/member/dto/MemoRequestDto.java +++ b/wingle/src/main/java/kr/co/wingle/member/dto/MemoRequestDto.java @@ -7,7 +7,7 @@ @Getter public class MemoRequestDto { @NotNull(message = "사용자 id가 없습니다.") - private Long userId; + private String userId; @NotNull(message = "메모가 없습니다.") private String memo; } diff --git a/wingle/src/main/java/kr/co/wingle/member/service/MemberService.java b/wingle/src/main/java/kr/co/wingle/member/service/MemberService.java index d091d4a5..62a5faa3 100644 --- a/wingle/src/main/java/kr/co/wingle/member/service/MemberService.java +++ b/wingle/src/main/java/kr/co/wingle/member/service/MemberService.java @@ -10,6 +10,7 @@ import kr.co.wingle.common.constants.ErrorCode; import kr.co.wingle.common.exception.ForbiddenException; import kr.co.wingle.common.exception.NotFoundException; +import kr.co.wingle.common.util.AES256Util; import kr.co.wingle.member.MemberRepository; import kr.co.wingle.member.dto.MemoRequestDto; import kr.co.wingle.member.dto.MemoResponseDto; @@ -27,6 +28,7 @@ public class MemberService { private final MemberRepository memberRepository; private final ProfileRepository profileRepository; + private final AES256Util aes; private final int pageSize = 10; @Transactional(readOnly = true) @@ -71,7 +73,8 @@ public WaitingUserResponseDto getWaitingUserInfo(Long userId) { @Transactional public MemoResponseDto saveMemo(MemoRequestDto memoRequestDto) { - Member member = findMemberByMemberId(memoRequestDto.getUserId()); + + Member member = findMemberByMemberId(Long.parseLong(aes.decrypt(memoRequestDto.getUserId()))); member.setMemo(memoRequestDto.getMemo()); return MemoResponseDto.from(memoRequestDto.getMemo()); } From 53efb896b0c8d8a6ed73f393ddb30564dac77096 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 31 May 2023 22:49:09 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[feat]=20=EA=B1=B0=EC=A0=88=20=EC=82=AC?= =?UTF-8?q?=EC=9C=A0=20=EC=A0=80=EC=9E=A5=20=EC=9C=A0=EC=A0=80=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=20=EC=95=94=ED=98=B8=ED=99=94=20#162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/kr/co/wingle/member/dto/RejectionRequestDto.java | 2 +- .../src/main/java/kr/co/wingle/member/service/AuthService.java | 2 +- .../main/java/kr/co/wingle/member/service/MemberService.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wingle/src/main/java/kr/co/wingle/member/dto/RejectionRequestDto.java b/wingle/src/main/java/kr/co/wingle/member/dto/RejectionRequestDto.java index e5558a44..db82a07a 100644 --- a/wingle/src/main/java/kr/co/wingle/member/dto/RejectionRequestDto.java +++ b/wingle/src/main/java/kr/co/wingle/member/dto/RejectionRequestDto.java @@ -10,7 +10,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class RejectionRequestDto { @NotNull(message = "사용자 id가 없습니다.") - private Long userId; + private String userId; @NotNull(message = "거절 사유가 없습니다.") private String reason; } diff --git a/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java b/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java index 4e57334d..1f2ada2f 100644 --- a/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java +++ b/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java @@ -192,7 +192,7 @@ public PermissionResponseDto sendAcceptanceMail(AcceptanceRequestDto acceptanceR @Transactional public PermissionResponseDto sendRejectionMail(RejectionRequestDto rejectionRequestDto) { - Long userId = rejectionRequestDto.getUserId(); + Long userId = Long.parseLong(aes.decrypt(rejectionRequestDto.getUserId())); Member member = memberService.findMemberByMemberId(userId); if (member.getPermission() == Permission.DENY.getStatus()) throw new CustomException(ErrorCode.ALREADY_DENY); diff --git a/wingle/src/main/java/kr/co/wingle/member/service/MemberService.java b/wingle/src/main/java/kr/co/wingle/member/service/MemberService.java index 62a5faa3..68afec5e 100644 --- a/wingle/src/main/java/kr/co/wingle/member/service/MemberService.java +++ b/wingle/src/main/java/kr/co/wingle/member/service/MemberService.java @@ -81,7 +81,7 @@ public MemoResponseDto saveMemo(MemoRequestDto memoRequestDto) { @Transactional public RejectionResponseDto saveRejectionReason(RejectionRequestDto request) { - Member member = findMemberByMemberId(request.getUserId()); + Member member = findMemberByMemberId(Long.parseLong(aes.decrypt(request.getUserId()))); member.setRejectionReason(request.getReason()); return RejectionResponseDto.from(request.getReason()); } From 78b925b32723747374182573140e5f6d271c0c08 Mon Sep 17 00:00:00 2001 From: silver Date: Wed, 31 May 2023 22:54:09 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[fix]=20=EB=8B=89=EB=84=A4=EC=9E=84=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=88=9C=ED=99=98=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20#162?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../co/wingle/member/service/AuthService.java | 6 ++--- .../kr/co/wingle/profile/ProfileService.java | 13 ++--------- .../kr/co/wingle/profile/ProfileUtil.java | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 wingle/src/main/java/kr/co/wingle/profile/ProfileUtil.java diff --git a/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java b/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java index 1f2ada2f..0c4b8f93 100644 --- a/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java +++ b/wingle/src/main/java/kr/co/wingle/member/service/AuthService.java @@ -51,7 +51,7 @@ import kr.co.wingle.member.mailVo.CodeMail; import kr.co.wingle.member.mailVo.RejectionMail; import kr.co.wingle.profile.ProfileRepository; -import kr.co.wingle.profile.ProfileService; +import kr.co.wingle.profile.ProfileUtil; import kr.co.wingle.profile.entity.Profile; import lombok.RequiredArgsConstructor; @@ -69,7 +69,7 @@ public class AuthService { private final RedisUtil redisUtil; private final MailService mailService; private final MemberService memberService; - private final ProfileService profileService; + private final ProfileUtil profileUtil; private final AES256Util aes; @Transactional @@ -91,7 +91,7 @@ public SignupResponseDto signup(SignupRequestDto request) { getTermAndSaveTermMember(member, TermCode.TERMS_OF_PROMOTION, request.isTermsOfPromotion()); // save profile - if (profileService.isDuplicatedNickname(request.getNickname())) { + if (profileUtil.isDuplicatedNickname(request.getNickname())) { throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME); } diff --git a/wingle/src/main/java/kr/co/wingle/profile/ProfileService.java b/wingle/src/main/java/kr/co/wingle/profile/ProfileService.java index 1c960476..0a6d741b 100644 --- a/wingle/src/main/java/kr/co/wingle/profile/ProfileService.java +++ b/wingle/src/main/java/kr/co/wingle/profile/ProfileService.java @@ -13,7 +13,6 @@ import kr.co.wingle.common.constants.ErrorCode; import kr.co.wingle.common.exception.DuplicateException; import kr.co.wingle.common.exception.NotFoundException; -import kr.co.wingle.common.util.AES256Util; import kr.co.wingle.common.util.S3Util; import kr.co.wingle.member.entity.Member; import kr.co.wingle.member.service.AuthService; @@ -46,7 +45,7 @@ public class ProfileService { private final InterestRepository interestRepository; private final SnsRepository snsRepository; private final S3Util s3Util; - private final AES256Util aes; + private final ProfileUtil profileUtil; @Transactional public ProfileResponseDto saveProfile(ProfileRequestDto request) { @@ -57,7 +56,7 @@ public ProfileResponseDto saveProfile(ProfileRequestDto request) { Profile profile = getProfile(member); if (!profile.getNickname().equals(request.getNickname()) && - isDuplicatedNickname(request.getNickname())) { + profileUtil.isDuplicatedNickname(request.getNickname())) { throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME); } @@ -222,12 +221,4 @@ public ProfileGetResponseDto getUserProfile(String id) throws return response; } - - public boolean isDuplicatedNickname(String newNickname) { - if (profileRepository.existsByNickname(newNickname)) { - throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME); - } - - return false; - } } diff --git a/wingle/src/main/java/kr/co/wingle/profile/ProfileUtil.java b/wingle/src/main/java/kr/co/wingle/profile/ProfileUtil.java new file mode 100644 index 00000000..e4663d33 --- /dev/null +++ b/wingle/src/main/java/kr/co/wingle/profile/ProfileUtil.java @@ -0,0 +1,23 @@ +package kr.co.wingle.profile; + +import org.springframework.stereotype.Component; + +import kr.co.wingle.common.constants.ErrorCode; +import kr.co.wingle.common.exception.DuplicateException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RequiredArgsConstructor +@Component +public class ProfileUtil { + private final ProfileRepository profileRepository; + + public boolean isDuplicatedNickname(String newNickname) { + if (profileRepository.existsByNickname(newNickname)) { + throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME); + } + + return false; + } +}