From a7c722bd3b1512dd36af934939cb9873a3eac641 Mon Sep 17 00:00:00 2001 From: kang Date: Sun, 11 Aug 2024 14:17:40 +0900 Subject: [PATCH] feat: create verify identity api --- .../ddanzi/controller/AuthController.java | 6 ++++ .../ddanzi/dto/auth/VerifyRequestDto.java | 25 +++++++++++++++++ .../ddanzi/dto/auth/VerifyResponseDto.java | 11 ++++++++ .../co/orange/ddanzi/service/AuthService.java | 28 ++++++++++++++++++- 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 src/main/java/co/orange/ddanzi/dto/auth/VerifyRequestDto.java create mode 100644 src/main/java/co/orange/ddanzi/dto/auth/VerifyResponseDto.java diff --git a/src/main/java/co/orange/ddanzi/controller/AuthController.java b/src/main/java/co/orange/ddanzi/controller/AuthController.java index 82493705..e382fe3e 100644 --- a/src/main/java/co/orange/ddanzi/controller/AuthController.java +++ b/src/main/java/co/orange/ddanzi/controller/AuthController.java @@ -2,6 +2,7 @@ import co.orange.ddanzi.domain.user.enums.LoginType; import co.orange.ddanzi.dto.auth.SigninRequestDto; +import co.orange.ddanzi.dto.auth.VerifyRequestDto; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.service.AuthService; import com.fasterxml.jackson.core.JsonProcessingException; @@ -28,4 +29,9 @@ ApiResponse signin(@RequestBody SigninRequestDto requestDto) throws JsonProce return authService.kakaoSignIn(requestDto.getToken()); return authService.kakaoSignIn(requestDto.getToken()); } + + @PostMapping("/verification") + ApiResponse verify(@RequestBody VerifyRequestDto requestDto) { + return authService.verify(requestDto); + } } diff --git a/src/main/java/co/orange/ddanzi/dto/auth/VerifyRequestDto.java b/src/main/java/co/orange/ddanzi/dto/auth/VerifyRequestDto.java new file mode 100644 index 00000000..bd655b53 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/dto/auth/VerifyRequestDto.java @@ -0,0 +1,25 @@ +package co.orange.ddanzi.dto.auth; + +import co.orange.ddanzi.domain.user.Authentication; +import co.orange.ddanzi.domain.user.enums.Sex; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +public class VerifyRequestDto { + private String name; + private String phone; + private LocalDate birth; + private Sex sex; + + public Authentication toEntity(String phone){ + return Authentication.builder() + .name(name) + .phone(phone) + .birth(birth) + .sex(sex) + .build(); + + } +} diff --git a/src/main/java/co/orange/ddanzi/dto/auth/VerifyResponseDto.java b/src/main/java/co/orange/ddanzi/dto/auth/VerifyResponseDto.java new file mode 100644 index 00000000..ab84eef4 --- /dev/null +++ b/src/main/java/co/orange/ddanzi/dto/auth/VerifyResponseDto.java @@ -0,0 +1,11 @@ +package co.orange.ddanzi.dto.auth; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class VerifyResponseDto { + private String nickname; + private String phone; +} diff --git a/src/main/java/co/orange/ddanzi/service/AuthService.java b/src/main/java/co/orange/ddanzi/service/AuthService.java index 82f59e4a..2d4021f8 100644 --- a/src/main/java/co/orange/ddanzi/service/AuthService.java +++ b/src/main/java/co/orange/ddanzi/service/AuthService.java @@ -1,14 +1,19 @@ package co.orange.ddanzi.service; +import co.orange.ddanzi.domain.user.Authentication; import co.orange.ddanzi.domain.user.User; import co.orange.ddanzi.domain.user.enums.LoginType; import co.orange.ddanzi.domain.user.enums.UserStatus; import co.orange.ddanzi.dto.auth.AuthResponseDto; import co.orange.ddanzi.dto.auth.SigninResponseDto; +import co.orange.ddanzi.dto.auth.VerifyRequestDto; +import co.orange.ddanzi.dto.auth.VerifyResponseDto; import co.orange.ddanzi.global.common.error.Error; import co.orange.ddanzi.global.common.response.ApiResponse; import co.orange.ddanzi.global.common.response.Success; +import co.orange.ddanzi.global.config.jwt.AuthUtils; import co.orange.ddanzi.global.config.jwt.JwtUtils; +import co.orange.ddanzi.repository.AuthenticationRepository; import co.orange.ddanzi.repository.UserRepository; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; @@ -36,8 +41,10 @@ @RequiredArgsConstructor @Service public class AuthService { - private final UserRepository userRepository; private final JwtUtils jwtUtils; + private final UserRepository userRepository; + private final AuthenticationRepository authenticationRepository; + private final AuthUtils authUtils; @Transactional public ApiResponse testSignin(String idToken){ @@ -76,6 +83,25 @@ public ApiResponse kakaoSignIn(String token) throws JsonProcessingException { return ApiResponse.onSuccess(Success.SIGNIN_KAKAO_SUCCESS, responseDto); } + @Transactional + public ApiResponse verify(VerifyRequestDto requestDto){ + User user = authUtils.getUser(); + + String phone = requestDto.getPhone().replace("-", "").replace(" ",""); + Authentication newAuthentication = requestDto.toEntity(phone); + newAuthentication = authenticationRepository.save(newAuthentication); + log.info("본인인증 완료 authentication_id -> {}", newAuthentication.getId()); + + user.setAuthentication(UserStatus.ACTIVATE,newAuthentication); + log.info("회원 정보 변경 완료 user_authentication_id -> {}", user.getAuthentication().getId()); + + VerifyResponseDto responseDto = VerifyResponseDto.builder() + .nickname(user.getNickname()) + .phone(newAuthentication.getPhone()) + .build(); + return ApiResponse.onSuccess(Success.CREATE_AUTHENTICATION_SUCCESS, responseDto); + } + public void kakaoSignUp(String email) { User user = User.builder()