Skip to content

Commit 79f180f

Browse files
committed
feat : Add Email Authentication Code Sender Api
1 parent d28cf86 commit 79f180f

File tree

18 files changed

+480
-4
lines changed

18 files changed

+480
-4
lines changed

src/docs/asciidoc/index.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,26 @@ include::{snippetsDir}/emailDuplicationCheck/1/http-response.adoc[]
119119
include::{snippetsDir}/emailDuplicationCheck/1/response-fields.adoc[]
120120

121121
---
122+
123+
124+
=== **2. 이메일 인증 api**
125+
126+
이메일 인증용 코드를 발송하는 api입니다.
127+
128+
==== Request
129+
include::{snippetsDir}/emailAuthentication/1/http-request.adoc[]
130+
131+
==== Request Body Fields
132+
include::{snippetsDir}/emailAuthentication/1/request-fields.adoc[]
133+
134+
==== 성공 Response
135+
include::{snippetsDir}/emailAuthentication/1/http-response.adoc[]
136+
137+
==== Response Body Fields
138+
include::{snippetsDir}/emailAuthentication/1/response-fields.adoc[]
139+
140+
==== 실패 Response
141+
실패1.
142+
include::{snippetsDir}/emailAuthentication/2/http-response.adoc[]
143+
실패 2
144+
include::{snippetsDir}/emailAuthentication/3/http-response.adoc[]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.ftm.server.adapter.controller.user;
2+
3+
import com.ftm.server.adapter.dto.request.EmailAuthenticationRequest;
4+
import com.ftm.server.common.response.ApiResponse;
5+
import com.ftm.server.common.response.enums.SuccessResponseCode;
6+
import com.ftm.server.domain.dto.command.EmailAuthenticationCommand;
7+
import com.ftm.server.domain.usecase.user.EmailAuthenticationUseCase;
8+
import jakarta.validation.Valid;
9+
import lombok.RequiredArgsConstructor;
10+
import org.springframework.http.HttpStatus;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.bind.annotation.PostMapping;
13+
import org.springframework.web.bind.annotation.RequestBody;
14+
import org.springframework.web.bind.annotation.RestController;
15+
16+
@RequiredArgsConstructor
17+
@RestController
18+
public class EmailAuthenticationController {
19+
20+
private final EmailAuthenticationUseCase emailAuthenticationUseCase;
21+
22+
@PostMapping("/api/users/email/authentication")
23+
public ResponseEntity<ApiResponse<Object>> emailAuthenticationCodeSender(
24+
@Valid @RequestBody EmailAuthenticationRequest request) {
25+
emailAuthenticationUseCase.sendEmailAuthenticationCode(
26+
EmailAuthenticationCommand.from(request)); // command 객체 전달
27+
return ResponseEntity.status(HttpStatus.OK)
28+
.body(ApiResponse.success(SuccessResponseCode.OK));
29+
}
30+
}

src/main/java/com/ftm/server/adapter/dto/request/.gitkeep

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ftm.server.adapter.dto.request;
2+
3+
import jakarta.validation.constraints.Pattern;
4+
import lombok.Data;
5+
6+
@Data
7+
public class EmailAuthenticationRequest {
8+
9+
@Pattern(
10+
regexp = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$",
11+
message = "이메일 형식이 올바르지 않습니다.")
12+
private final String email;
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.ftm.server.adapter.gateway;
2+
3+
public interface MailSenderGateway {
4+
5+
void sendEmail(String to, String code);
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ftm.server.adapter.gateway.repository;
2+
3+
import com.ftm.server.entity.entities.EmailVerificationLogs;
4+
import java.util.Optional;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.stereotype.Repository;
7+
8+
@Repository
9+
public interface EmailVerificationLogsRepository
10+
extends JpaRepository<EmailVerificationLogs, Long> {
11+
12+
Optional<EmailVerificationLogs> findByEmail(String email);
13+
}

src/main/java/com/ftm/server/common/response/enums/ErrorResponseCode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ public enum ErrorResponseCode {
2222
// 409번
2323
USER_ALREADY_EXISTS(HttpStatus.CONFLICT, "E409_001", "이미 존재하는 사용자입니다."),
2424
PASSWORD_NOT_MATCHED(HttpStatus.CONFLICT, "E409_002", "비밀번호가 일치하지 않습니다."),
25+
EXCEED_NUMBER_OF_TRIAL(HttpStatus.CONFLICT, "E409_003", "시도 가능 횟수를 초과했습니다. 잠시 후에 다시 시도 해 주세요."),
2526

2627
// 500번
27-
UNKNOWN_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "E500_001", "알 수 없는 서버 에러가 발생했습니다.");
28+
UNKNOWN_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "E500_001", "알 수 없는 서버 에러가 발생했습니다."),
29+
FAIL_TO_SEND_EMAIL(HttpStatus.INTERNAL_SERVER_ERROR, "E500_002", "서버 내부 문제로 메일 전송에 실패했습니다.");
2830

2931
private final HttpStatus httpStatus;
3032
private final String code;

src/main/java/com/ftm/server/common/utils/.gitkeep

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.ftm.server.common.utils;
2+
3+
import java.security.SecureRandom;
4+
import org.springframework.stereotype.Component;
5+
6+
@Component
7+
public class RandomCodeCreator {
8+
9+
private static final int CODE_LENGTH = 6;
10+
11+
private final SecureRandom random = new SecureRandom();
12+
13+
public String generateAuthCode() {
14+
15+
StringBuilder sb = new StringBuilder(CODE_LENGTH);
16+
for (int i = 0; i < CODE_LENGTH; i++) {
17+
int digit = random.nextInt(10);
18+
sb.append(digit);
19+
}
20+
return sb.toString();
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ftm.server.domain.dto.command;
2+
3+
import com.ftm.server.adapter.dto.request.EmailAuthenticationRequest;
4+
import lombok.Data;
5+
6+
@Data
7+
public class EmailAuthenticationCommand {
8+
private final String email;
9+
10+
public static EmailAuthenticationCommand from(EmailAuthenticationRequest request) {
11+
return new EmailAuthenticationCommand(request.getEmail());
12+
}
13+
}

0 commit comments

Comments
 (0)