Skip to content

Commit

Permalink
Merge pull request #46 from DEPthes/develop
Browse files Browse the repository at this point in the history
[DEPLOY]
  • Loading branch information
jisujeong0 authored Aug 17, 2024
2 parents e31b088 + 071cf46 commit e0d4f12
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ResponseEntity<?> hitTheThemeLikeButton(@CurrentUser CustomUserDetails cu
public ResponseEntity<?> getThemeList(
@CurrentUser CustomUserDetails customUserDetails,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "3") int size,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "date") String sortBy) {
Pageable pageable = PageRequest.of(page - 1, size);
return themeService.getThemeList(customUserDetails, pageable, sortBy);
Expand All @@ -39,7 +39,7 @@ public ResponseEntity<?> searchTheme(
@CurrentUser CustomUserDetails customUserDetails,
@RequestParam String keyword,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "3") int size){
@RequestParam(defaultValue = "5") int size){
Pageable pageable = PageRequest.of(page - 1, size);
return themeService.searchTheme(customUserDetails, keyword, pageable);
}
Expand All @@ -50,7 +50,7 @@ public ResponseEntity<?> getThemeDetail(
@CurrentUser CustomUserDetails customUserDetails,
@PathVariable Long themeId,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "2") int size,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "date") String sortBy) {
Pageable pageable = PageRequest.of(page - 1, size);
return themeService.getThemeDetail(themeId, sortBy, pageable, customUserDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,21 @@ public ResponseEntity<?> getUserInfoByNickname(
public ResponseEntity<?> findMyBoards(
@CurrentUser CustomUserDetails customUserDetails,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "false") boolean filterDrafts,
@RequestParam(defaultValue = "date") String sortBy) { // date, like
return userLikeService.getMyBoards(customUserDetails, page, filterDrafts, sortBy);
return userLikeService.getMyBoards(customUserDetails, page, size, filterDrafts, sortBy);
}

@GetMapping("/board/search")
public ResponseEntity<?> searchMyBoards(
@CurrentUser CustomUserDetails customUserDetails,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "false") boolean filterDrafts,
@RequestParam String keyword,
@RequestParam(defaultValue = "date") String sortBy) {
return userLikeService.searchMyBoards(customUserDetails, page, keyword, filterDrafts, sortBy);
return userLikeService.searchMyBoards(customUserDetails, page, size, keyword, filterDrafts, sortBy);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,37 @@ public class UserLikeController {
public ResponseEntity<?> findLikedBoardsByUser(
@CurrentUser CustomUserDetails customUserDetails,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "currentLike") String sortBy) { // date, like, currentLike
return userLikeService.getLikedBoardsByUser(customUserDetails, page, sortBy);
return userLikeService.getLikedBoardsByUser(customUserDetails, page, size, sortBy);
}

@GetMapping("/board/search")
public ResponseEntity<?> searchLikedBoardsByUser(
@CurrentUser CustomUserDetails customUserDetails,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "5") int size,
@RequestParam String keyword,
@RequestParam(defaultValue = "currentLike") String sortBy) {
return userLikeService.searchLikedBoardsByUser(customUserDetails, page, keyword, sortBy);
return userLikeService.searchLikedBoardsByUser(customUserDetails, page, size, keyword, sortBy);
}

@GetMapping("/theme")
public ResponseEntity<?> findLikedThemesByUser(
@CurrentUser CustomUserDetails customUserDetails,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "5") int size,
@RequestParam(defaultValue = "currentLike") String sortBy) { // date, like, currentLike, board
return userLikeService.getLikedThemesByUser(customUserDetails, page, sortBy);
return userLikeService.getLikedThemesByUser(customUserDetails, page, size, sortBy);
}

