From 8cf6bcf68c6d0113f51b901b7466cdd96ed785b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Tue, 3 Sep 2024 11:45:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=EC=A7=88=EB=AC=B8=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EB=AA=A9=EB=A1=9D=20=EB=B6=84=EB=A6=AC(Admin?= =?UTF-8?q?=EA=B3=BC=20=EC=9D=BC=EB=B0=98=20=EC=9C=A0=EC=A0=80=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminQuestionTypeStatusController.java | 12 -------- .../api/QuestionTypeStatusController.java | 29 +++++++++++++++++++ ...AdminQuestionTypeStatusControllerDocs.java | 8 ----- .../QuestionTypeStatusControllerDocs.java | 17 +++++++++++ 4 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 src/main/java/mju/iphak/maru_egg/question/api/QuestionTypeStatusController.java create mode 100644 src/main/java/mju/iphak/maru_egg/question/docs/QuestionTypeStatusControllerDocs.java diff --git a/src/main/java/mju/iphak/maru_egg/question/api/AdminQuestionTypeStatusController.java b/src/main/java/mju/iphak/maru_egg/question/api/AdminQuestionTypeStatusController.java index dd3fc8e..850c92d 100644 --- a/src/main/java/mju/iphak/maru_egg/question/api/AdminQuestionTypeStatusController.java +++ b/src/main/java/mju/iphak/maru_egg/question/api/AdminQuestionTypeStatusController.java @@ -1,8 +1,5 @@ package mju.iphak.maru_egg.question.api; -import java.util.List; - -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -16,7 +13,6 @@ import mju.iphak.maru_egg.question.application.QuestionTypeStatusService; import mju.iphak.maru_egg.question.docs.AdminQuestionTypeStatusControllerDocs; import mju.iphak.maru_egg.question.dto.request.UpdateQuestionTypeStatusRequest; -import mju.iphak.maru_egg.question.dto.response.QuestionTypeStatusResponse; @RequiredArgsConstructor @RestController @@ -42,12 +38,4 @@ public void initializeQuestionTypeStatus() { public void updateQuestionTypeStatus(@Valid @RequestBody UpdateQuestionTypeStatusRequest request) { questionTypeStatusService.updateStatus(request.type()); } - - @CustomApiResponses({ - @CustomApiResponse(error = "InternalServerError", status = 500, message = "내부 서버 오류가 발생했습니다.", description = "내부 서버 오류") - }) - @GetMapping() - public List getQuestionTypeStatus() { - return questionTypeStatusService.getQuestionTypeStatus(); - } } diff --git a/src/main/java/mju/iphak/maru_egg/question/api/QuestionTypeStatusController.java b/src/main/java/mju/iphak/maru_egg/question/api/QuestionTypeStatusController.java new file mode 100644 index 0000000..6b5223d --- /dev/null +++ b/src/main/java/mju/iphak/maru_egg/question/api/QuestionTypeStatusController.java @@ -0,0 +1,29 @@ +package mju.iphak.maru_egg.question.api; + +import java.util.List; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import lombok.RequiredArgsConstructor; +import mju.iphak.maru_egg.common.meta.CustomApiResponse; +import mju.iphak.maru_egg.common.meta.CustomApiResponses; +import mju.iphak.maru_egg.question.application.QuestionTypeStatusService; +import mju.iphak.maru_egg.question.dto.response.QuestionTypeStatusResponse; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/questions/status") +public class QuestionTypeStatusController { + + private final QuestionTypeStatusService questionTypeStatusService; + + @CustomApiResponses({ + @CustomApiResponse(error = "InternalServerError", status = 500, message = "내부 서버 오류가 발생했습니다.", description = "내부 서버 오류") + }) + @GetMapping() + public List getQuestionTypeStatus() { + return questionTypeStatusService.getQuestionTypeStatus(); + } +} diff --git a/src/main/java/mju/iphak/maru_egg/question/docs/AdminQuestionTypeStatusControllerDocs.java b/src/main/java/mju/iphak/maru_egg/question/docs/AdminQuestionTypeStatusControllerDocs.java index e90748d..04c8640 100644 --- a/src/main/java/mju/iphak/maru_egg/question/docs/AdminQuestionTypeStatusControllerDocs.java +++ b/src/main/java/mju/iphak/maru_egg/question/docs/AdminQuestionTypeStatusControllerDocs.java @@ -1,7 +1,5 @@ package mju.iphak.maru_egg.question.docs; -import java.util.List; - import org.springframework.web.bind.annotation.RequestBody; import io.swagger.v3.oas.annotations.Operation; @@ -9,7 +7,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import mju.iphak.maru_egg.question.dto.request.UpdateQuestionTypeStatusRequest; -import mju.iphak.maru_egg.question.dto.response.QuestionTypeStatusResponse; @Tag(name = "Admin QuestionTypeStatus API", description = "어드민 질문타입 상태 관련 API 입니다.") public interface AdminQuestionTypeStatusControllerDocs { @@ -23,9 +20,4 @@ public interface AdminQuestionTypeStatusControllerDocs { @ApiResponse(responseCode = "200", description = "질문타입 상태 변경 성공") }) void updateQuestionTypeStatus(@Valid @RequestBody UpdateQuestionTypeStatusRequest request); - - @Operation(summary = "전체 질문타입과 상태 조회", description = "전체 질문타입과 상태를 조회합니다.", responses = { - @ApiResponse(responseCode = "200", description = "전체 질문타입과 상태 조회 성공") - }) - List getQuestionTypeStatus(); } diff --git a/src/main/java/mju/iphak/maru_egg/question/docs/QuestionTypeStatusControllerDocs.java b/src/main/java/mju/iphak/maru_egg/question/docs/QuestionTypeStatusControllerDocs.java new file mode 100644 index 0000000..5198956 --- /dev/null +++ b/src/main/java/mju/iphak/maru_egg/question/docs/QuestionTypeStatusControllerDocs.java @@ -0,0 +1,17 @@ +package mju.iphak.maru_egg.question.docs; + +import java.util.List; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import mju.iphak.maru_egg.question.dto.response.QuestionTypeStatusResponse; + +@Tag(name = "QuestionTypeStatus API", description = "질문타입 상태 관련 API 입니다.") +public interface QuestionTypeStatusControllerDocs { + + @Operation(summary = "전체 질문타입과 상태 조회", description = "전체 질문타입과 상태를 조회합니다.", responses = { + @ApiResponse(responseCode = "200", description = "전체 질문타입과 상태 조회 성공") + }) + List getQuestionTypeStatus(); +} From 9759a19b5f2b5c78ccb197a5c87bb28b65a16132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=82=98=EA=B2=BD=ED=98=B8?= Date: Tue, 3 Sep 2024 11:45:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test:=20=EC=A7=88=EB=AC=B8=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EB=AA=A9=EB=A1=9D=20=EB=B6=84=EB=A6=AC(Admin?= =?UTF-8?q?=EA=B3=BC=20=EC=9D=BC=EB=B0=98=20=EC=9C=A0=EC=A0=80=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...AdminQuestionTypeStatusControllerTest.java | 2 - .../api/QuestionTypeStatusControllerTest.java | 45 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/test/java/mju/iphak/maru_egg/question/api/QuestionTypeStatusControllerTest.java diff --git a/src/test/java/mju/iphak/maru_egg/question/api/AdminQuestionTypeStatusControllerTest.java b/src/test/java/mju/iphak/maru_egg/question/api/AdminQuestionTypeStatusControllerTest.java index 1765328..3c5aabc 100644 --- a/src/test/java/mju/iphak/maru_egg/question/api/AdminQuestionTypeStatusControllerTest.java +++ b/src/test/java/mju/iphak/maru_egg/question/api/AdminQuestionTypeStatusControllerTest.java @@ -7,7 +7,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; @@ -26,7 +25,6 @@ class AdminQuestionTypeStatusControllerTest extends IntegrationTest { @BeforeEach void setUp() { - MockitoAnnotations.openMocks(this); questionTypeStatusService.initializeQuestionTypeStatus(); questionTypeStatusService.deleteQuestionTypeStatus(QuestionType.JEONGSI); } diff --git a/src/test/java/mju/iphak/maru_egg/question/api/QuestionTypeStatusControllerTest.java b/src/test/java/mju/iphak/maru_egg/question/api/QuestionTypeStatusControllerTest.java new file mode 100644 index 0000000..6abeb61 --- /dev/null +++ b/src/test/java/mju/iphak/maru_egg/question/api/QuestionTypeStatusControllerTest.java @@ -0,0 +1,45 @@ +package mju.iphak.maru_egg.question.api; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +import mju.iphak.maru_egg.common.IntegrationTest; +import mju.iphak.maru_egg.question.application.QuestionTypeStatusService; + +class QuestionTypeStatusControllerTest extends IntegrationTest { + + @Autowired + private QuestionTypeStatusService questionTypeStatusService; + + @BeforeEach + void setUp() { + questionTypeStatusService.initializeQuestionTypeStatus(); + } + + @DisplayName("200 전체 질문타입과 상태 조회") + @Test + public void 전체_질문타입과_상태_조회_정상적인_요청() throws Exception { + // given & when + ResultActions resultActions = performGetQuestionTypeStatus(); + + // then + resultActions + .andExpect(status().isOk()) + .andExpect(jsonPath("$").isArray()) + .andExpect(jsonPath("$").isNotEmpty()); + } + + private ResultActions performGetQuestionTypeStatus() throws Exception { + return mvc.perform(get("/api/questions/status") + .contentType(MediaType.APPLICATION_JSON)) + .andDo(print()); + } +} \ No newline at end of file