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..8d48db3b --- /dev/null +++ b/backend/src/main/java/develup/api/HashTagApi.java @@ -0,0 +1,30 @@ +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() { + List responses = hashTagService.getHashTags(); + + return ResponseEntity.ok(new ApiResponse<>(responses)); + } +} 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; 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))); + } +}