-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
168 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.moddy.server.common.util; | ||
|
||
import com.moddy.server.external.sms.SmsService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class SmsUtil { | ||
private final SmsService smsService; | ||
|
||
public boolean sendVerificationCode(String to, String verificationCode) { | ||
return smsService.sendSms(to, verificationCode); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/moddy/server/config/sms/AwsSnsConfig.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,27 @@ | ||
package com.moddy.server.config.sms; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.sns.AmazonSNSClient; | ||
import com.amazonaws.services.sns.AmazonSNSClientBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class AwsSnsConfig { | ||
@Value("${cloud.aws.credentials.accessKey}") | ||
private String accessKey; | ||
@Value("${cloud.aws.credentials.secretKey}") | ||
private String secretKey; | ||
|
||
@Bean | ||
public AmazonSNSClient amazonSNSClient() { | ||
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); | ||
return (AmazonSNSClient) AmazonSNSClientBuilder | ||
.standard() | ||
.withRegion("ap-northeast-1") | ||
.withCredentials(new AWSStaticCredentialsProvider(credentials)) | ||
.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
4 changes: 4 additions & 0 deletions
4
src/main/java/com/moddy/server/controller/auth/dto/request/PhoneNumberRequestDto.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,4 @@ | ||
package com.moddy.server.controller.auth.dto.request; | ||
|
||
public record PhoneNumberRequestDto(String phoneNumber) { | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/moddy/server/domain/verify/UserVerification.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,25 @@ | ||
package com.moddy.server.domain.verify; | ||
|
||
import com.moddy.server.domain.BaseTimeEntity; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class UserVerification extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@NotNull | ||
private String phoneNumber; | ||
@NotNull | ||
private String verificationCode; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/moddy/server/domain/verify/repository/UserVerificationRepository.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,12 @@ | ||
package com.moddy.server.domain.verify.repository; | ||
|
||
import com.moddy.server.domain.verify.UserVerification; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface UserVerificationRepository extends JpaRepository<UserVerification, Long> { | ||
Optional<UserVerification> findByPhoneNumber(String phoneNumber); | ||
|
||
void deleteByPhoneNumber(String phoneNumber); | ||
} |
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.moddy.server.external.sms; | ||
|
||
public interface SmsService { | ||
String MESSAGE_FORM = "[%s] moddy에서 보낸 인증번호입니다. 해당 인증번호는 3분간 유효합니다."; | ||
|
||
boolean sendSms(String to, String verificationCode); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/moddy/server/external/sms/impl/AwsSmsServiceImpl.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,24 @@ | ||
package com.moddy.server.external.sms.impl; | ||
|
||
import com.amazonaws.services.sns.AmazonSNSClient; | ||
import com.amazonaws.services.sns.model.PublishRequest; | ||
import com.moddy.server.external.sms.SmsService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class AwsSmsServiceImpl implements SmsService { | ||
private final AmazonSNSClient amazonSNSClient; | ||
private static final String KR = "+82"; | ||
|
||
@Override | ||
public boolean sendSms(String to, String verificationCode) { | ||
PublishRequest request = new PublishRequest(); | ||
request.setMessage(String.format(MESSAGE_FORM, verificationCode)); | ||
request.setPhoneNumber(KR + to); | ||
|
||
amazonSNSClient.publish(request); | ||
return true; | ||
} | ||
} |
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