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/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/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 2abe8016..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 @@ -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.ProfileUtil; 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 ProfileUtil profileUtil; + private final AES256Util aes; @Transactional public SignupResponseDto signup(SignupRequestDto request) { @@ -87,10 +91,16 @@ 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 (profileUtil.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()); + // encrypt and return + return SignupResponseDto.of(aes.encrypt(member.getId().toString()), member.getName(), profile.getNickname()); } @Transactional @@ -182,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 d091d4a5..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 @@ -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,14 +73,15 @@ 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()); } @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()); } 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..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()) && - profileRepository.existsByNickname(request.getNickname())) { + profileUtil.isDuplicatedNickname(request.getNickname())) { throw new DuplicateException(ErrorCode.DUPLICATE_NICKNAME); } 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; + } +}