-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from swm-nodriversomabus/BUS-101-Cellphone-Ce…
…rtification Bus 101 cellphone certification
- Loading branch information
Showing
21 changed files
with
370 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/api/common/config/AWSConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.api.common.config; | ||
|
||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.sns.AmazonSNSClient; | ||
import com.amazonaws.services.sns.AmazonSNSClientBuilder; | ||
import lombok.Getter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
|
||
@Getter | ||
@Configuration | ||
public class AWSConfig { | ||
|
||
@Value("${aws.accessKey}") | ||
private String awsAccessKey; | ||
|
||
@Value("${aws.secretKey}") | ||
private String awsSecretKey; | ||
|
||
@Value("${aws.region}") | ||
private String awsRegion; | ||
|
||
@Primary | ||
@Bean | ||
public AmazonSNSClient getAWSSNSClient(){ | ||
return (AmazonSNSClient) AmazonSNSClientBuilder.standard() | ||
.withRegion(awsRegion) | ||
.withCredentials( | ||
new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsAccessKey, awsSecretKey)) | ||
) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/api/sms/adapter/in/rest/SmsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.example.api.sms.adapter.in.rest; | ||
|
||
import com.example.api.sms.application.port.in.SendCertificationCodeUsecase; | ||
import com.example.api.sms.application.port.in.VerifyCodeUsecase; | ||
import com.example.api.sms.dto.CheckSMSDto; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/sms") | ||
@Validated | ||
public class SmsController { | ||
private final SendCertificationCodeUsecase sendCertificationCodeUsecase; | ||
private final VerifyCodeUsecase verifyCodeUsecase; | ||
|
||
/** | ||
* 핸드폰 인증에 사용 | ||
* | ||
* @param phone | ||
*/ | ||
@Operation(summary = "certification phone", description = "핸드폰 인증") | ||
@GetMapping("/code/{phone}") | ||
public void sendCertificationPhone(@PathVariable String phone){ | ||
sendCertificationCodeUsecase.send(phone); | ||
} | ||
|
||
@PostMapping("/code") | ||
public void certificatePhone(@RequestBody @Validated CheckSMSDto checkSMSDto){ | ||
verifyCodeUsecase.verifyCertificationCode(checkSMSDto); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/api/sms/adapter/out/persistence/PhoneCertification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.api.sms.adapter.out.persistence; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* 핸드폰 인증에 사용되는 클래스 | ||
*/ | ||
@Getter | ||
@AllArgsConstructor | ||
@RedisHash(value = "phone_check", timeToLive = 360) // hash collection 명시 | ||
public class PhoneCertification implements Serializable { | ||
@Id | ||
private String phone; | ||
private String code; | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/example/api/sms/adapter/out/persistence/PhoneCertificationPersistence.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.example.api.sms.adapter.out.persistence; | ||
|
||
|
||
import com.example.api.sms.application.port.out.CertificationCodePort; | ||
import com.example.api.sms.application.port.out.CheckVerifiedPhonePort; | ||
import com.example.api.sms.repository.PhoneCertificationRepository; | ||
import com.example.api.common.exception.CustomException; | ||
import com.example.api.common.type.ErrorCodeEnum; | ||
import com.example.api.sms.repository.VerifyCertificationRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class PhoneCertificationPersistence implements CertificationCodePort, CheckVerifiedPhonePort { | ||
private final PhoneCertificationRepository repository; | ||
private final VerifyCertificationRepository verifyCertificationRepository; | ||
@Override | ||
public void saveCode(String phone, String code) { | ||
repository.save(new PhoneCertification(phone, code)); | ||
} | ||
|
||
@Override | ||
public PhoneCertification findCode(String phone) { | ||
return repository.findById(phone).orElseThrow(()-> new CustomException(ErrorCodeEnum.CODE_IS_EXPIRED)); | ||
} | ||
|
||
/** | ||
* 인증 번호 만료 여부 확인 | ||
* @param phone | ||
*/ | ||
@Override | ||
public void findCheckedPhone(String phone) { | ||
verifyCertificationRepository.findById(phone).orElseThrow(()-> new CustomException(ErrorCodeEnum.CODE_IS_EXPIRED)); | ||
} | ||
|
||
/** | ||
* 인증 여부 저장 | ||
* @param phone | ||
*/ | ||
@Override | ||
public void saveCheckedPhone(String phone) { | ||
verifyCertificationRepository.save(new VerifyPhoneCertification(phone)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/api/sms/adapter/out/persistence/VerifyPhoneCertification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.api.sms.adapter.out.persistence; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
import java.io.Serializable; | ||
|
||
|
||
/** | ||
* 핸드폰 인증 성공시 한시간 동안 유효하게 냅둠 | ||
*/ | ||
@Getter | ||
@AllArgsConstructor | ||
@RedisHash(value = "phone_check", timeToLive = 3600) // hash collection 명시 | ||
public class VerifyPhoneCertification implements Serializable { | ||
@Id | ||
String phone; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/api/sms/application/port/in/SendCertificationCodeUsecase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.api.sms.application.port.in; | ||
|
||
import com.amazonaws.services.sns.model.PublishResult; | ||
|
||
public interface SendCertificationCodeUsecase { | ||
PublishResult send(String phone); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/api/sms/application/port/in/VerifyCodeUsecase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.api.sms.application.port.in; | ||
|
||
import com.example.api.sms.dto.CheckSMSDto; | ||
|
||
public interface VerifyCodeUsecase { | ||
void verifyCertificationCode(CheckSMSDto checkSMSDto); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/api/sms/application/port/out/CertificationCodePort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.api.sms.application.port.out; | ||
|
||
import com.example.api.sms.adapter.out.persistence.PhoneCertification; | ||
|
||
public interface CertificationCodePort { | ||
void saveCode(String phone, String code); | ||
|
||
PhoneCertification findCode(String phone); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/api/sms/application/port/out/CheckVerifiedPhonePort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.api.sms.application.port.out; | ||
|
||
public interface CheckVerifiedPhonePort { | ||
void findCheckedPhone(String phone); | ||
|
||
void saveCheckedPhone(String phone); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.api.sms.dto; | ||
|
||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CheckSMSDto { | ||
@NotBlank(message = "핸드폰 번호를 입력해주세요") | ||
@Pattern( | ||
regexp = "(01[016789])(\\d{3,4})(\\d{4})", | ||
message = "올바른 핸드폰 번호를 입력해주세요" | ||
) | ||
String phone; | ||
|
||
@NotBlank(message = "인증번호를 입력해주세요") | ||
@Pattern(regexp = "^[0-9]{6}$", message = "숫자 6자리만 입력해야 합니다.") | ||
String code; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/api/sms/repository/PhoneCertificationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.api.sms.repository; | ||
|
||
import com.example.api.sms.adapter.out.persistence.PhoneCertification; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface PhoneCertificationRepository extends CrudRepository<PhoneCertification, String> { | ||
// Optional<PhoneCertification> findByPhone(String phone); | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/api/sms/repository/VerifyCertificationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.api.sms.repository; | ||
|
||
import com.example.api.sms.adapter.out.persistence.VerifyPhoneCertification; | ||
import org.springframework.data.repository.CrudRepository; | ||
|
||
public interface VerifyCertificationRepository extends CrudRepository<VerifyPhoneCertification, String> { | ||
|
||
} |
Oops, something went wrong.