@GetMapping("/theme/search")
public ResponseEntity<?> searchLikedThemesByUser(
@CurrentUser CustomUserDetails customUserDetails,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "5") int size,
@RequestParam String keyword,
@RequestParam(defaultValue = "currentLike") String sortBy) {
return userLikeService.searchLikedThemesByUser(customUserDetails, page, keyword, sortBy);
return userLikeService.searchLikedThemesByUser(customUserDetails, page, size, keyword, sortBy);
}
}
60 changes: 30 additions & 30 deletions src/main/java/depth/mvp/ns/domain/user/service/UserLikeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class UserLikeService {

// Description: 좋아요를 누른 게시글
// 좋아요 누른 글 조회 + 정렬
public ResponseEntity<?> getLikedBoardsByUser(CustomUserDetails customUserDetails, int page, String sortBy) {
public ResponseEntity<?> getLikedBoardsByUser(CustomUserDetails customUserDetails, int page, int size, String sortBy) {
User user = validUserById(customUserDetails.getId());

List<BoardLikeByUserRes> boardLikeByUserResList;
Expand All @@ -57,13 +57,13 @@ public ResponseEntity<?> getLikedBoardsByUser(CustomUserDetails customUserDetail
// date, like 정렬 적용
sortBoardLikes(boardLikeByUserResList, sortBy);
// 페이징 적용
boardLikeByUserResList = applyPagination(boardLikeByUserResList, page, 3);
boardLikeByUserResList = applyPagination(boardLikeByUserResList, page, size);
} else {
// currentLike 기준 정렬 및 페이징
boardLikeByUserResList = sortBoardByCurrentLike(user, page, null);
boardLikeByUserResList = sortBoardByCurrentLike(user, page, size, null);
}

PageInfo pageInfo = createPageInfo(allBoardLikes.size(), page, 3);
PageInfo pageInfo = createPageInfo(allBoardLikes.size(), page, size);
PageRes<BoardLikeByUserRes> pageBoardLikeRes = PageRes.<BoardLikeByUserRes>builder()
.pageInfo(pageInfo)
.resList(boardLikeByUserResList)
Expand Down Expand Up @@ -104,8 +104,8 @@ private void sortBoardLikes(List<BoardLikeByUserRes> boardLikeByUserResList, Str
}

// currentLike 기준으로 정렬 및 페이징
private List<BoardLikeByUserRes> sortBoardByCurrentLike(User user, int page, String keyword) {
Pageable pageable = PageRequest.of(page - 1, 3, Sort.by(Sort.Direction.DESC, "createdDate"));
private List<BoardLikeByUserRes> sortBoardByCurrentLike(User user, int page, int size, String keyword) {
Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdDate"));
Page<BoardLike> boardLikePage;
// 조회, 검색 동일한 메소드 사용하므로 keyword 유무로 구분
if (keyword == null) {
Expand Down Expand Up @@ -149,7 +149,7 @@ private PageInfo createPageInfo(int totalElements, int page, int size) {
}

// 검색
public ResponseEntity<?> searchLikedBoardsByUser(CustomUserDetails customUserDetails, int page, String keyword, String sortBy) {
public ResponseEntity<?> searchLikedBoardsByUser(CustomUserDetails customUserDetails, int page, int size, String keyword, String sortBy) {
User user = validUserById(customUserDetails.getId());
List<BoardLikeByUserRes> boardLikeByUserResList;
List<BoardLike> allBoardLikes = boardLikeRepository.findByUserAndStatusAndBoardFieldsContaining(
Expand All @@ -161,13 +161,13 @@ public ResponseEntity<?> searchLikedBoardsByUser(CustomUserDetails customUserDet
// date, like 정렬 적용
sortBoardLikes(boardLikeByUserResList, sortBy);
// 페이징 적용
boardLikeByUserResList = applyPagination(boardLikeByUserResList, page, 3);
boardLikeByUserResList = applyPagination(boardLikeByUserResList, page, size);
} else {
// currentLike 기준 정렬 및 페이징
boardLikeByUserResList = sortBoardByCurrentLike(user, page, keyword);
boardLikeByUserResList = sortBoardByCurrentLike(user, page, size, keyword);
}

PageInfo pageInfo = createPageInfo(allBoardLikes.size(), page, 3);
PageInfo pageInfo = createPageInfo(allBoardLikes.size(), page, size);
PageRes<BoardLikeByUserRes> pageBoardLikeRes = PageRes.<BoardLikeByUserRes>builder()
.pageInfo(pageInfo)
.resList(boardLikeByUserResList)
Expand All @@ -182,7 +182,7 @@ public ResponseEntity<?> searchLikedBoardsByUser(CustomUserDetails customUserDet

// Description: 좋아요를 누른 주제
// 주제 조회
public ResponseEntity<?> getLikedThemesByUser(CustomUserDetails customUserDetails, int page, String sortBy) {
public ResponseEntity<?> getLikedThemesByUser(CustomUserDetails customUserDetails, int page, int size, String sortBy) {
// date, like, currentLike, board
User user = validUserById(customUserDetails.getId());

Expand All @@ -194,13 +194,13 @@ public ResponseEntity<?> getLikedThemesByUser(CustomUserDetails customUserDetail
// date, like, board 정렬 적용
sortThemeLikes(themeLikeByUserResList, sortBy);
// 페이징 적용
themeLikeByUserResList = applyPagination(themeLikeByUserResList, page, 3);
themeLikeByUserResList = applyPagination(themeLikeByUserResList, page, size);
} else {
// currentLike 기준 정렬 및 페이징
themeLikeByUserResList = sortThemeByCurrentLike(user, page, null);
themeLikeByUserResList = sortThemeByCurrentLike(user, page, size, null);
}

PageInfo pageInfo = createPageInfo(allThemeLikes.size(), page, 3);
PageInfo pageInfo = createPageInfo(allThemeLikes.size(), page, size);
PageRes<ThemeLikeByUserRes> pageThemeLikeRes = PageRes.<ThemeLikeByUserRes>builder()
.pageInfo(pageInfo)
.resList(themeLikeByUserResList)
Expand Down Expand Up @@ -244,8 +244,8 @@ private void sortThemeLikes(List<ThemeLikeByUserRes> themeLikeByUserResList, Str
}

// currentLike 기준으로 정렬 및 페이징
private List<ThemeLikeByUserRes> sortThemeByCurrentLike(User user, int page, String keyword) {
Pageable pageable = PageRequest.of(page - 1, 3, Sort.by(Sort.Direction.DESC, "createdDate"));
private List<ThemeLikeByUserRes> sortThemeByCurrentLike(User user, int page, int size, String keyword) {
Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdDate"));
Page<ThemeLike> themeLikePage;

if (keyword == null) {
Expand All @@ -272,7 +272,7 @@ private List<ThemeLikeByUserRes> sortThemeByCurrentLike(User user, int page, Str
}

// 주제 검색
public ResponseEntity<?> searchLikedThemesByUser(CustomUserDetails customUserDetails, int page, String keyword, String sortBy) {
public ResponseEntity<?> searchLikedThemesByUser(CustomUserDetails customUserDetails, int page, int size, String keyword, String sortBy) {
User user = validUserById(customUserDetails.getId());
List<ThemeLikeByUserRes> themeLikeByUserResList;
List<ThemeLike> allThemeLikes = themeLikeRepository.findByUserAndStatusAndThemeFieldsContaining(
Expand All @@ -284,13 +284,13 @@ public ResponseEntity<?> searchLikedThemesByUser(CustomUserDetails customUserDet
// date, like, board 정렬 적용
sortThemeLikes(themeLikeByUserResList, sortBy);
// 페이징 적용
themeLikeByUserResList = applyPagination(themeLikeByUserResList, page, 3);
themeLikeByUserResList = applyPagination(themeLikeByUserResList, page, size);
} else {
// currentLike 기준 정렬 및 페이징
themeLikeByUserResList = sortThemeByCurrentLike(user, page, keyword);
themeLikeByUserResList = sortThemeByCurrentLike(user, page, size, keyword);
}

PageInfo pageInfo = createPageInfo(allThemeLikes.size(), page, 3);
PageInfo pageInfo = createPageInfo(allThemeLikes.size(), page, size);
PageRes<ThemeLikeByUserRes> pageThemeLikeRes = PageRes.<ThemeLikeByUserRes>builder()
.pageInfo(pageInfo)
.resList(themeLikeByUserResList)
Expand All @@ -304,7 +304,7 @@ public ResponseEntity<?> searchLikedThemesByUser(CustomUserDetails customUserDet
}

// 내 글
public ResponseEntity<?> getMyBoards(CustomUserDetails customUserDetails, int page, boolean filterDrafts, String sortBy) {
public ResponseEntity<?> getMyBoards(CustomUserDetails customUserDetails, int page, int size, boolean filterDrafts, String sortBy) {
// 최신순, 좋아요 순
User user = validUserById(customUserDetails.getId());
// 임시저장 제외 여부에 따라 totalElements 달라짐
Expand All @@ -320,18 +320,18 @@ public ResponseEntity<?> getMyBoards(CustomUserDetails customUserDetails, int pa
List<MyBoardRes> myBoardResList;
switch (sortBy) {
case "date":
myBoardResList = sortByDate(user, page, filterDrafts, null);
myBoardResList = sortByDate(user, page, size, filterDrafts, null);
break;
case "like":
myBoardResList = sortByLike(user, filterDrafts, null);
myBoardResList.sort(Comparator.comparing(MyBoardRes::getCountLike, Comparator.reverseOrder()));
myBoardResList = applyPagination(myBoardResList, page, 3);
myBoardResList = applyPagination(myBoardResList, page, size);
break;
default:
throw new InvalidParameterException("잘못된 요청 파라미터입니다.");
}

PageInfo pageInfo = createPageInfo(allMyBoards.size(), page, 3);
PageInfo pageInfo = createPageInfo(allMyBoards.size(), page, size);
PageRes<MyBoardRes> pageMyBoardRes = PageRes.<MyBoardRes>builder()
.pageInfo(pageInfo)
.resList(myBoardResList)
Expand All @@ -344,7 +344,7 @@ public ResponseEntity<?> getMyBoards(CustomUserDetails customUserDetails, int pa
return ResponseEntity.ok(apiResponse);
}

public ResponseEntity<?> searchMyBoards(CustomUserDetails customUserDetails, int page, String keyword, boolean filterDrafts, String sortBy) {
public ResponseEntity<?> searchMyBoards(CustomUserDetails customUserDetails, int page, int size, String keyword, boolean filterDrafts, String sortBy) {
// 최신순, 좋아요 순
User user = validUserById(customUserDetails.getId());

Expand All @@ -360,18 +360,18 @@ public ResponseEntity<?> searchMyBoards(CustomUserDetails customUserDetails, int
List<MyBoardRes> myBoardResList;
switch (sortBy) {
case "date":
myBoardResList = sortByDate(user, page, filterDrafts, keyword);
myBoardResList = sortByDate(user, page, size, filterDrafts, keyword);
break;
case "like":
myBoardResList = sortByLike(user, filterDrafts, keyword);
myBoardResList.sort(Comparator.comparing(MyBoardRes::getCountLike, Comparator.reverseOrder()));
myBoardResList = applyPagination(myBoardResList, page, 3);
myBoardResList = applyPagination(myBoardResList, page, size);
break;
default:
throw new InvalidParameterException("잘못된 요청 파라미터입니다.");
}

PageInfo pageInfo = createPageInfo(allMyBoards.size(), page, 3);
PageInfo pageInfo = createPageInfo(allMyBoards.size(), page, size);
PageRes<MyBoardRes> pageMyBoardRes = PageRes.<MyBoardRes>builder()
.pageInfo(pageInfo)
.resList(myBoardResList)
Expand Down Expand Up @@ -415,8 +415,8 @@ private List<Board> getFilteredBoards(User user, boolean filterDrafts, String ke
}
}

private List<MyBoardRes> sortByDate(User user, int page, boolean filterDrafts, String keyword) {
Pageable pageable = PageRequest.of(page - 1, 3, Sort.by(Sort.Direction.DESC, "createdDate"));
private List<MyBoardRes> sortByDate(User user, int page, int size, boolean filterDrafts, String keyword) {
Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdDate"));
List<Board> boardList = getFilteredBoards(user, filterDrafts, keyword, pageable);

return boardList.stream()
Expand Down

0 comments on commit e0d4f12

Please sign in to comment.