Skip to content

Commit

Permalink
Merge pull request #149 from YogitTeam/feat/report
Browse files Browse the repository at this point in the history
#9 fix: 보드 카테고리1개별 조회-res에 totalPage 필드 추가
  • Loading branch information
xhaktmchl authored Mar 15, 2023
2 parents cf5c963 + 260f2c1 commit 06c331e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class BlockServiceImpl implements BlockService{
private final BlockRepository blockRepository;
private final UserRepository userRepository;
private final BoardRepository boardRepository;
private final BoardUserRepository boardUserRepository;
private final TokenService tokenService;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public ApplicationResponse<List<List<GetAllBoardRes>>> findBoardsByCategories(@R
@ApiResponse(code = 4000 , message = "서버 오류입니다.")
})
@PostMapping("/get/myclub")
public ApplicationResponse<List<GetAllBoardRes>> findMyClubBoards(@RequestBody @Validated GetMyClubBoardsReq dto){
public ApplicationResponse<GetAllBoardsByCategoryRes> findMyClubBoards(@RequestBody @Validated GetMyClubBoardsReq dto){
return boardService.findMyClubBoards(dto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface BoardRepository extends JpaRepository<Board, Long> {
Page<Board> findAllBoardsByCategory(Pageable pageable, @Param("categoryId") Long categoryId);

@Query("select b from Board b where b.status = 'ACTIVE' and b.host.id = :userId")
Slice<Board> findMyClubBoardsByUserId(Pageable pageable, @Param("userId") Long userId);
Page<Board> findMyClubBoardsByUserId(Pageable pageable, @Param("userId") Long userId);

@Query("select b from Board b where b.status = 'ACTIVE' and b.host.id = :userId")
List<Board> findBoardsByUserId(@Param("userId") Long userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.yogit.server.board.repository;

import com.yogit.server.board.entity.BoardUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -17,7 +20,7 @@ public interface BoardUserRepository extends JpaRepository<BoardUser, Long> {
Optional<BoardUser> findByUserIdAndBoardId(@Param("userId") Long userId, @Param("boardId") Long boardId);

@Query("select bu from BoardUser bu where bu.status = 'ACTIVE' and bu.user.id = :userId")
Slice<BoardUser> findByUserId(@Param("userId") Long userId);
Page<BoardUser> findByUserId(Pageable pageable, @Param("userId") Long userId);

@Query("select bu from BoardUser bu where bu.status = 'ACTIVE' and bu.board.id = :boardId")
List<BoardUser> findAllByBoardId(@Param("boardId") Long boardId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface BoardService {

ApplicationResponse<List<List<GetAllBoardRes>>> findBoardsByCategories(GetBoardsByCategoriesReq getBoardsByCategoriesReq);

ApplicationResponse<List<GetAllBoardRes>> findMyClubBoards(GetMyClubBoardsReq getMyClubBoardsReq);
ApplicationResponse<GetAllBoardsByCategoryRes> findMyClubBoards(GetMyClubBoardsReq getMyClubBoardsReq);

ApplicationResponse<GetBoardRes> findBoard(GetBoardReq getBoardReq);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public ApplicationResponse<List<List<GetAllBoardRes>>> findAllBoards(GetAllBoard

@Transactional(readOnly = true)
@Override
public ApplicationResponse<List<GetAllBoardRes>> findMyClubBoards(GetMyClubBoardsReq dto){
public ApplicationResponse<GetAllBoardsByCategoryRes> findMyClubBoards(GetMyClubBoardsReq dto){

tokenService.validateRefreshToken(dto.getUserId(), dto.getRefreshToken());

Expand All @@ -260,8 +260,8 @@ public ApplicationResponse<List<GetAllBoardRes>> findMyClubBoards(GetMyClubBoard
);
PageRequest pageRequest = PageRequest.of(cursor, PAGING_SIZE, sort);

Slice<Board> boards = null;
Slice<BoardUser> boardUsers = null;
Page<Board> boards = null;
Page<BoardUser> boardUsers = null;
List<GetAllBoardRes> res = null;
/*
1.생성한 보드: Opened Club
Expand All @@ -278,7 +278,7 @@ public ApplicationResponse<List<GetAllBoardRes>> findMyClubBoards(GetMyClubBoard
}
}
else if(dto.getMyClubType().equals(MyClubType.APPLIED_CLUB.toString())){
boardUsers = boardUserRepository.findByUserId(dto.getUserId());
boardUsers = boardUserRepository.findByUserId(pageRequest, dto.getUserId());
// System.out.println("보드 유저는?: "+ boardUsers);

// 보드 res에 이미지uuid -> aws s3 url로 변환
Expand All @@ -291,7 +291,12 @@ else if(dto.getMyClubType().equals(MyClubType.APPLIED_CLUB.toString())){
}
else{ throw new InvalidMyClubTypeException();}

return ApplicationResponse.ok(res);
if(dto.getMyClubType().equals(MyClubType.OPENED_CLUB.toString())){
return ApplicationResponse.ok(GetAllBoardsByCategoryRes.toDto(res, boards.getTotalPages()));
}
else {
return ApplicationResponse.ok(GetAllBoardsByCategoryRes.toDto(res, boardUsers.getTotalPages()));
}
}


Expand Down

0 comments on commit 06c331e

Please sign in to comment.