-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
해시태그 목록 조회 기능 구현(issue #307) #308
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ApiResponse<List<HashTagResponse>>> getHashTags() { | ||
return ResponseEntity.ok(new ApiResponse<>(hashTagService.getHashTags())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/develup/application/hashtag/HashTagService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HashTagResponse> getHashTags() { | ||
return hashTagRepository.findAll().stream() | ||
.map(HashTagResponse::from) | ||
.toList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HashTagResponse> 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))); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Request Changes]
분리해주세요!