Skip to content

Commit 0956fc4

Browse files
authored
Merge pull request #74 from Hongik-Chainee/develop
feat/savename
2 parents 5a0839c + e996c12 commit 0956fc4

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/main/java/com/chaineeproject/chainee/kyc/KycController.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class KycController {
3131

3232
private final KycPhoneService kycPhoneService;
3333
private final UserRepository userRepo;
34-
3534
private final AuthService authService;
3635
private final JwtProperties jwtProps;
3736

@@ -87,7 +86,7 @@ public KycPhoneRequestResDto request(@AuthenticationPrincipal Jwt jwt,
8786

8887
@Operation(
8988
summary = "휴대폰 인증검증",
90-
description = "전송된 6자리 코드를 검증하고, 성공 시 access/refresh를 재발급합니다.",
89+
description = "전송된 6자리 코드를 검증하고, 성공 시 access/refresh를 재발급하며, 이름을 저장합니다.",
9190
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
9291
required = true,
9392
content = @Content(
@@ -99,7 +98,8 @@ public KycPhoneRequestResDto request(@AuthenticationPrincipal Jwt jwt,
9998
value = """
10099
{
101100
"requestId": "8e5d1a0e-2c39-4a39-b73f-18d8d5b2c9f1",
102-
"code": "123456"
101+
"code": "123456",
102+
"name": "김여원"
103103
}
104104
"""
105105
)
@@ -146,7 +146,16 @@ public ResponseEntity<KycPhoneVerifyResDto> verify(@AuthenticationPrincipal Jwt
146146
@RequestBody @Valid KycPhoneVerifyDto body,
147147
HttpServletResponse res) {
148148
User user = me(jwt);
149-
boolean ok = kycPhoneService.verifyCode(user, body.requestId(), body.code());
149+
150+
boolean ok;
151+
try {
152+
ok = kycPhoneService.verifyCode(user, body.requestId(), body.code(), body.name());
153+
} catch (IllegalStateException | IllegalArgumentException e) {
154+
return ResponseEntity.ok(
155+
new KycPhoneVerifyResDto(false, "RETRY", null, null, null)
156+
);
157+
}
158+
150159
if (!ok) {
151160
return ResponseEntity.ok(
152161
new KycPhoneVerifyResDto(false, "RETRY", null, null, null)

src/main/java/com/chaineeproject/chainee/kyc/KycPhoneService.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,17 @@ private String sha256(String s) {
5252
public String requestCode(User user, String phone, String serviceName) {
5353
boolean isDev = Arrays.asList(env.getActiveProfiles()).contains("dev");
5454

55-
// dev 프로필 & test.enabled=true & (test.phone 미지정 또는 일치) & test.code 존재 → 고정코드 사용
5655
boolean matchPhone = (testPhone == null || testPhone.isBlank())
5756
|| normalize(phone).equals(normalize(testPhone));
5857
boolean useFixed = isDev && testEnabled && matchPhone
5958
&& testCode != null && !testCode.isBlank();
6059

6160
String code = useFixed ? testCode : random6();
6261

63-
// 테스트가 아니거나, 테스트라도 실제 발송 요구 시에만 Solapi 호출
6462
if (!useFixed || testSendSms) {
6563
solapiClient.sendVerificationCode(phone, code, serviceName);
6664
}
6765

68-
// 개발 편의: dev일 때만 코드 로깅
6966
if (isDev) log.warn("[DEV] KYC code for {} -> {}", phone, code);
7067

7168
KycSession sess = KycSession.builder()
@@ -80,7 +77,7 @@ public String requestCode(User user, String phone, String serviceName) {
8077
}
8178

8279
@Transactional
83-
public boolean verifyCode(User user, String requestId, String code) {
80+
public boolean verifyCode(User user, String requestId, String code, String name) {
8481
KycSession sess = kycRepo.findById(requestId)
8582
.orElseThrow(() -> new IllegalArgumentException("잘못된 요청 ID"));
8683
if (!sess.getUser().getId().equals(user.getId()))
@@ -93,6 +90,17 @@ public boolean verifyCode(User user, String requestId, String code) {
9390

9491
// 통과 처리
9592
sess.setVerified(true);
93+
94+
// ✅ 이름 저장 정책: 기존 이름이 비어있을 때만 저장 (안전)
95+
String trimmed = name == null ? null : name.trim();
96+
if (trimmed != null && !trimmed.isEmpty()) {
97+
if (user.getName() == null || user.getName().isBlank()) {
98+
user.setName(trimmed);
99+
}
100+
// (항상 갱신 원하면 아래 주석 해제)
101+
// user.setName(trimmed);
102+
}
103+
96104
user.setKycVerified(true);
97105
user.setKycPhone(sess.getPhone());
98106
user.setKycVerifiedAt(LocalDateTime.now());

src/main/java/com/chaineeproject/chainee/kyc/dto/KycPhoneVerifyDto.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ public record KycPhoneVerifyDto(
1010

1111
@Schema(description = "수신한 6자리 인증코드", example = "123456")
1212
@NotBlank
13-
String code
13+
String code,
14+
15+
@Schema(description = "실명", example = "김여원")
16+
@NotBlank
17+
String name
1418
) {}

0 commit comments

Comments
 (0)