Skip to content

Commit c9f5f47

Browse files
committed
feat : add 이메일 중복 api
1 parent 7c33b57 commit c9f5f47

File tree

20 files changed

+370
-7
lines changed

20 files changed

+370
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ out/
3838

3939
### env ###
4040
.env
41+
local.env
4142

4243
### sql ###
4344
*.sql

src/docs/asciidoc/index.adoc

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Content-Type : application/json
3434
{
3535
"status": "http status" ,
3636
"code": "custom status code",
37-
"message" : "response message"
37+
"message" : "response message",
3838
"data": "data"
3939
}
4040
----
@@ -69,7 +69,7 @@ Content-Type: application/json
6969
{
7070
"status": "CREATED", // 예시
7171
"code": "S002", //예시
72-
"message" : "resource가 정상적으로 생성되었습니다."
72+
"message" : "resource가 정상적으로 생성되었습니다.",
7373
"data": null
7474
}
7575
----
@@ -82,7 +82,7 @@ Content-Type: application/json
8282
{
8383
"status": "OK", //예시
8484
"code": "S001", //예시
85-
"message" : "요청이 정상적으로 처리되었습니다."
85+
"message" : "요청이 정상적으로 처리되었습니다.",
8686
"data": {
8787
"id": 123,
8888
"name": "example"
@@ -99,3 +99,22 @@ Content-Type: application/json
9999
| 공통 | 500 | INTERNAL_SERVER_ERROR | E500_001 | 서버 측에서 처리하지 못한 예외가 발생하면 모든 api 요청에 대해 공통적으로 반환됨.
100100
|===
101101

102+
== 회원
103+
104+
=== **1. 이메일 중복 확인**
105+
106+
이메일 중복을 확인하는 api입니다.
107+
108+
==== Request
109+
include::{snippets}/api/users/email/duplication/1/http-request.adoc[]
110+
111+
==== Request Query Parameter Fields
112+
include::{snippets}/api/users/email/duplication/1/query-parameters.adoc[]
113+
114+
==== 성공 Response
115+
include::{snippets}/api/users/email/duplication/1/http-response.adoc[]
116+
117+
==== Response Body Fields
118+
include::{snippets}/api/users/email/duplication/1/response-fields.adoc[]
119+
120+
---

src/main/java/com/ftm/server/adapter/controller/user/.gitkeep

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.ftm.server.adapter.controller.user;
2+
3+
import com.ftm.server.adapter.dto.response.EmailDuplicationCheckResponse;
4+
import com.ftm.server.common.response.ApiResponse;
5+
import com.ftm.server.common.response.enums.SuccessResponseCode;
6+
import com.ftm.server.domain.dto.query.FindByEmailQuery;
7+
import com.ftm.server.domain.usecase.user.EmailDuplicationCheckUseCase;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.GetMapping;
12+
import org.springframework.web.bind.annotation.RequestParam;
13+
import org.springframework.web.bind.annotation.RestController;
14+
15+
@RestController
16+
@RequiredArgsConstructor
17+
public class EmailDuplicationCheckController {
18+
19+
private final EmailDuplicationCheckUseCase emailDuplicationCheckUseCase;
20+
21+
@GetMapping("api/users/email/duplication")
22+
public ResponseEntity<ApiResponse<EmailDuplicationCheckResponse>> emailDuplicationCheck(
23+
@RequestParam(value = "email") String email) {
24+
return ResponseEntity.status(HttpStatus.OK)
25+
.body(
26+
ApiResponse.success(
27+
SuccessResponseCode.OK,
28+
EmailDuplicationCheckResponse.from(
29+
emailDuplicationCheckUseCase.emailDuplicationCheck(
30+
FindByEmailQuery.of(email)))));
31+
}
32+
}

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

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.ftm.server.adapter.dto.response;
2+
3+
import com.ftm.server.domain.dto.vo.EmailDuplicationVo;
4+
import lombok.Data;
5+
6+
@Data
7+
public class EmailDuplicationCheckResponse {
8+
9+
private final Boolean isDuplicated;
10+
11+
public static EmailDuplicationCheckResponse from(EmailDuplicationVo emailDuplicationVo) {
12+
return new EmailDuplicationCheckResponse(emailDuplicationVo.getIsDuplicated());
13+
}
14+
}

src/main/java/com/ftm/server/adapter/gateway/repository/UserRepository.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
import com.ftm.server.entity.entities.User;
44
import org.springframework.data.jpa.repository.JpaRepository;
55

6-
public interface UserRepository extends JpaRepository<User, Long> {}
6+
public interface UserRepository extends JpaRepository<User, Long> {
7+
8+
Boolean existsByEmail(String email);
9+
}

src/main/java/com/ftm/server/common/exception/CustomException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public class CustomException extends RuntimeException {
88

99
private final ErrorResponseCode errorResponseCode;
1010

11+
public CustomException(ErrorResponseCode errorResponseCode, String message) {
12+
super(message); // 예외 메시지 설정
13+
this.errorResponseCode = errorResponseCode;
14+
}
15+
1116
public CustomException(ErrorResponseCode errorResponseCode) {
1217
super(errorResponseCode.getMessage()); // 예외 메시지 설정
1318
this.errorResponseCode = errorResponseCode;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.ftm.server.common.handler;
2+
3+
import com.ftm.server.common.exception.CustomException;
4+
import com.ftm.server.common.response.ApiResponse;
5+
import com.ftm.server.common.response.enums.ErrorResponseCode;
6+
import lombok.extern.slf4j.Slf4j;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.http.converter.HttpMessageNotReadableException;
9+
import org.springframework.web.bind.MethodArgumentNotValidException;
10+
import org.springframework.web.bind.MissingServletRequestParameterException;
11+
import org.springframework.web.bind.annotation.ExceptionHandler;
12+
import org.springframework.web.bind.annotation.RestControllerAdvice;
13+
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
14+
import org.springframework.web.multipart.support.MissingServletRequestPartException;
15+
16+
@Slf4j
17+
@RestControllerAdvice
18+
public class GlobalExceptionHandler {
19+
20+
@ExceptionHandler({CustomException.class})
21+
public ResponseEntity<ApiResponse> handleCustomException(CustomException e) {
22+
log.error(
23+
"[{}] code:{} / code message:{}",
24+
e.getErrorResponseCode().name(),
25+
e.getErrorResponseCode().getCode(),
26+
e.getMessage());
27+
return ResponseEntity.status(e.getErrorResponseCode().getHttpStatus())
28+
.body(ApiResponse.fail(e.getErrorResponseCode()));
29+
}
30+
31+
// 기타 처리되지 못한 exception
32+
@ExceptionHandler(Exception.class)
33+
public ResponseEntity<ApiResponse> handlingException(Exception e) {
34+
35+
log.error(
36+
"[Exception] code : {} code message : {}",
37+
ErrorResponseCode.UNKNOWN_SERVER_ERROR.getCode(),
38+
e.getMessage());
39+
return ResponseEntity.status(ErrorResponseCode.UNKNOWN_SERVER_ERROR.getHttpStatus())
40+
.body(ApiResponse.fail(ErrorResponseCode.UNKNOWN_SERVER_ERROR));
41+
}
42+
43+
// request body의 type이 잘못된 경우
44+
@ExceptionHandler({
45+
MethodArgumentNotValidException
46+
.class, // json body (requestpart의 body, requestBody의 body)의 필드가 설정한 유효값을 만족시키지 않거나,
47+
// 필수값이 누락됨.
48+
HttpMessageNotReadableException
49+
.class, // json body (requestpart의 body, requestBody의 body)의 필드 type이 잘못됨.
50+
MissingServletRequestPartException.class, // required인 requestpart가 없음.
51+
MissingServletRequestParameterException.class, // requried인 request param이 없음.
52+
MethodArgumentTypeMismatchException.class // request parameter, pathVariable의 type이 잘못됨.
53+
})
54+
public ResponseEntity<ApiResponse> handleMissingServletRequestPartException(Exception e) {
55+
56+
log.error(
57+
"[Exception] code : {} code message : {}",
58+
ErrorResponseCode.INVALID_REQUEST_ARGUMENT.getCode(),
59+
e.getMessage());
60+
return ResponseEntity.status(ErrorResponseCode.INVALID_REQUEST_ARGUMENT.getHttpStatus())
61+
.body(ApiResponse.fail(ErrorResponseCode.INVALID_REQUEST_ARGUMENT));
62+
}
63+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public enum ErrorResponseCode {
88

99
// 400번
1010
INVALID_REQUEST_ARGUMENT(
11-
HttpStatus.BAD_REQUEST, "E400_001", "클라이언트 요청이 잘못된 형식이거나, 필수 데이터가 누락되었습니다."),
11+
HttpStatus.BAD_REQUEST, "E400_001", "클라이언트 요청값의 일부가 잘못된 형식이거나, 필수 데이터가 누락되었습니다."),
1212

1313
// 401번
1414
NOT_AUTHENTICATED(HttpStatus.UNAUTHORIZED, "E401_001", "인증되지 않은 사용자입니다."),

0 commit comments

Comments
 (0)