Skip to content

Commit ba3f369

Browse files
committed
ChwitKey#117 refactor : article search paging 리팩토링
1 parent 538c48c commit ba3f369

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/main/java/com/example/cherrypickserver/article/dto/assembler/ArticleAssembler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public class ArticleAssembler {
2121

2222
public Pageable setSortType(Pageable pageable, String sortType) {
2323
SortType type = SortType.getSortTypeByName(sortType);
24-
if(type == SortType.ASC) pageable = PageRequest.of(0, pageable.getPageSize(), Sort.by("uploadedAt").ascending());
25-
else if(type == SortType.DESC) pageable = PageRequest.of(0, pageable.getPageSize(), Sort.by("uploadedAt").descending());
26-
else if(type == SortType.LIKE) pageable = PageRequest.of(0, pageable.getPageSize(), Sort.by("likeCount").descending());
24+
if(type == SortType.ASC) pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("uploadedAt").ascending());
25+
else if(type == SortType.DESC) pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("uploadedAt").descending());
26+
else if(type == SortType.LIKE) pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("likeCount").descending());
2727
else pageable = PageRequest.of(0, pageable.getPageSize());
2828
return pageable;
2929
}

src/main/java/com/example/cherrypickserver/article/presentation/ArticleController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import lombok.RequiredArgsConstructor;
1717
import org.springframework.data.domain.Page;
1818
import org.springframework.data.domain.Pageable;
19+
import org.springframework.data.web.PageableDefault;
1920
import org.springframework.web.bind.annotation.*;
2021

2122
import java.util.List;
@@ -55,7 +56,7 @@ public ResponseCustom<DetailArticleRes> detailArticle(
5556
public ResponseCustom<Page<SearchArticleRes>> searchArticle(
5657
@Parameter(description = "검색어") @RequestParam String cond,
5758
@Parameter(description = "ASC(오름차순), DESC(내림차순), LIKE(인기순)")@RequestParam String sortType,
58-
Pageable pageable
59+
@PageableDefault(size = 10) Pageable pageable
5960
)
6061
{
6162
return ResponseCustom.OK(articleService.searchArticle(cond, sortType, pageable));
@@ -73,7 +74,7 @@ public ResponseCustom<Page<SearchArticleRes>> searchArticleByKeyword(
7374
@Parameter(description = "멤버 id") @IsLogin LoginStatus loginStatus,
7475
@Parameter(description = "ASC(오름차순), DESC(내림차순), LIKE(인기순)") @RequestParam String sortType,
7576
@Parameter(description = "멤버가 등록한 키워드") @RequestParam String keyword,
76-
Pageable pageable
77+
@PageableDefault(size = 10) Pageable pageable
7778
)
7879
{
7980
return ResponseCustom.OK(articleService.searchArticleByKeyword(loginStatus.getMemberId(), keyword, sortType, pageable));
@@ -91,7 +92,7 @@ public ResponseCustom<Page<SearchArticleRes>> searchArticleByIndustry(
9192
@Parameter(description = "멤버 id") @IsLogin LoginStatus loginStatus,
9293
@Parameter(description = "ASC(오름차순), DESC(내림차순), LIKE(인기순)") @RequestParam String sortType,
9394
@Parameter(description = "멤버가 등록한 직군") @RequestParam String industry,
94-
Pageable pageable
95+
@PageableDefault(size = 10) Pageable pageable
9596
)
9697
{
9798
return ResponseCustom.OK(articleService.searchArticleByIndustry(loginStatus.getMemberId(), industry, sortType, pageable));

0 commit comments

Comments
 (0)