diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin index f2acdf8..998bbb1 100644 Binary files a/build/tmp/compileJava/previous-compilation-data.bin and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignUpRequest.java b/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignUpRequest.java index 4215204..1d8c2ab 100644 --- a/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignUpRequest.java +++ b/src/main/java/gwangjang/server/domain/auth/application/dto/request/LocalSignUpRequest.java @@ -1,4 +1,19 @@ package gwangjang.server.domain.auth.application.dto.request; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor public class LocalSignUpRequest { + private String id; + private String pw; + private String nickname; + private String gender; + private String email; + private String birthDate; } diff --git a/src/main/java/gwangjang/server/domain/auth/application/mapper/MemberMapper.java b/src/main/java/gwangjang/server/domain/auth/application/mapper/MemberMapper.java index 6cce3a0..ffd6a61 100644 --- a/src/main/java/gwangjang/server/domain/auth/application/mapper/MemberMapper.java +++ b/src/main/java/gwangjang/server/domain/auth/application/mapper/MemberMapper.java @@ -1,5 +1,6 @@ package gwangjang.server.domain.auth.application.mapper; +import gwangjang.server.domain.auth.application.dto.request.LocalSignUpRequest; import gwangjang.server.domain.auth.application.dto.response.GoogleUserResponse; import gwangjang.server.domain.auth.application.dto.response.KakaoUserResponse; import gwangjang.server.domain.member.domain.entity.Member; @@ -8,6 +9,8 @@ import gwangjang.server.domain.member.domain.entity.constant.SocialProvider; import org.springframework.stereotype.Component; +import java.util.UUID; + @Component public class MemberMapper { @@ -46,4 +49,14 @@ public Member createGoogleMember(GoogleUserResponse googleUserResponse){ return newMember; } + + public Member createLocalMember(LocalSignUpRequest localSignUpRequest) { + return Member.builder() + .socialId(SocialProvider.LOCAL + "@" + UUID.randomUUID()) + .provider(SocialProvider.LOCAL) + .email(localSignUpRequest.getEmail()) + .role(Role.USER) + .registrationStatus(RegistrationStatus.COMPLETED) + .build(); + } } diff --git a/src/main/java/gwangjang/server/domain/auth/application/service/SignUpUserCase.java b/src/main/java/gwangjang/server/domain/auth/application/service/SignUpUserCase.java index 41325b9..fd4d4bc 100644 --- a/src/main/java/gwangjang/server/domain/auth/application/service/SignUpUserCase.java +++ b/src/main/java/gwangjang/server/domain/auth/application/service/SignUpUserCase.java @@ -1,8 +1,13 @@ package gwangjang.server.domain.auth.application.service; +import gwangjang.server.domain.auth.application.dto.request.LocalSignInRequest; +import gwangjang.server.domain.auth.application.dto.request.LocalSignUpRequest; import gwangjang.server.domain.auth.application.dto.request.SignUpRequest; import gwangjang.server.domain.auth.application.dto.response.SignInResponse; +import gwangjang.server.domain.auth.application.mapper.MemberMapper; +import gwangjang.server.domain.auth.exception.EmailDuplicationException; import gwangjang.server.domain.auth.exception.NicknameDuplicationException; +import gwangjang.server.domain.member.domain.service.MemberSaveService; import gwangjang.server.global.security.jwt.service.TokenUtil; import gwangjang.server.domain.member.domain.entity.Member; import gwangjang.server.domain.member.domain.entity.constant.RegistrationStatus; @@ -22,7 +27,9 @@ public class SignUpUserCase { private final TokenUtil tokenUtil; private final MemberGetService memberGetService; + private final MemberSaveService memberSaveService; private final MemberCheckService memberCheckService; + private final MemberMapper memberMapper; // 추가 정보 기입 public SignInResponse signUp(String token, SignUpRequest signUpRequest) { @@ -41,6 +48,28 @@ public SignInResponse signUp(String token, SignUpRequest signUpRequest) { member.getRegistrationStatus().equals(RegistrationStatus.COMPLETED),member.getRole().getKey()); // //5. refresh token 저장 tokenUtil.storeRefreshToken(member.getSocialId(), tokenResponse); +// + return SignInResponse.from(tokenResponse, member.getRegistrationStatus()); + } + // 추가 정보 기입 + public SignInResponse localSignUp(LocalSignUpRequest localSignUpRequest) { + + + //2. signUp 처리 + String nickname=localSignUpRequest.getNickname(); + if(memberCheckService.checkNickname(nickname)) throw new NicknameDuplicationException(); //닉네임 중복검사 (이중체크) + + String email = localSignUpRequest.getEmail(); + if(memberCheckService.checkEmail(email)) throw new EmailDuplicationException(); + + Member member = memberSaveService.saveMember(memberMapper.createLocalMember(localSignUpRequest)); + //3. security 처리 + AuthenticationUtil.makeAuthentication(member); + //4. token 만들기 + TokenInfoResponse tokenResponse = tokenUtil.createToken(member.getSocialId(), + member.getRegistrationStatus().equals(RegistrationStatus.COMPLETED),member.getRole().getKey()); +// //5. refresh token 저장 + tokenUtil.storeRefreshToken(member.getSocialId(), tokenResponse); // return SignInResponse.from(tokenResponse, member.getRegistrationStatus()); } diff --git a/src/main/java/gwangjang/server/domain/auth/exception/EmailDuplicationException.java b/src/main/java/gwangjang/server/domain/auth/exception/EmailDuplicationException.java new file mode 100644 index 0000000..f3777a1 --- /dev/null +++ b/src/main/java/gwangjang/server/domain/auth/exception/EmailDuplicationException.java @@ -0,0 +1,11 @@ +package gwangjang.server.domain.auth.exception; + +import gwangjang.server.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class EmailDuplicationException extends AuthException { + public EmailDuplicationException(){ + super(ErrorCode.NICKNAME_DUPLICATION_ERROR, + HttpStatus.BAD_REQUEST); + } +} diff --git a/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java b/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java index 609028d..0262c61 100644 --- a/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java +++ b/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java @@ -1,9 +1,6 @@ package gwangjang.server.domain.auth.presentation; -import gwangjang.server.domain.auth.application.dto.request.LocalSignInRequest; -import gwangjang.server.domain.auth.application.dto.request.SignInRequest; -import gwangjang.server.domain.auth.application.dto.request.SignUpRequest; -import gwangjang.server.domain.auth.application.dto.request.TestRequest; +import gwangjang.server.domain.auth.application.dto.request.*; import gwangjang.server.domain.auth.application.dto.response.CheckNicknameResponse; import gwangjang.server.domain.auth.application.dto.response.ReissueTokenResponse; import gwangjang.server.domain.auth.application.dto.response.SignInResponse; @@ -19,6 +16,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.parameters.P; import org.springframework.web.bind.annotation.*; @@ -49,18 +47,23 @@ public ResponseEntity> signIn( @PostMapping("/signIn/{provider}") public ResponseEntity> socialSignIn(@PathVariable String provider, @Valid @RequestBody SignInRequest signInRequest) { - log.info("kakao login Hi"); return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.signIn(signInRequest.getToken(), provider))); } - @PutMapping("/signUp") - public ResponseEntity> socialSignUp(@RequestHeader(value = "Authorization") String token, - @Valid @RequestBody SignUpRequest signUpRequest) { + @PutMapping("/signUp/{provider}") + public ResponseEntity> socialSignUp(@PathVariable String provider, + @RequestHeader(value = "Authorization") String token, + @Valid @RequestBody SignUpRequest signUpRequest) { token = (token != null && token.startsWith("Bearer ")) ? token.substring(7) : token; return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.signUp(token, signUpRequest))); } + @PostMapping("/signUp") + public ResponseEntity> signUp(@Valid @RequestBody LocalSignUpRequest signUpRequest) { + return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.localSignUp(signUpRequest))); + } + @GetMapping("/reissue") public ResponseEntity> reissue(@RequestHeader(value = "RefreshToken") String token) { ReissueTokenResponse reissueToken = reissueTokenService.reissueToken(token); diff --git a/src/main/java/gwangjang/server/domain/member/domain/entity/Member.java b/src/main/java/gwangjang/server/domain/member/domain/entity/Member.java index 9fcfca7..f241e16 100644 --- a/src/main/java/gwangjang/server/domain/member/domain/entity/Member.java +++ b/src/main/java/gwangjang/server/domain/member/domain/entity/Member.java @@ -1,6 +1,7 @@ package gwangjang.server.domain.member.domain.entity; import gwangjang.server.domain.auth.application.dto.request.SignUpRequest; +import gwangjang.server.domain.member.domain.entity.constant.Gender; import gwangjang.server.domain.member.domain.entity.constant.RegistrationStatus; import gwangjang.server.domain.member.domain.entity.constant.Role; import gwangjang.server.domain.member.domain.entity.constant.SocialProvider; @@ -45,11 +46,14 @@ public class Member { @Enumerated(EnumType.STRING) private Role role; - private String nickname; - private String loginId; private String loginPw; + private String nickname; + + private String birth; + private String gender; + public void tempSignUp() { this.registrationStatus = RegistrationStatus.COMPLETED; } diff --git a/src/main/java/gwangjang/server/domain/member/domain/repository/MemberCustomRepository.java b/src/main/java/gwangjang/server/domain/member/domain/repository/MemberCustomRepository.java index 4b7cf0a..ef4a047 100644 --- a/src/main/java/gwangjang/server/domain/member/domain/repository/MemberCustomRepository.java +++ b/src/main/java/gwangjang/server/domain/member/domain/repository/MemberCustomRepository.java @@ -3,4 +3,5 @@ public interface MemberCustomRepository { boolean checkNickname(String nickname); + boolean checkEmail(String email); } diff --git a/src/main/java/gwangjang/server/domain/member/domain/repository/MemberCustomRepositoryImpl.java b/src/main/java/gwangjang/server/domain/member/domain/repository/MemberCustomRepositoryImpl.java index 636da55..def8386 100644 --- a/src/main/java/gwangjang/server/domain/member/domain/repository/MemberCustomRepositoryImpl.java +++ b/src/main/java/gwangjang/server/domain/member/domain/repository/MemberCustomRepositoryImpl.java @@ -23,4 +23,13 @@ public boolean checkNickname(String nickname) { .fetchFirst() != null; } + @Override + public boolean checkEmail(String email) { + return queryFactory + .selectOne() + .from(member) + .where(member.email.eq(email)) + .fetchFirst() != null; + } + } diff --git a/src/main/java/gwangjang/server/domain/member/domain/service/MemberCheckService.java b/src/main/java/gwangjang/server/domain/member/domain/service/MemberCheckService.java index 616ed2c..58db3b9 100644 --- a/src/main/java/gwangjang/server/domain/member/domain/service/MemberCheckService.java +++ b/src/main/java/gwangjang/server/domain/member/domain/service/MemberCheckService.java @@ -14,5 +14,8 @@ public class MemberCheckService { public boolean checkNickname(String nickname) { return memberRepository.checkNickname(nickname); } + public boolean checkEmail(String email) { + return memberRepository.checkEmail(email); + } } diff --git a/src/main/java/gwangjang/server/global/response/ErrorCode.java b/src/main/java/gwangjang/server/global/response/ErrorCode.java index c85faea..db89ec2 100644 --- a/src/main/java/gwangjang/server/global/response/ErrorCode.java +++ b/src/main/java/gwangjang/server/global/response/ErrorCode.java @@ -23,6 +23,7 @@ public enum ErrorCode { TOKEN_INVALID_ERROR("AU0002", "입력 토큰이 유효하지 않습니다."), APPID_INVALID_ERROR("AU0003", "appId가 유효하지 않습니다"), NICKNAME_DUPLICATION_ERROR("AU0004", "닉네임이 중복됩니다."), + EMAIL_DUPLICATION_ERROR("AU0005", "닉네임이 중복됩니다."), NOT_FOUND_BY_LOGIN_ID_ERROR("L001","해당 id인 유저가 존재하지 않습니다"), INCORRECT_PASSWORD("L002","비밀번호가 틀렸습니다");