Skip to content

Commit

Permalink
#339 중복 이메일, 중복 닉네임 response 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
betgws committed Jan 10, 2025
1 parent 00f486b commit d25dc4f
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand All @@ -30,7 +31,7 @@ public class MemberController {

@PostMapping("/join")
@Operation(summary = "회원가입", description = "username과 password를 입력받아 회원가입을 진행합니다.")
public ApiResponse<?> joinProcess(@RequestBody JoinRequest joinRequest) {
public ApiResponse<?> joinProcess(@Valid @RequestBody JoinRequest joinRequest) {

joinService.join(joinRequest);
return ApiResponse.onSuccess("회원가입 성공");
Expand Down Expand Up @@ -60,7 +61,7 @@ public ApiResponse<MemberInfoResponse> getMemberInfo(@AuthenticationPrincipal Pr

@PostMapping("/member/{nickname}")
@Operation(summary = "마이페이지내에 닉네임 중복 검사 ", description = "중복된 닉네임이면 False, 사용 가능한 닉네임이면 True를 반환합니다.")
public ApiResponse<NameCheckResponse> checkNickname(@AuthenticationPrincipal PrincipalDetail principalDetail, @PathVariable String nickname){
public ApiResponse<Boolean> checkNickname(@AuthenticationPrincipal PrincipalDetail principalDetail, @PathVariable String nickname){
return ApiResponse.onSuccess(memberService.isNicknameAvailable(nickname));
}

Expand All @@ -74,9 +75,8 @@ public ApiResponse<?> updateMemberInfo(@AuthenticationPrincipal PrincipalDetail

@PostMapping("/join/check")
@Operation(summary = "이메일 중복 검사", description = "이메일(username) 중복 여부를 반환합니다.")
public ApiResponse<UsernameCheckResponse> checkUsername(@RequestBody UsernameCheckRequest usernameCheckRequest) {
UsernameCheckResponse usernameCheckResponse = joinService.isDuplicatedUsername(usernameCheckRequest);
return ApiResponse.onSuccess(usernameCheckResponse);
public ApiResponse<Boolean> checkUsername(@RequestBody UsernameCheckRequest usernameCheckRequest) {
return ApiResponse.onSuccess(joinService.isDuplicatedUsername(usernameCheckRequest));
}

@PostMapping(value = "/member/profileImage", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
package com.drinkeg.drinkeg.domain.member.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDate;
import java.util.List;

@Getter
@Builder
public class JoinRequest {


@NotBlank(message = "Username은 필수입니다.")
private String username;

@NotBlank(message = "Password는 필수입니다.")
@Pattern(
regexp = "^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]+$",
message = "Password는 최소 하나의 영문자와 숫자를 포함해야 합니다."
)
private String password;

@NotBlank(message = "rePassword는 필수입니다.")
private String rePassword;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MemberInfoResponse {
private String authType;
private boolean isAdult;

public static MemberInfoResponse create(Member member){
public static MemberInfoResponse of(Member member){

return MemberInfoResponse.builder()
.imageUrl(member.getImageUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MemberResponseDTO {

private String imageUrl;

public static MemberResponseDTO create(Member member){
public static MemberResponseDTO of(Member member){

return MemberResponseDTO.builder()
.id(member.getId())
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public LoginResponseDTO appleLogin(AppleLoginRequestDTO appleLoginRequestDTO, Ht

}

return LoginResponseDTO.create(member.getId(), member.getUsername(), member.getRole(),member.getIsFirst() );
return LoginResponseDTO.of(member.getId(), member.getUsername(), member.getRole(),member.getIsFirst() );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LoginResponseDTO {
private Boolean isFirst;
// private String refreshToken

public static LoginResponseDTO create(Long id, String username, Role role,Boolean isFirst){
public static LoginResponseDTO of(Long id, String username, Role role,Boolean isFirst){
return LoginResponseDTO.builder()
.id(id)
.username(username)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public LoginResponseDTO kakaoLogin(KakaoLoginRequestDTO kakaoLoginRequestDTO, Ht

memberRepository.save(member);

return LoginResponseDTO.create(member.getId(), member.getUsername(), member.getRole(),member.getIsFirst());
return LoginResponseDTO.of(member.getId(), member.getUsername(), member.getRole(),member.getIsFirst());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@

@Service
@RequiredArgsConstructor
@Transactional
public class JoinService {

private final MemberRepository memberRepository;
private final BCryptPasswordEncoder bCryptPasswordEncoder;
private final StorageService storageService;


@Transactional

public void join(JoinRequest joinRequest) {

String username = joinRequest.getUsername();
Expand All @@ -35,14 +36,11 @@ public void join(JoinRequest joinRequest) {
if (!password.equals(rePassword)){
throw new GeneralException(ErrorStatus.PASSWORD_NOT_MATCH);
}
if(!isValidPassword(password)){
throw new GeneralException(ErrorStatus.PASSWORD_NOT_INVALID);
}


Member member = Member.createMember( username,(bCryptPasswordEncoder.encode(password) ),true);

memberRepository.save(member);
System.out.println("Saved Member: " );

}

Expand All @@ -65,24 +63,13 @@ public MemberResponseDTO addMemberDetail(MemberRequestDTO memberRequestDTO, Stri
memberRepository.save(member);


return MemberResponseDTO.create(member);
return MemberResponseDTO.of(member);
}

public boolean isValidPassword(String password) {

// 영문자, 숫자, 특수문자 각각에 대한 패턴
String letterPattern = ".*[A-Za-z].*";
String digitPattern = ".*\\d.*";

boolean hasLetter = password.matches(letterPattern);
boolean hasDigit = password.matches(digitPattern);

// 세 가지 조건이 모두 충족되는지 확인
return hasLetter && hasDigit;
}

public UsernameCheckResponse isDuplicatedUsername(UsernameCheckRequest usernameCheckRequest) {
@Transactional(readOnly = true)
public boolean isDuplicatedUsername(UsernameCheckRequest usernameCheckRequest) {

return new UsernameCheckResponse(memberRepository.existsByUsername(usernameCheckRequest.username()));
return memberRepository.existsByUsername(usernameCheckRequest.username());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface MemberService {

public MemberInfoResponse showMemberInfo(String username);

public NameCheckResponse isNicknameAvailable(String nickname);
public boolean isNicknameAvailable(String nickname);

public void updateMemberInfo(MemberUpdateRequest memberUpdateRequest, String username);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public void deleteMemberByUsername(String username){
public MemberInfoResponse showMemberInfo(String username){
Member member = memberRepository.findByUsername(username)
.orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND));
return MemberInfoResponse.create(member);
return MemberInfoResponse.of(member);
}

@Override
public NameCheckResponse isNicknameAvailable(String nickname){
return NameCheckResponse.create(!memberRepository.existsByName(nickname));
public boolean isNicknameAvailable(String nickname){
return !memberRepository.existsByName(nickname);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
jwtExceptionHandler(response, ErrorStatus.PASSWORD_NOT_FUND);
return null;
}
String username = "drinkeg "+ requestBody.get("username");
String username = requestBody.get("username");
String password = requestBody.get("password");

// 스프링 시큐리티에서 username과 password를 검증하기 위해서는 token에 담아야 함
Expand Down Expand Up @@ -101,7 +101,7 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR
Boolean isFirst = principalDetail.getIsFirst();


LoginResponseDTO loginResponseDTO = LoginResponseDTO.create(id,username,Role.fromValue(role),isFirst);
LoginResponseDTO loginResponseDTO = LoginResponseDTO.of(id,username,Role.fromValue(role),isFirst);


// ApiResponse 생성
Expand Down

0 comments on commit d25dc4f

Please sign in to comment.