Skip to content

Commit

Permalink
feat: create verify identity api
Browse files Browse the repository at this point in the history
  • Loading branch information
Kang1221 committed Aug 11, 2024
1 parent 05bc86d commit a7c722b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/java/co/orange/ddanzi/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
25 changes: 25 additions & 0 deletions src/main/java/co/orange/ddanzi/dto/auth/VerifyRequestDto.java
Original file line number Diff line number Diff line change
@@ -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();

}
}
11 changes: 11 additions & 0 deletions src/main/java/co/orange/ddanzi/dto/auth/VerifyResponseDto.java
Original file line number Diff line number Diff line change
@@ -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;
}
28 changes: 27 additions & 1 deletion src/main/java/co/orange/ddanzi/service/AuthService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a7c722b

Please sign in to comment.