Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nickname duplication check API #56

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/fullcar/core/response/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum ErrorCode {
EMAIL_ADDRESS_IN_BLACKLIST(BAD_REQUEST, "λΈ”λž™λ¦¬μŠ€νŠΈμ— μžˆλŠ” 이메일 μ£Όμ†Œμž…λ‹ˆλ‹€."),
CANNOT_SEND_TO_OWN_CARPOOL(BAD_REQUEST, "μžκΈ°μžμ‹ μ˜ μΉ΄ν’€μ—λŠ” μ‹ μ²­ν•  수 μ—†μŠ΅λ‹ˆλ‹€."),
DUPLICATED_FORM(BAD_REQUEST, "이미 μš”μ²­μ„ 보낸 μΉ΄ν’€μž…λ‹ˆλ‹€."),
DUPLICATED_NICKNAME(BAD_REQUEST, "μ€‘λ³΅λœ λ‹‰λ„€μž„ μž…λ‹ˆλ‹€."),

/* 401 UNAUTHORIZED */
UNAUTHORIZED_KAKAO_TOKEN(UNAUTHORIZED, "μœ νš¨ν•˜μ§€ μ•Šμ€ 카카였 토큰"),
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/fullcar/core/response/SuccessCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum SuccessCode {
SIGNIN_SUCCESS(OK, "μ†Œμ…œλ‘œκ·ΈμΈ 성곡"),
GET_NEW_TOKEN_SUCCESS(OK, "토큰 μž¬λ°œκΈ‰ 성곡"),
READ_SUCCESS(OK, "쑰회 성곡"),
EMAIL_SENT_SUCCESS(OK, "인증메일 λ°œμ†‘ 성곡");
EMAIL_SENT_SUCCESS(OK, "인증메일 λ°œμ†‘ 성곡"),
AVAILABLE_NICKNAME(OK, "μ‚¬μš© κ°€λŠ₯ν•œ λ‹‰λ„€μž„");

private final HttpStatus status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.fullcar.member.application.member;

import com.fullcar.core.exception.CustomException;
import com.fullcar.core.exception.NotFoundException;
import com.fullcar.core.response.ErrorCode;
import com.fullcar.member.domain.member.*;
import com.fullcar.member.presentation.member.dto.request.NicknameRequestDto;
import com.fullcar.member.presentation.member.dto.request.OnboardingRequestDto;
import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto;
import com.fullcar.member.presentation.member.dto.response.NicknameResponseDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -38,4 +41,15 @@ public void registerOnboarding(Member member, OnboardingRequestDto onboardingReq
public MemberGetResponseDto getMember(Member member) {
return memberMapper.toDto(member);
}

@Transactional(readOnly = true)
public NicknameResponseDto checkNicknameDuplication(NicknameRequestDto nicknameRequestDto) {
if (memberRepository.existsByNickname(nicknameRequestDto.getNickname()))
throw new CustomException(ErrorCode.DUPLICATED_NICKNAME);
else {
return NicknameResponseDto.builder()
.nickname(nicknameRequestDto.getNickname())
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public interface MemberRepository extends JpaRepository<Member, MemberId> {

Optional<Member> findByRefreshToken(String refreshToken);

boolean existsByNickname(String nickname);

default Member findByIdAndIsDeletedOrThrow(MemberId id, boolean isDeleted) {
return findByIdAndIsDeleted(id, isDeleted)
.orElseThrow(() -> new CustomException(ErrorCode.NOT_EXIST_USER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import com.fullcar.member.application.member.MemberService;
import com.fullcar.member.domain.member.Member;
import com.fullcar.member.domain.member.service.MailService;
import com.fullcar.member.presentation.member.dto.request.NicknameRequestDto;
import com.fullcar.member.presentation.member.dto.request.OnboardingRequestDto;
import com.fullcar.member.presentation.member.dto.request.EmailRequestDto;
import com.fullcar.member.presentation.member.dto.response.MemberGetResponseDto;
import com.fullcar.member.presentation.member.dto.response.NicknameResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand Down Expand Up @@ -58,4 +60,15 @@ public ApiResponse<Object> sendAuthenticationMail(@RequestBody EmailRequestDto e
mailService.sendMail(emailRequestDto);
return ApiResponse.success(SuccessCode.EMAIL_SENT_SUCCESS);
}

@Operation(summary = "λ‹‰λ„€μž„ 쀑볡 검사 API")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "μ‚¬μš© κ°€λŠ₯ν•œ λ‹‰λ„€μž„"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "500", description = "μ„œλ²„ λ‚΄λΆ€ 였λ₯˜", content = @Content)
})
@PostMapping("/onboarding/nickname")
public ApiResponse<NicknameResponseDto> checkNicknameDuplication(@RequestBody NicknameRequestDto nicknameRequestDto) {
NicknameResponseDto responseDto = memberService.checkNicknameDuplication(nicknameRequestDto);
return ApiResponse.success(SuccessCode.AVAILABLE_NICKNAME, responseDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.fullcar.member.presentation.member.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class NicknameRequestDto {
@Schema(description = "λ‹‰λ„€μž„", example = "였예")
private String nickname;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.fullcar.member.presentation.member.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Schema(description = "λ‹‰λ„€μž„ 응닡 λͺ¨λΈ")
public class NicknameResponseDto {
@Schema(description = "λ‹‰λ„€μž„", example = "였예")
private String nickname;
}
Loading