From d25dc4fc2a09691528d8e3eb1c515fd30edc91c1 Mon Sep 17 00:00:00 2001 From: dayeong Date: Fri, 10 Jan 2025 14:34:40 +0900 Subject: [PATCH] =?UTF-8?q?#339=20=EC=A4=91=EB=B3=B5=20=EC=9D=B4=EB=A9=94?= =?UTF-8?q?=EC=9D=BC,=20=EC=A4=91=EB=B3=B5=20=EB=8B=89=EB=84=A4=EC=9E=84?= =?UTF-8?q?=20response=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 10 +++---- .../domain/member/dto/JoinRequest.java | 16 ++++++++--- .../domain/member/dto/MemberInfoResponse.java | 2 +- .../domain/member/dto/MemberResponseDTO.java | 2 +- .../member/dto/UsernameCheckResponse.java | 6 ----- .../apple/appleService/AppleLoginService.java | 2 +- .../login/oauth2/dto/LoginResponseDTO.java | 2 +- .../kakao/kakaoService/KakaoLoginService.java | 2 +- .../domain/member/service/JoinService.java | 27 +++++-------------- .../domain/member/service/MemberService.java | 2 +- .../member/service/MemberServiceImpl.java | 6 ++--- .../global/security/jwt/LoginFilter.java | 4 +-- 12 files changed, 36 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/com/drinkeg/drinkeg/domain/member/dto/UsernameCheckResponse.java diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/controller/MemberController.java b/src/main/java/com/drinkeg/drinkeg/domain/member/controller/MemberController.java index 6c1f2695..d45ab3e3 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/controller/MemberController.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/controller/MemberController.java @@ -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; @@ -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("회원가입 성공"); @@ -60,7 +61,7 @@ public ApiResponse getMemberInfo(@AuthenticationPrincipal Pr @PostMapping("/member/{nickname}") @Operation(summary = "마이페이지내에 닉네임 중복 검사 ", description = "중복된 닉네임이면 False, 사용 가능한 닉네임이면 True를 반환합니다.") - public ApiResponse checkNickname(@AuthenticationPrincipal PrincipalDetail principalDetail, @PathVariable String nickname){ + public ApiResponse checkNickname(@AuthenticationPrincipal PrincipalDetail principalDetail, @PathVariable String nickname){ return ApiResponse.onSuccess(memberService.isNicknameAvailable(nickname)); } @@ -74,9 +75,8 @@ public ApiResponse updateMemberInfo(@AuthenticationPrincipal PrincipalDetail @PostMapping("/join/check") @Operation(summary = "이메일 중복 검사", description = "이메일(username) 중복 여부를 반환합니다.") - public ApiResponse checkUsername(@RequestBody UsernameCheckRequest usernameCheckRequest) { - UsernameCheckResponse usernameCheckResponse = joinService.isDuplicatedUsername(usernameCheckRequest); - return ApiResponse.onSuccess(usernameCheckResponse); + public ApiResponse 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) diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/dto/JoinRequest.java b/src/main/java/com/drinkeg/drinkeg/domain/member/dto/JoinRequest.java index 89d9c37d..e74a21f4 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/dto/JoinRequest.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/dto/JoinRequest.java @@ -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; diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/dto/MemberInfoResponse.java b/src/main/java/com/drinkeg/drinkeg/domain/member/dto/MemberInfoResponse.java index 8ca75c79..d45482a9 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/dto/MemberInfoResponse.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/dto/MemberInfoResponse.java @@ -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()) diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/dto/MemberResponseDTO.java b/src/main/java/com/drinkeg/drinkeg/domain/member/dto/MemberResponseDTO.java index 1fdbf250..09bbdd3d 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/dto/MemberResponseDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/dto/MemberResponseDTO.java @@ -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()) diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/dto/UsernameCheckResponse.java b/src/main/java/com/drinkeg/drinkeg/domain/member/dto/UsernameCheckResponse.java deleted file mode 100644 index 0095a76a..00000000 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/dto/UsernameCheckResponse.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.drinkeg.drinkeg.domain.member.dto; - -public record UsernameCheckResponse( - boolean isDuplicate -) { -} diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/apple/appleService/AppleLoginService.java b/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/apple/appleService/AppleLoginService.java index 6ae166e9..13e161ac 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/apple/appleService/AppleLoginService.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/apple/appleService/AppleLoginService.java @@ -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() ); } diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/dto/LoginResponseDTO.java b/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/dto/LoginResponseDTO.java index ce4536dc..f7a327a6 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/dto/LoginResponseDTO.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/dto/LoginResponseDTO.java @@ -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) diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/kakao/kakaoService/KakaoLoginService.java b/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/kakao/kakaoService/KakaoLoginService.java index 419616a6..e68ded3b 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/kakao/kakaoService/KakaoLoginService.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/login/oauth2/kakao/kakaoService/KakaoLoginService.java @@ -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()); } diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/service/JoinService.java b/src/main/java/com/drinkeg/drinkeg/domain/member/service/JoinService.java index 09267a8a..b9a7ddc0 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/service/JoinService.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/service/JoinService.java @@ -15,6 +15,7 @@ @Service @RequiredArgsConstructor +@Transactional public class JoinService { private final MemberRepository memberRepository; @@ -22,7 +23,7 @@ public class JoinService { private final StorageService storageService; - @Transactional + public void join(JoinRequest joinRequest) { String username = joinRequest.getUsername(); @@ -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: " ); } @@ -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()); } } \ No newline at end of file diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/service/MemberService.java b/src/main/java/com/drinkeg/drinkeg/domain/member/service/MemberService.java index 4a467c40..f879b344 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/service/MemberService.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/service/MemberService.java @@ -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); diff --git a/src/main/java/com/drinkeg/drinkeg/domain/member/service/MemberServiceImpl.java b/src/main/java/com/drinkeg/drinkeg/domain/member/service/MemberServiceImpl.java index 72ee7e9b..80ca96bb 100644 --- a/src/main/java/com/drinkeg/drinkeg/domain/member/service/MemberServiceImpl.java +++ b/src/main/java/com/drinkeg/drinkeg/domain/member/service/MemberServiceImpl.java @@ -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 diff --git a/src/main/java/com/drinkeg/drinkeg/global/security/jwt/LoginFilter.java b/src/main/java/com/drinkeg/drinkeg/global/security/jwt/LoginFilter.java index eb615134..792d1ac7 100644 --- a/src/main/java/com/drinkeg/drinkeg/global/security/jwt/LoginFilter.java +++ b/src/main/java/com/drinkeg/drinkeg/global/security/jwt/LoginFilter.java @@ -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에 담아야 함 @@ -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 생성