From 242e0013c3e28156f9a1a423b707b7c2b853ecc8 Mon Sep 17 00:00:00 2001 From: KyungMin Lee Date: Mon, 26 Feb 2024 12:08:29 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20Swagger=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/swagger/template/ChatSwagger.java | 55 +++++++++++++++++++ .../error/SwaggerChatErrorExamples.java | 9 +++ .../domain/chat/application/ChatService.java | 1 + .../chat/presentation/ChatController.java | 3 +- 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/oeid/mogakgo/common/swagger/template/ChatSwagger.java create mode 100644 src/main/java/io/oeid/mogakgo/core/properties/swagger/error/SwaggerChatErrorExamples.java diff --git a/src/main/java/io/oeid/mogakgo/common/swagger/template/ChatSwagger.java b/src/main/java/io/oeid/mogakgo/common/swagger/template/ChatSwagger.java new file mode 100644 index 00000000..e418e484 --- /dev/null +++ b/src/main/java/io/oeid/mogakgo/common/swagger/template/ChatSwagger.java @@ -0,0 +1,55 @@ +package io.oeid.mogakgo.common.swagger.template; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +import io.oeid.mogakgo.core.properties.swagger.error.SwaggerChatErrorExamples; +import io.oeid.mogakgo.core.properties.swagger.error.SwaggerProjectErrorExamples; +import io.oeid.mogakgo.core.properties.swagger.error.SwaggerUserErrorExamples; +import io.oeid.mogakgo.domain.chat.application.dto.res.ChatRoomDataRes; +import io.oeid.mogakgo.domain.chat.application.dto.res.ChatRoomPublicRes; +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.enums.ParameterIn; +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 java.util.List; +import org.springframework.http.ResponseEntity; + +@Tag(name = "Chat", description = "채팅 관련 API") +@SuppressWarnings("unused") +public interface ChatSwagger { + + @Operation(summary = "채팅방 목록 조회", description = "사용자의 채팅방 목록을 조회하는 API") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "채팅방 목록 조회 성공"), + @ApiResponse(responseCode = "404", description = "요청한 유저가 존재하지 않음", + content = @Content( + mediaType = APPLICATION_JSON_VALUE, + schema = @Schema(implementation = ErrorResponse.class), + examples = @ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND) + )) + }) + ResponseEntity> getChatRoomList(@Parameter(hidden = true) Long userId); + + @Operation(summary = "채팅방 상세 조회", description = "채팅방의 상세 정보를 조회하는 API") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "채팅방 상세 조회 성공"), + @ApiResponse(responseCode = "404", description = "요청한 데이터가 유효하지 않음", + content = @Content( + mediaType = APPLICATION_JSON_VALUE, + schema = @Schema(implementation = ErrorResponse.class), + examples = { + @ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND), + @ExampleObject(name = "E030301", value = SwaggerProjectErrorExamples.PROJECT_NOT_FOUND), + @ExampleObject(name = "E110301", value = SwaggerChatErrorExamples.CHAT_ROOM_NOT_FOUND) + } + )) + }) + ResponseEntity getChatRoomDetailData(@Parameter(hidden = true) Long userId, + @Parameter(in = ParameterIn.PATH) String chatRoomId); +} diff --git a/src/main/java/io/oeid/mogakgo/core/properties/swagger/error/SwaggerChatErrorExamples.java b/src/main/java/io/oeid/mogakgo/core/properties/swagger/error/SwaggerChatErrorExamples.java new file mode 100644 index 00000000..989a0df2 --- /dev/null +++ b/src/main/java/io/oeid/mogakgo/core/properties/swagger/error/SwaggerChatErrorExamples.java @@ -0,0 +1,9 @@ +package io.oeid.mogakgo.core.properties.swagger.error; + +public class SwaggerChatErrorExamples { + + public static final String CHAT_ROOM_NOT_FOUND = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":404,\"code\":\"E110301\",\"message\":\"해당 채팅방이 존재하지 않습니다.\"}"; + + private SwaggerChatErrorExamples() { + } +} diff --git a/src/main/java/io/oeid/mogakgo/domain/chat/application/ChatService.java b/src/main/java/io/oeid/mogakgo/domain/chat/application/ChatService.java index d764c39a..19ca7d41 100644 --- a/src/main/java/io/oeid/mogakgo/domain/chat/application/ChatService.java +++ b/src/main/java/io/oeid/mogakgo/domain/chat/application/ChatService.java @@ -34,6 +34,7 @@ public class ChatService { // 채팅방 리스트 조회 // TODO 마지막 채팅 기록 가져오기 구현 public List findAllChatRoomByUserId(Long userId) { + userCommonService.getUserById(userId); return chatRoomRepository.findAllChatRoomByUserId(userId); } diff --git a/src/main/java/io/oeid/mogakgo/domain/chat/presentation/ChatController.java b/src/main/java/io/oeid/mogakgo/domain/chat/presentation/ChatController.java index b0946ee8..3803eadc 100644 --- a/src/main/java/io/oeid/mogakgo/domain/chat/presentation/ChatController.java +++ b/src/main/java/io/oeid/mogakgo/domain/chat/presentation/ChatController.java @@ -1,6 +1,7 @@ package io.oeid.mogakgo.domain.chat.presentation; import io.oeid.mogakgo.common.annotation.UserId; +import io.oeid.mogakgo.common.swagger.template.ChatSwagger; import io.oeid.mogakgo.domain.chat.application.ChatService; import io.oeid.mogakgo.domain.chat.application.dto.res.ChatRoomDataRes; import io.oeid.mogakgo.domain.chat.application.dto.res.ChatRoomPublicRes; @@ -15,7 +16,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/chat") -public class ChatController { +public class ChatController implements ChatSwagger { private final ChatService chatService;