-
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.
Merge pull request #20 from KUSITMS-Team-A/feature/19-sms-api
[#19] Feature: 문자 인증 코드를 전송합니다.
- Loading branch information
Showing
7 changed files
with
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
rootProject.name = 'Backend' | ||
rootProject.name = 'backend' |
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 |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package com.backend.domain.mail.controller; | ||
|
||
import com.backend.domain.mail.dto.request.MailRequest; | ||
import com.backend.domain.mail.dto.request.SmsRequest; | ||
import com.backend.domain.mail.service.MailService; | ||
import com.backend.error.ErrorCode; | ||
import com.backend.error.dto.ErrorResponse; | ||
import com.backend.error.exception.custom.BusinessException; | ||
import io.github.resilience4j.ratelimiter.annotation.RateLimiter; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
|
@@ -17,8 +24,31 @@ public class MailController { | |
|
||
private final MailService mailService; | ||
|
||
@PostMapping("/mail") | ||
@Operation(summary = "메일 인증 코드 전송", description = "입력한 메일에 인증 코드를 전송합니다. 형식: [email protected]", | ||
responses = { | ||
@ApiResponse(responseCode = "200", description = "인증 코드 전송 성공, 보낸 인증 코드를 반환합니다.", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
}) | ||
@GetMapping("/mail") | ||
public ResponseEntity<Integer> sendCode(@Valid @RequestBody MailRequest emailRequest) { | ||
return ResponseEntity.ok(mailService.sendAuthenticationCode(emailRequest)); | ||
} | ||
|
||
@Operation(summary = "문자 인증 코드 전송", description = "입력한 번호에 인증 코드를 전송합니다. 형식: 01012345678", | ||
responses = { | ||
@ApiResponse(responseCode = "200", description = "인증 코드 전송 성공, 보낸 인증 코드를 반환합니다.", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class))) | ||
}) | ||
@RateLimiter(name = "jedero", fallbackMethod = "rateLimiterFallback") | ||
@GetMapping("/sms") | ||
public ResponseEntity<Integer> sendSMS(@Valid @RequestBody SmsRequest smsRequest) { | ||
int result = mailService.sendSMS(smsRequest); | ||
return ResponseEntity.ok(result); | ||
} | ||
|
||
public ResponseEntity<String> rateLimiterFallback(Throwable t) { | ||
// HttpHeaders responseHeaders = new HttpHeaders(); | ||
// responseHeaders.set("Retry-After", "10s"); | ||
throw new BusinessException(ErrorCode.TOO_MANY_SMS); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/backend/domain/mail/dto/request/SmsRequest.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,6 @@ | ||
package com.backend.domain.mail.dto.request; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
|
||
public record SmsRequest(@NotEmpty String toNumber) { | ||
} |
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