Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/#10] 번호 인증 검사 기능 구현 #15

Merged
merged 32 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d8b0159
[FEAT] 번호 인증 검사 API Response Body 데이터 정의
yummygyudon Nov 18, 2024
a4c06ce
[FEAT] 번호 인증 Usecase 및 Command 정의
yummygyudon Nov 18, 2024
270684e
[FEAT] 번호 인증 데이터 Out Port 정의 및 JPA 메서드 선언
yummygyudon Nov 18, 2024
e57a769
[FEAT] 번호 인증 검사 In Port Usecase 구현
yummygyudon Nov 18, 2024
72cf821
[FEAT] 번호 인증 요청에 대한 API 메서드 구현
yummygyudon Nov 18, 2024
0ab5f54
[TEST] PhoneVerification 객체 간 동일여부 판단 메서드 테스트
yummygyudon Nov 18, 2024
9d0c2f2
[FIX] PhoneVerification Inner Record `@EqualsAndHashCode` 추가
yummygyudon Nov 18, 2024
557048a
[REFACTOR] Transaction Helper 객체 구현
yummygyudon Nov 19, 2024
87b7deb
[REFACTOR] PhoneVerification Out Port 메서드명 개선
yummygyudon Nov 19, 2024
b134dda
[CHORE] 소스코드 변경 사항 및 패키징 추가 반영
yummygyudon Nov 19, 2024
83c80bf
[CHORE] 와일드 카드 제거 및 Usecase 반환 데이터 변경 반영
yummygyudon Nov 19, 2024
f52d94e
[FIX] 요구사항에 따른 PhoneVerification Null 가능 반영
yummygyudon Nov 19, 2024
78bf06e
[TEST] PhoneVerification Null 가능 반영 정상 작동 여부 확인
yummygyudon Nov 19, 2024
a23cbf4
[REFACTOR] 트랜젝션 처리/예외 처리 계층 변경
yummygyudon Nov 20, 2024
eab709b
[FIX] Response Getter 추가
yummygyudon Dec 4, 2024
35f6a06
[FIX] gitignore `*.properties` 추가로 인해 `gradle-wrapper.properties` 삭제되…
yummygyudon Dec 4, 2024
d0389c3
[REFACTOR] Request DTO 내 Json Property 속성 명시
yummygyudon Dec 4, 2024
308ab9a
[FIX] API 메서드 파라미터 중 Body 데이터에 대한 `@RequestBody` 어노테이션 적용
yummygyudon Dec 4, 2024
1bc602c
[REFACTOR] API Response DTO 내 Json Property 속성 명시
yummygyudon Dec 4, 2024
4dd4da3
[TEST] Verify API Test
yummygyudon Dec 4, 2024
a7080bd
[TEST] Verify Usecase 테스트
yummygyudon Dec 4, 2024
10d0b01
[REFACTOR] Usecase 결과 - API Response 분리
yummygyudon Dec 4, 2024
6b70bee
[REFACTOR] Usecase 결과에 대한 API Response DTO 변환 메서드 정의 및 반영
yummygyudon Dec 4, 2024
5b6af89
[TEST] Usecase VO 선언 및 Response DTO 분리에 대한 API 테스트 및 Usecase 테스트 변경 반영
yummygyudon Dec 4, 2024
af48afe
Merge branch 'dev' into feat/#10
yummygyudon Dec 4, 2024
064e5a9
[FEAT] User 도메인 Out Port 추가 - UserRegisterInfo Repository 및 UserRegi…
yummygyudon Dec 5, 2024
74c56cd
[FEAT] UserRegisterInfo 데이터 계층(`external`) 객체 구현
yummygyudon Dec 5, 2024
3414ee5
[FEAT] User 데이터 계층(`external`) 전화번호 기반 조회 기능 구현
yummygyudon Dec 5, 2024
d6e3e29
[MODIFY] 사용자 정보가 존재할 경우에만 인증 이력이 생성되도록 기능 수정
yummygyudon Dec 5, 2024
c642ca2
[MODIFY] 인증 완료 시, 대상자 이름 및 번호 데이터를 함께 반환할 수 있도록 DTO 수정
yummygyudon Dec 5, 2024
6a5a651
[MODIFY] 인증 처리 Usecase Return 방식 VO 반환 방식으로의 변경에 따른 반영
yummygyudon Dec 5, 2024
83488cf
[TEST] 인증 생성 UseCase 구현체 Test
yummygyudon Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package sopt.makers.authentication.application.auth.api;

