Skip to content

Commit

Permalink
feat: 닉네임 중복검사
Browse files Browse the repository at this point in the history
  • Loading branch information
char-yb committed Jan 17, 2024
1 parent 5e16273 commit 72cbf6c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.depromeet.domain.auth.dto.request.UsernameCheckRequest;
import com.depromeet.domain.member.application.MemberService;
import com.depromeet.domain.member.dto.request.NicknameCheckRequest;
import com.depromeet.domain.member.dto.response.MemberFindOneResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -32,6 +33,14 @@ public ResponseEntity<Void> memberUsernameCheck(
return ResponseEntity.ok().build();
}

@Operation(summary = "닉네임 중복 체크", description = "닉네임 중복 체크를 진행합니다.")
@PostMapping("/check-nickname")
public ResponseEntity<Void> memberNicknameCheck(
@Valid @RequestBody NicknameCheckRequest request) {
memberService.checkNickname(request);
return ResponseEntity.ok().build();
}

// TODO: 테스트 코드 작성 필요
@Operation(summary = "회원 탈퇴", description = "회원탈퇴를 진행합니다.")
@DeleteMapping("/withdrawal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.depromeet.domain.auth.dto.request.UsernameCheckRequest;
import com.depromeet.domain.member.dao.MemberRepository;
import com.depromeet.domain.member.domain.Member;
import com.depromeet.domain.member.dto.request.NicknameCheckRequest;
import com.depromeet.domain.member.dto.response.MemberFindOneResponse;
import com.depromeet.global.error.exception.CustomException;
import com.depromeet.global.error.exception.ErrorCode;
Expand Down Expand Up @@ -34,6 +35,13 @@ public void checkUsername(UsernameCheckRequest request) {
}
}

@Transactional(readOnly = true)
public void checkNickname(NicknameCheckRequest request) {
if (memberRepository.existsByProfileNickname(request.nickname())) {
throw new CustomException(ErrorCode.MEMBER_ALREADY_NICKNAME);
}
}

public void withdrawal(UsernameCheckRequest request) {
final Member member =
memberRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public interface MemberRepository extends JpaRepository<Member, Long> {

boolean existsByUsername(String username);

boolean existsByProfileNickname(String nickname);

Optional<Member> findByUsername(String username);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.depromeet.domain.member.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

public record NicknameCheckRequest(
@NotNull(message = "닉네임은 비워둘 수 없습니다.")
@Schema(description = "회원 닉네임", defaultValue = "nickname")
String nickname) {}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum ErrorCode {
INVALID_ACCESS_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 엑세스 토큰입니다."),
INVALID_REFRESH_TOKEN(HttpStatus.UNAUTHORIZED, "유효하지 않은 리프레시 토큰입니다."),
MEMBER_ALREADY_REGISTERED(HttpStatus.CONFLICT, "이미 가입된 회원입니다."),
MEMBER_ALREADY_NICKNAME(HttpStatus.CONFLICT, "이미 존재하는 닉네임입니다."),
MEMBER_ALREADY_DELETED(HttpStatus.NOT_FOUND, "이미 탈퇴한 회원입니다."),
SOCIAL_AUTHENTICATION_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "서버 오류로 인해 소셜 로그인에 실패했습니다."),
INVALID_APPLE_PRIVATE_KEY(HttpStatus.INTERNAL_SERVER_ERROR, "애플 로그인에 필요한 비밀 키가 올바르지 않습니다."),
Expand Down

0 comments on commit 72cbf6c

Please sign in to comment.