Skip to content

Commit

Permalink
refactor(tag): popular -> top으로 통일
Browse files Browse the repository at this point in the history
  • Loading branch information
jminkkk committed Dec 30, 2024
1 parent 571cfae commit 8013833
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ResponseEntity<FindAllTagsResponse> getTags(@RequestParam Long memberId)

@GetMapping("/top")
public ResponseEntity<FindAllTagsResponse> getTopTags(@RequestParam(defaultValue = "10") int size) {
FindAllTagsResponse response = tagService.getPopularTags(size);
FindAllTagsResponse response = tagService.getTopTags(size);
return ResponseEntity.ok(response);
}
}
6 changes: 3 additions & 3 deletions backend/src/main/java/codezap/tag/service/TagService.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ private FindAllTagsResponse createFindAllTagsResponse(List<Tag> tags) {
.collect(Collectors.collectingAndThen(Collectors.toList(), FindAllTagsResponse::new));
}

public FindAllTagsResponse getPopularTags(int size) {
public FindAllTagsResponse getTopTags(int size) {
LocalDate startDate = LocalDate.now();
List<Tag> tags = findPopularTags(size, startDate);
List<Tag> tags = findTopTags(size, startDate);
return createFindAllTagsResponse(tags);
}

private List<Tag> findPopularTags(int size, LocalDate startDate) {
private List<Tag> findTopTags(int size, LocalDate startDate) {
List<Tag> tags = tagRepository.findMostUsedTagsWithinDateRange(size, startDate.minusDays(7));

if (tags.size() >= size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void getTopTags() throws Exception {
FindTagResponse.from(new Tag(2L, "tag2"))
));

when(tagService.getPopularTags(anyInt())).thenReturn(findAllTagsResponse);
when(tagService.getTopTags(anyInt())).thenReturn(findAllTagsResponse);

// when & then
mvc.perform(get("/tags/top"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void findAllByNamesSuccess() {

@Nested
@DisplayName("특정 날짜 이후 템플릿 태그가 가장 많이 생성된 태그 목록을 최신순으로 조회")
class FindPopularTagsWithinDateRange {
class FindMostUsedTagsWithinDateRange {

@Test
@DisplayName("성공")
Expand Down Expand Up @@ -184,11 +184,11 @@ void findMostUsedTagsWithinDateRangeWhenNoTags() {

@Nested
@DisplayName("템플릿 태그가 가장 많이 생성된 태그 목록을 최신순으로 조회")
class FindMostUsedTagsWithinDateRange {
class FindMostUsedTagsByRecentTemplates {

@Test
@DisplayName("성공")
void findMostUsedTagsWithinDateRange() {
void findMostUsedTagsByRecentTemplates() {
// Given
Member member1 = memberRepository.save(MemberFixture.getFirstMember());
Category category1 = categoryRepository.save(CategoryFixture.getFirstCategory());
Expand Down
12 changes: 6 additions & 6 deletions backend/src/test/java/codezap/tag/service/TagServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ void findAllByTemplates_WhenNotExist() {

@Nested
@DisplayName("최근 일주일 내 템플릿이 가장 많이 생성된 태그 목록 조회")
class GetPopularTags {
class GetTopTags {

@Test
@DisplayName("성공")
void getPopularTags() {
void getTopTags() {
// given
var member = memberRepository.save(MemberFixture.getFirstMember());
var category = categoryRepository.save(Category.createDefaultCategory(member));
Expand All @@ -368,7 +368,7 @@ void getPopularTags() {
templateTagRepository.save(new TemplateTag(template2, tag3));

// when
var actual = sut.getPopularTags(2);
var actual = sut.getTopTags(2);

// then
assertAll(
Expand All @@ -378,15 +378,15 @@ void getPopularTags() {
}

@Test
@Sql(scripts = "classpath:popular-tags.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "classpath:top-tags.sql", executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
@DisplayName("성공: 최근 일주일 내 태그 목록이 지정된 갯수보다 적은 경우 갯수를 만족할만큼 날짜를 늘려 조회한 후 반환")
void getPopularTagsWhen() {
void getTopTagsWhen() {
// given
var tag1 = tagRepository.findByName("lastTag1");
var tag2 = tagRepository.findByName("lastTag2");

// when
var actual = sut.getPopularTags(2);
var actual = sut.getTopTags(2);

// then
assertThat(actual.tags()).containsExactly(FindTagResponse.from(tag1.get()), FindTagResponse.from(tag2.get()));
Expand Down
File renamed without changes.

0 comments on commit 8013833

Please sign in to comment.