From 799b10375a58f7c82a6bc26516996bfc41d7d4d7 Mon Sep 17 00:00:00 2001 From: le2sky Date: Fri, 16 Aug 2024 12:13:55 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=ED=95=B4=EC=8B=9C=ED=83=9C?= =?UTF-8?q?=EA=B7=B8=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20api=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/develup/api/HashTagApi.java | 28 ++++++++++++++ .../application/hashtag/HashTagService.java | 21 +++++++++++ .../test/java/develup/api/ApiTestSupport.java | 6 ++- .../test/java/develup/api/HashTagApiTest.java | 37 +++++++++++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 backend/src/main/java/develup/api/HashTagApi.java create mode 100644 backend/src/main/java/develup/application/hashtag/HashTagService.java create mode 100644 backend/src/test/java/develup/api/HashTagApiTest.java diff --git a/backend/src/main/java/develup/api/HashTagApi.java b/backend/src/main/java/develup/api/HashTagApi.java new file mode 100644 index 00000000..17bae5f0 --- /dev/null +++ b/backend/src/main/java/develup/api/HashTagApi.java @@ -0,0 +1,28 @@ +package develup.api; + +import java.util.List; +import develup.api.common.ApiResponse; +import develup.application.hashtag.HashTagResponse; +import develup.application.hashtag.HashTagService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Tag(name = "해시태그 API") +class HashTagApi { + + private final HashTagService hashTagService; + + public HashTagApi(HashTagService hashTagService) { + this.hashTagService = hashTagService; + } + + @GetMapping("/hash-tags") + @Operation(summary = "해시태그 목록 조회 API", description = "해시태그 목록을 조회합니다.") + public ResponseEntity>> getHashTags() { + return ResponseEntity.ok(new ApiResponse<>(hashTagService.getHashTags())); + } +} diff --git a/backend/src/main/java/develup/application/hashtag/HashTagService.java b/backend/src/main/java/develup/application/hashtag/HashTagService.java new file mode 100644 index 00000000..22764c76 --- /dev/null +++ b/backend/src/main/java/develup/application/hashtag/HashTagService.java @@ -0,0 +1,21 @@ +package develup.application.hashtag; + +import java.util.List; +import develup.domain.hashtag.HashTagRepository; +import org.springframework.stereotype.Service; + +@Service +public class HashTagService { + + private final HashTagRepository hashTagRepository; + + public HashTagService(HashTagRepository hashTagRepository) { + this.hashTagRepository = hashTagRepository; + } + + public List getHashTags() { + return hashTagRepository.findAll().stream() + .map(HashTagResponse::from) + .toList(); + } +} diff --git a/backend/src/test/java/develup/api/ApiTestSupport.java b/backend/src/test/java/develup/api/ApiTestSupport.java index 86441786..b09e9a9d 100644 --- a/backend/src/test/java/develup/api/ApiTestSupport.java +++ b/backend/src/test/java/develup/api/ApiTestSupport.java @@ -4,6 +4,7 @@ import develup.api.auth.AuthArgumentResolver; import develup.api.auth.CookieAuthorizationExtractor; import develup.application.auth.AuthService; +import develup.application.hashtag.HashTagService; import develup.application.member.MemberService; import develup.application.mission.MissionService; import develup.application.solution.SolutionService; @@ -38,8 +39,11 @@ public class ApiTestSupport { protected SolutionCommentService solutionCommentService; @MockBean - protected CookieAuthorizationExtractor cookieAuthorizationExtractor; + protected HashTagService hashTagService; @MockBean protected AuthArgumentResolver argumentResolver; + + @MockBean + protected CookieAuthorizationExtractor cookieAuthorizationExtractor; } diff --git a/backend/src/test/java/develup/api/HashTagApiTest.java b/backend/src/test/java/develup/api/HashTagApiTest.java new file mode 100644 index 00000000..2d377b13 --- /dev/null +++ b/backend/src/test/java/develup/api/HashTagApiTest.java @@ -0,0 +1,37 @@ +package develup.api; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.List; +import develup.application.hashtag.HashTagResponse; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.BDDMockito; + +class HashTagApiTest extends ApiTestSupport { + + @Test + @DisplayName("해시 태그 목록을 조회한다.") + void getHashTags() throws Exception { + List responses = List.of( + new HashTagResponse(1L, "JAVA"), + new HashTagResponse(2L, "JAVASCRIPT") + ); + BDDMockito.given(hashTagService.getHashTags()) + .willReturn(responses); + + mockMvc.perform(get("/hash-tags")) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.data[0].id", is(1))) + .andExpect(jsonPath("$.data[0].name", equalTo("JAVA"))) + .andExpect(jsonPath("$.data[1].id", is(2))) + .andExpect(jsonPath("$.data[1].name", equalTo("JAVASCRIPT"))) + .andExpect(jsonPath("$.data.length()", is(2))); + } +} From 64c85bba4abb592176048b323ef23619e9f390e9 Mon Sep 17 00:00:00 2001 From: le2sky Date: Fri, 16 Aug 2024 12:14:53 +0900 Subject: [PATCH 2/3] =?UTF-8?q?style:=20import=EB=AC=B8=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/develup/api/SolutionCommentApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/develup/api/SolutionCommentApi.java b/backend/src/main/java/develup/api/SolutionCommentApi.java index 837e378e..500c4931 100644 --- a/backend/src/main/java/develup/api/SolutionCommentApi.java +++ b/backend/src/main/java/develup/api/SolutionCommentApi.java @@ -6,9 +6,9 @@ import develup.api.common.ApiResponse; import develup.application.auth.Accessor; import develup.application.solution.comment.CreateSolutionCommentResponse; +import develup.application.solution.comment.SolutionCommentRepliesResponse; import develup.application.solution.comment.SolutionCommentRequest; import develup.application.solution.comment.SolutionCommentService; -import develup.application.solution.comment.SolutionCommentRepliesResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; From c4b5bde7044b0599edb5380046f57f9db2a735b5 Mon Sep 17 00:00:00 2001 From: le2sky Date: Fri, 16 Aug 2024 13:51:34 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=20=EB=B3=80=EC=88=98=20=ED=95=A0=EB=8B=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/java/develup/api/HashTagApi.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/develup/api/HashTagApi.java b/backend/src/main/java/develup/api/HashTagApi.java index 17bae5f0..8d48db3b 100644 --- a/backend/src/main/java/develup/api/HashTagApi.java +++ b/backend/src/main/java/develup/api/HashTagApi.java @@ -23,6 +23,8 @@ public HashTagApi(HashTagService hashTagService) { @GetMapping("/hash-tags") @Operation(summary = "해시태그 목록 조회 API", description = "해시태그 목록을 조회합니다.") public ResponseEntity>> getHashTags() { - return ResponseEntity.ok(new ApiResponse<>(hashTagService.getHashTags())); + List responses = hashTagService.getHashTags(); + + return ResponseEntity.ok(new ApiResponse<>(responses)); } }