import sopt.makers.authentication.application.auth.dto.request.AuthRequest;
import sopt.makers.authentication.application.auth.dto.response.AuthResponse;
import sopt.makers.authentication.support.code.domain.success.AuthSuccess;
import sopt.makers.authentication.support.common.api.BaseResponse;
import sopt.makers.authentication.usecase.auth.port.in.CreatePhoneVerificationUsecase;
import sopt.makers.authentication.usecase.auth.port.in.VerifyPhoneVerificationUsecase;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -18,6 +20,7 @@
public class AuthApiController implements AuthApi {

private final CreatePhoneVerificationUsecase createVerificationUsecase;
private final VerifyPhoneVerificationUsecase verifyVerificationUsecase;

@Override
@PostMapping("/phone")
Expand All @@ -32,6 +35,10 @@ public ResponseEntity<BaseResponse<?>> createPhoneVerification(
@PostMapping("/verify/phone")
public ResponseEntity<BaseResponse<?>> verifyPhoneVerification(
AuthRequest.VerifyPhoneVerification phoneVerification) {
return null;
boolean result = verifyVerificationUsecase.verify(phoneVerification.toCommand());
return ResponseEntity.status(AuthSuccess.CREATE_PHONE_VERIFICATION.getStatus().value())
.body(
BaseResponse.ofSuccess(
AuthSuccess.CREATE_PHONE_VERIFICATION, new AuthResponse.VerifyResult(result)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sopt.makers.authentication.domain.auth.PhoneVerificationType;
import sopt.makers.authentication.usecase.auth.port.in.CreatePhoneVerificationUsecase.CreateVerificationCommand;
import sopt.makers.authentication.usecase.auth.port.in.VerifyPhoneVerificationUsecase.VerifyVerificationCommand;

import lombok.RequiredArgsConstructor;

Expand All @@ -17,5 +18,14 @@ public CreateVerificationCommand toCommand() {
}
}

public record VerifyPhoneVerification(String name, String number, String code) {}
public record VerifyPhoneVerification(
String name, String number, String code, String verificationTypeName) {
public VerifyVerificationCommand toCommand() {
return new VerifyVerificationCommand(
this.name,
this.number,
this.code,
PhoneVerificationType.valueOf(this.verificationTypeName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import static lombok.AccessLevel.PRIVATE;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor(access = PRIVATE)
public final class AuthResponse {}
public final class AuthResponse {

public record VerifyResult(@JsonProperty("isVerified") boolean isVerified) {}
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package sopt.makers.authentication.database;
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved

import sopt.makers.authentication.database.rdb.entity.auth.PhoneVerificationEntity;
import sopt.makers.authentication.database.rdb.repository.auth.PhoneVerificationRegister;
import sopt.makers.authentication.database.rdb.repository.auth.PhoneVerificationRemover;
import sopt.makers.authentication.database.rdb.repository.auth.PhoneVerificationRetriever;
import sopt.makers.authentication.domain.auth.PhoneVerification;
import sopt.makers.authentication.usecase.auth.port.out.PhoneVerificationRepository;

import org.springframework.stereotype.Repository;

import lombok.RequiredArgsConstructor;

@Repository
@RequiredArgsConstructor
public class PhoneVerificationRepositoryImpl implements PhoneVerificationRepository {

private final PhoneVerificationRegister register;
private final PhoneVerificationRetriever retriever;
private final PhoneVerificationRemover remover;
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved

@Override
public PhoneVerification create(PhoneVerification phoneVerification) {
PhoneVerificationEntity createdEntity = register.register(phoneVerification);
return createdEntity.toDomain();
}

@Override
public PhoneVerification findByPhoneVerification(PhoneVerification phoneVerification) {
PhoneVerificationEntity phoneVerificationEntity = retriever.find(phoneVerification);
return phoneVerificationEntity.toDomain();
}

@Override
public void deletedByPhoneVerification(PhoneVerification phoneVerification) {
remover.remove(phoneVerification);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sopt.makers.authentication.database.rdb.entity;
package sopt.makers.authentication.database.rdb.entity.auth;

import static lombok.AccessLevel.PRIVATE;
import static lombok.AccessLevel.PROTECTED;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package sopt.makers.authentication.database.rdb.repository.auth;

import sopt.makers.authentication.database.rdb.entity.auth.PhoneVerificationEntity;
import sopt.makers.authentication.domain.auth.PhoneVerification;
import sopt.makers.authentication.domain.auth.PhoneVerificationType;
import sopt.makers.authentication.support.code.domain.failure.AuthFailure;
import sopt.makers.authentication.support.exception.domain.AuthException;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

interface PhoneVerificationJpaRepository extends JpaRepository<PhoneVerificationEntity, Long> {

Optional<PhoneVerificationEntity> findByNameAndPhoneAndCodeAndType(
String name, String phone, String code, PhoneVerificationType type);

void deleteByNameAndPhoneAndCodeAndType(
String name, String phone, String code, PhoneVerificationType type);

default PhoneVerificationEntity findByPhoneVerification(PhoneVerification verification) {
PhoneVerificationEntity targetPhoneVerificationEntity =
findByNameAndPhoneAndCodeAndType(
verification.getName(),
verification.getPhone(),
verification.getVerificationCode().getCode(),
verification.getVerificationType())
.orElseThrow(() -> new AuthException(AuthFailure.NOT_FOUND_PHONE_VERIFICATION));
return targetPhoneVerificationEntity;
}
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved

default void deleteByVerification(PhoneVerification verification) {
deleteByNameAndPhoneAndCodeAndType(
verification.getName(),
verification.getPhone(),
verification.getVerificationCode().getCode(),
verification.getVerificationType());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sopt.makers.authentication.database.rdb.repository.auth;

import sopt.makers.authentication.database.rdb.entity.auth.PhoneVerificationEntity;
import sopt.makers.authentication.domain.auth.PhoneVerification;

import jakarta.transaction.Transactional;

import org.springframework.stereotype.Component;

import lombok.RequiredArgsConstructor;

@Component
@Transactional
@RequiredArgsConstructor
public class PhoneVerificationRegister {

private final PhoneVerificationJpaRepository jpaRepository;

public PhoneVerificationEntity register(PhoneVerification phoneVerification) {
PhoneVerificationEntity entity = PhoneVerificationEntity.fromDomain(phoneVerification);
return jpaRepository.save(entity);
}

public PhoneVerificationEntity register(final long id, PhoneVerification phoneVerification) {
PhoneVerificationEntity entity = PhoneVerificationEntity.fromDomain(id, phoneVerification);
return jpaRepository.save(entity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sopt.makers.authentication.database.rdb.repository.auth;

import sopt.makers.authentication.domain.auth.PhoneVerification;

import jakarta.transaction.Transactional;

import org.springframework.stereotype.Component;

import lombok.RequiredArgsConstructor;

@Component
@Transactional
@RequiredArgsConstructor
public class PhoneVerificationRemover {

private final PhoneVerificationJpaRepository jpaRepository;

public void remove(PhoneVerification phoneVerification) {
jpaRepository.deleteByVerification(phoneVerification);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sopt.makers.authentication.database.rdb.repository.auth;

import sopt.makers.authentication.database.rdb.entity.auth.PhoneVerificationEntity;
import sopt.makers.authentication.domain.auth.PhoneVerification;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;

@Component
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class PhoneVerificationRetriever {

private final PhoneVerificationJpaRepository jpaRepository;

public PhoneVerificationEntity find(PhoneVerification phoneVerification) {
return jpaRepository.findByPhoneVerification(phoneVerification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import java.util.Random;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@Builder(access = PRIVATE)
@RequiredArgsConstructor(access = PRIVATE)
@EqualsAndHashCode
public class PhoneVerification {

private final String name;
Expand Down Expand Up @@ -40,6 +42,7 @@ public static PhoneVerification create(String name, String phone, PhoneVerificat
}

@Getter
@EqualsAndHashCode
public static class VerificationCode {
private static final int CODE_SIZE = 6;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
@Getter
@RequiredArgsConstructor(access = PRIVATE)
public enum AuthFailure implements FailureCode {
// 400
INVALID_SOCIAL_PLATFORM(HttpStatus.BAD_REQUEST, "지원하지 않는 소셜 플랫폼입니다"),

// 404
NOT_FOUND_PHONE_VERIFICATION(HttpStatus.NOT_FOUND, "존재하지 않는 번호 인증 이력입니다."),
;
private final HttpStatus status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@Getter
@RequiredArgsConstructor(access = PRIVATE)
public enum AuthSuccess implements SuccessCode {
VERIFY_PHONE_VERIFICATION(HttpStatus.OK, "번호 인증에 성공했습니다."),

CREATE_PHONE_VERIFICATION(HttpStatus.CREATED, "번호 인증 생성에 성공했습니다."),
;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sopt.makers.authentication.usecase.auth.port.in;

import sopt.makers.authentication.domain.auth.PhoneVerificationType;

public interface VerifyPhoneVerificationUsecase {

boolean verify(VerifyVerificationCommand command);

record VerifyVerificationCommand(
String name, String phone, String code, PhoneVerificationType verificationType) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@

public interface PhoneVerificationRepository {

PhoneVerification save(PhoneVerification phoneVerification);
PhoneVerification create(PhoneVerification phoneVerification);

PhoneVerification findByPhoneVerification(PhoneVerification phoneVerification);

void deletedByPhoneVerification(PhoneVerification phoneVerification);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public PhoneVerification create(CreateVerificationCommand command) {
convertCodeToMessage(phoneVerification.getVerificationCode().getCode()));

messageSendPort.sendMessage(verificationMessage);
return verificationRepository.save(phoneVerification);
return verificationRepository.create(phoneVerification);
}

private String convertCodeToMessage(String code) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sopt.makers.authentication.usecase.auth.service;

import sopt.makers.authentication.domain.auth.PhoneVerification;
import sopt.makers.authentication.usecase.auth.port.in.VerifyPhoneVerificationUsecase;
import sopt.makers.authentication.usecase.auth.port.out.PhoneVerificationRepository;

import org.springframework.stereotype.Service;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class VerifyVerificationService implements VerifyPhoneVerificationUsecase {
private final PhoneVerificationRepository phoneVerificationRepository;

@Override
public boolean verify(VerifyVerificationCommand command) {
PhoneVerification targetVerification =
PhoneVerification.of(
command.name(), command.phone(), command.verificationType(), command.code());
PhoneVerification findVerification =
phoneVerificationRepository.findByPhoneVerification(targetVerification);
boolean isVerified = targetVerification.equals(findVerification);

if (isVerified) {
phoneVerificationRepository.deletedByPhoneVerification(findVerification);
yummygyudon marked this conversation as resolved.
Show resolved Hide resolved
}
return isVerified;
}
}
Loading