From 9fb72aaf397478545cecfd8950c271fd90335d7f Mon Sep 17 00:00:00 2001 From: JIN-076 Date: Mon, 19 Feb 2024 15:58:19 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8?= =?UTF-8?q?=20=EB=A7=A4=EC=B9=AD=20=EC=9A=94=EC=B2=AD=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20API=20=EC=9E=91=EC=84=B1,=20API=20=EA=B4=80=EB=A0=A8=20Swagg?= =?UTF-8?q?er=20=EC=9E=91=EC=84=B1,=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0,?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=83=98?= =?UTF-8?q?=ED=94=8C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/ProjectJoinRequestSwagger.java | 56 +++++++++++++++++++ ...waggerProjectJoinRequestErrorExamples.java | 12 ++++ .../ProjectJoinRequestController.java | 30 ++++++++++ .../mogakgo/exception/code/ErrorCode400.java | 5 +- 4 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/oeid/mogakgo/common/swagger/template/ProjectJoinRequestSwagger.java create mode 100644 src/main/java/io/oeid/mogakgo/core/properties/swagger/error/SwaggerProjectJoinRequestErrorExamples.java create mode 100644 src/main/java/io/oeid/mogakgo/domain/project_join_req/presentation/ProjectJoinRequestController.java diff --git a/src/main/java/io/oeid/mogakgo/common/swagger/template/ProjectJoinRequestSwagger.java b/src/main/java/io/oeid/mogakgo/common/swagger/template/ProjectJoinRequestSwagger.java new file mode 100644 index 00000000..4c6be793 --- /dev/null +++ b/src/main/java/io/oeid/mogakgo/common/swagger/template/ProjectJoinRequestSwagger.java @@ -0,0 +1,56 @@ +package io.oeid.mogakgo.common.swagger.template; + +import io.oeid.mogakgo.core.properties.swagger.error.SwaggerProjectErrorExamples; +import io.oeid.mogakgo.core.properties.swagger.error.SwaggerProjectJoinRequestErrorExamples; +import io.oeid.mogakgo.core.properties.swagger.error.SwaggerUserErrorExamples; +import io.oeid.mogakgo.domain.project_join_req.application.dto.req.ProjectJoinCreateReq; +import io.oeid.mogakgo.domain.project_join_req.presentation.dto.res.ProjectJoinRequestAPIRes; +import io.oeid.mogakgo.exception.dto.ErrorResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; + +@Tag(name = "Project Join Request", description = "프로젝트 매칭 요청 관련 API") +public interface ProjectJoinRequestSwagger { + + @Operation(summary = "프로젝트 매칭 요청 생성", description = "회원이 프로젝트 매칭 요청을 생성할 때 사용하는 API") + @ApiResponses(value = { + @ApiResponse(responseCode = "201", description = "프로젝트 매칭 요청 생성 성공", + content = @Content(schema = @Schema(implementation = ProjectJoinRequestAPIRes.class))), + @ApiResponse(responseCode = "400", description = "요청한 데이터가 유효하지 않음", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ErrorResponse.class), + examples = { + @ExampleObject(name = "E090101", + value = SwaggerProjectJoinRequestErrorExamples.PROJECT_JOIN_REQUEST_ALREADY_EXIST), + @ExampleObject(name = "E090103", + value = SwaggerProjectJoinRequestErrorExamples.PROJECT_JOIN_REQUEST_INVALID_REGION) + })), + @ApiResponse(responseCode = "403", description = "프로젝트 매칭 요청 권한이 없음", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ErrorResponse.class), + examples = @ExampleObject(name = "E090201", + value = SwaggerProjectJoinRequestErrorExamples.PROJECT_JOIN_REQUEST_FORBIDDEN_OPERATION))), + @ApiResponse(responseCode = "404", description = "요청한 데이터가 존재하지 않음", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = ErrorResponse.class), + examples = { + @ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND), + @ExampleObject(name = "E030301", value = SwaggerProjectErrorExamples.PROJECT_NOT_FOUND) + })), + }) + ResponseEntity create( + @Parameter(hidden = true) Long userId, + ProjectJoinCreateReq request + ); + +} diff --git a/src/main/java/io/oeid/mogakgo/core/properties/swagger/error/SwaggerProjectJoinRequestErrorExamples.java b/src/main/java/io/oeid/mogakgo/core/properties/swagger/error/SwaggerProjectJoinRequestErrorExamples.java new file mode 100644 index 00000000..88a6b9b1 --- /dev/null +++ b/src/main/java/io/oeid/mogakgo/core/properties/swagger/error/SwaggerProjectJoinRequestErrorExamples.java @@ -0,0 +1,12 @@ +package io.oeid.mogakgo.core.properties.swagger.error; + +public class SwaggerProjectJoinRequestErrorExamples { + + public static final String PROJECT_JOIN_REQUEST_ALREADY_EXIST = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":403,\"code\":\"E090201\",\"message\":\"프로젝트 생성자는 해당 프로젝트에 매칭 요청을 보낼 수 없습니다.\"}"; + public static final String PROJECT_JOIN_REQUEST_FORBIDDEN_OPERATION = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":403,\"code\":\"E090101\",\"message\":\"이미 매칭 요청을 보낸 프로젝트에 매칭 요청을 보낼 수 없습니다..\"}"; + public static final String PROJECT_JOIN_REQUEST_INVALID_REGION = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":403,\"code\":\"E090102\",\"message\":\"프로젝트 매칭 서비스는 동네 인증되지 않은 구역에서 진행할 수 없습니다..\"}"; + private SwaggerProjectJoinRequestErrorExamples() { + + } + +} diff --git a/src/main/java/io/oeid/mogakgo/domain/project_join_req/presentation/ProjectJoinRequestController.java b/src/main/java/io/oeid/mogakgo/domain/project_join_req/presentation/ProjectJoinRequestController.java new file mode 100644 index 00000000..3533aaba --- /dev/null +++ b/src/main/java/io/oeid/mogakgo/domain/project_join_req/presentation/ProjectJoinRequestController.java @@ -0,0 +1,30 @@ +package io.oeid.mogakgo.domain.project_join_req.presentation; + +import io.oeid.mogakgo.common.annotation.UserId; +import io.oeid.mogakgo.common.swagger.template.ProjectJoinRequestSwagger; +import io.oeid.mogakgo.domain.project_join_req.application.ProjectJoinRequestService; +import io.oeid.mogakgo.domain.project_join_req.application.dto.req.ProjectJoinCreateReq; +import io.oeid.mogakgo.domain.project_join_req.presentation.dto.res.ProjectJoinRequestAPIRes; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1/project-join-request") +@RequiredArgsConstructor +public class ProjectJoinRequestController implements ProjectJoinRequestSwagger { + + private final ProjectJoinRequestService projectJoinRequestService; + + @PostMapping + public ResponseEntity create( + @UserId Long userId, @Valid @RequestBody ProjectJoinCreateReq request + ) { + return ResponseEntity.status(201) + .body(ProjectJoinRequestAPIRes.from(projectJoinRequestService.create(userId, request))); + } +} diff --git a/src/main/java/io/oeid/mogakgo/exception/code/ErrorCode400.java b/src/main/java/io/oeid/mogakgo/exception/code/ErrorCode400.java index b4f2e78a..7acb9040 100644 --- a/src/main/java/io/oeid/mogakgo/exception/code/ErrorCode400.java +++ b/src/main/java/io/oeid/mogakgo/exception/code/ErrorCode400.java @@ -26,9 +26,8 @@ public enum ErrorCode400 implements ErrorCode { USERNAME_SHOULD_BE_NOT_EMPTY("E020103", "유저 이름은 비어있을 수 없습니다."), USER_REGION_SHOULD_BE_NOT_EMPTY("E020104", "유저 지역은 비어있을 수 없습니다."), USER_ID_NOT_NULL("E020001", "유저 아이디는 필수값입니다."), - INVALID_PROJECT_JOIN_REQUEST("E090101", "프로젝트 생성자는 프로젝트 매칭 요청을 생성할 수 없습니다."), - PROJECT_JOIN_REQUEST_ALREADY_EXIST("E090102", "이미 매칭 요청을 전송한 프로젝트에 매칭 요청을 생성할 수 없습니다."), - INVALID_PROJECT_JOIN_REQUEST_REGION("E090103", "동네 인증한 구역에서만 프로젝트 매칭 요청을 생성할 수 있습니다."), + PROJECT_JOIN_REQUEST_ALREADY_EXIST("E090101", "이미 매칭 요청을 전송한 프로젝트에 매칭 요청을 생성할 수 없습니다."), + INVALID_PROJECT_JOIN_REQUEST_REGION("E090102", "동네 인증한 구역에서만 프로젝트 매칭 요청을 생성할 수 있습니다."), ; private final HttpStatus httpStatus = HttpStatus.BAD_REQUEST;