Skip to content

Commit

Permalink
Fix: 닉네임 중복 에러 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
gkdudans committed Nov 30, 2024
1 parent 94d8ed2 commit b78c02b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Member extends BaseTimeEntity {
@NotNull
private Long kakaoId;

@Column(name = "nickname")
@Column(name = "nickname", unique = true)
@NotNull
private String nickname;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bookwoori.core.domain.member.dto.response.MemberResponseDto;
import org.bookwoori.core.domain.member.entity.Member;
import org.bookwoori.core.domain.member.service.MemberService;
import org.bookwoori.core.global.exception.CustomException;
import org.bookwoori.core.global.exception.ErrorCode;
import org.bookwoori.core.global.s3.S3Util;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -23,6 +25,12 @@ public class MemberFacade {

public void updateMember(UpdateMemberRequestDto requestDto) {
Member currentMember = memberService.getCurrentMember();
String newNickname = requestDto.nickname();
if (!currentMember.getNickname().equals(newNickname)) {
if (memberService.existsByNickname(newNickname)) {
throw new CustomException(ErrorCode.ALREADY_EXIST_NICKNAME);
}
}
String profileImgUrl = updateImage(requestDto.profileImg(), currentMember.getProfileImg(),
"member/profile-image");
String backgroundImgUrl = updateImage(requestDto.backgroundImg(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
Long findIdByKakaoId(@Param("kakaoId") Long kakaoId);

boolean existsByKakaoId(Long kakaoId);

boolean existsByNickname(String newNickname);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public void saveMember(Member member) {
public boolean existsByKakaoId(Long kakaoId) {
return memberRepository.existsByKakaoId(kakaoId);
}

@Transactional(readOnly = true)
public boolean existsByNickname(String newNickname) {
return memberRepository.existsByNickname(newNickname);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public enum ErrorCode {
// Member (3000 ~ 3099)
MEMBER_NOT_FOUND(404, 3000, "사용자를 찾을 수 없습니다."),
MEMBER_INACTIVE(404, 3001, "이미 계정을 삭제한 멤버입니다."),
ALREADY_EXIST_NICKNAME(409, 3002, "이미 존재하는 닉네임입니다."),

// Server (3100 ~ 3199)
SERVER_NOT_FOUND(404, 3100, "서버를 찾을 수 없습니다."),
Expand Down

0 comments on commit b78c02b

Please sign in to comment.