Skip to content

Commit

Permalink
#9 #70 feat: 모든 카테코리 별 보드 리스트 조회(findBoardsByCategories)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaktmchl committed Nov 27, 2022
1 parent b453d5c commit 4c37199
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ public ApplicationResponse<List<GetAllBoardRes>> findAllBoardsByCategory(@Reques
}


/**
* 게시글 모든 카테코리 별 리스트 모음 조회
* @author 토마스
*/
@ApiOperation(value = "게시글 모든 카테코리 별 리스트 모음 조회", notes = "그룹 게시글 모든 카테코리 별 리스트 모음 조회")
@ApiResponses({
@ApiResponse(code= 201, message = "요청에 성공하였습니다."),
@ApiResponse(code= 404, message = "존재하지 않는 유저입니다."),
@ApiResponse(code = 4000 , message = "서버 오류입니다.")
})
@PostMapping("/get/categories")
public ApplicationResponse<List<List<GetAllBoardRes>>> findBoardsByCategories(@RequestBody @Validated GetBoardsByCategories dto){
return boardService.findBoardsByCategories(dto);
}


/**
* 게시글 상세 조회
* @author 토마스
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.yogit.server.board.dto.request;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class GetBoardsByCategories {

@ApiModelProperty(example = "1")
@ApiParam(value = "유저 ID", required = true)
private Long userId;

@ApiModelProperty(example = "1")
@ApiParam(value = "페이징 조회 페이지", required = true)
private int cursor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface BoardService {

ApplicationResponse<List<GetAllBoardRes>> findAllBoardsByCategory(GetAllBoardsByCategoryReq getAllBoardsByCategoryReq);

ApplicationResponse<List<List<GetAllBoardRes>>> findBoardsByCategories(GetBoardsByCategories getBoardsByCategories);

ApplicationResponse<BoardRes> findBoard(GetBoardReq getBoardReq);

ApplicationResponse<DeleteBoardImageRes> deleteBoardImage(DeleteBoardImageReq deleteBoardImageReq);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,45 @@ public ApplicationResponse<List<GetAllBoardRes>> findAllBoardsByCategory(GetAllB
Slice<Board> boards = boardRepository.findAllBoardsByCategory(pageRequest, dto.getCategoryId());
// 보드 res에 이미지uuid -> aws s3 url로 변환
List<GetAllBoardRes> boardsRes = boards.stream()
.map(board -> GetAllBoardRes.toDto(board, awsS3Service.makeUrlOfFilename(awsS3Service.makeUrlOfFilename(board.getBoardImagesUUids().get(0))), awsS3Service.makeUrlOfFilename(user.getProfileImg())))
.map(board -> GetAllBoardRes.toDto(board, awsS3Service.makeUrlOfFilename(board.getBoardImagesUUids().get(0)), awsS3Service.makeUrlOfFilename(user.getProfileImg())))
.collect(Collectors.toList());
return ApplicationResponse.ok(boardsRes);
}

@Transactional(readOnly = true)
@Override
public ApplicationResponse<List<List<GetAllBoardRes>>> findBoardsByCategories(GetBoardsByCategories dto) {
int cursor = dto.getCursor();
List<List<GetAllBoardRes>> boardsByCategories = new ArrayList<>();

User user = userRepository.findById(dto.getUserId())
.orElseThrow(() -> new NotFoundUserException());

List<Category> categories = categoryRepository.findAllCategories();
if(categories.isEmpty()){
System.out.println("카테고리가 없습니다.");
}

// jpa 다중 정렬 order
Sort sort = Sort.by(
Sort.Order.desc("currentMember"),
Sort.Order.asc("date")
);
PageRequest pageRequest = PageRequest.of(cursor, PAGING_SIZE, sort);

// 카테고리 별 리스트 반복문 조회
for(Category category: categories){
Slice<Board> boards = boardRepository.findAllBoardsByCategory(pageRequest, category.getId());
// 보드 res에 이미지uuid -> aws s3 url로 변환
List<GetAllBoardRes> boardsRes = boards.stream()
.map(board -> GetAllBoardRes.toDto(board, awsS3Service.makeUrlOfFilename(board.getBoardImagesUUids().get(0)), awsS3Service.makeUrlOfFilename(user.getProfileImg())))
.collect(Collectors.toList());

boardsByCategories.add(boardsRes);
}

return ApplicationResponse.ok(boardsByCategories);
}

@Transactional(readOnly = true)
@Override
Expand Down

0 comments on commit 4c37199

Please sign in to comment.