Skip to content

Commit

Permalink
#9 fix:보드 currentMember 필드값 계산방식 boardusers조회해서하는 방식으로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
xhaktmchl committed Mar 9, 2023
1 parent e72d446 commit 0f249ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ApplicationResponse<BlockRes> createBlock(CreateBlockReq dto){
if(!boardUsers.isEmpty()){
for(BoardUser bu: boardUsers){
if(bu.getUser().getId().equals(blockingUser.getId()) && bu.getStatus().equals(BaseStatus.ACTIVE)){
bu.changeStatusToInactive();
//bu.changeStatusToInactive();
}
}
}
Expand All @@ -83,7 +83,7 @@ public ApplicationResponse<BlockRes> createBlock(CreateBlockReq dto){
if(!boardUsers.isEmpty()){
for(BoardUser bu: boardUsers){
if(bu.getUser().getId().equals(blockedUser.getId()) && bu.getStatus().equals(BaseStatus.ACTIVE)){
bu.changeStatusToInactive();
//bu.changeStatusToInactive();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public interface BoardUserRepository extends JpaRepository<BoardUser, Long> {
@Query("select bu from BoardUser bu where bu.status = 'ACTIVE' and bu.user.id = :userId")
Slice<BoardUser> findByUserId(@Param("userId") Long userId);

List<BoardUser> findAllByBoardId(Long boardId);
@Query("select bu from BoardUser bu where bu.status = 'ACTIVE' and bu.board.id = :boardId")
List<BoardUser> findAllByBoardId(@Param("boardId") Long boardId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public ApplicationResponse<GetBoardRes> createBoard(CreateBoardReq dto){

// 호스트 boardUser 생성 및 board에 추가
board.addBoardUser(new BoardUser(host, board));
board.addCurrentMember();// 보드 현재 인원 +1
//board.addCurrentMember();// 보드 현재 인원 +1


// board 저장
Board savedBoard = boardRepository.save(board);
Expand All @@ -102,7 +103,11 @@ public ApplicationResponse<GetBoardRes> createBoard(CreateBoardReq dto){
}
}

List<User> participants = board.getBoardUsers().stream()
// 보드 현재 인원
List<BoardUser> participantsOrigin = boardUserRepository.findAllByBoardId(board.getId());
board.changeBoardCurrentMember(participantsOrigin.size());

List<User> participants = participantsOrigin.stream()
.map(boardUser -> boardUser.getUser())
.collect(Collectors.toList());

Expand Down Expand Up @@ -373,7 +378,11 @@ public ApplicationResponse<GetBoardRes> findBoard(GetBoardReq dto){
Board board = boardRepository.findBoardById(dto.getBoardId())
.orElseThrow(() -> new NotFoundBoardException());

List<User> participants = board.getBoardUsers().stream()
// 보드 현재 인원
List<BoardUser> participantsOrigin = boardUserRepository.findAllByBoardId(board.getId());
board.changeBoardCurrentMember(participantsOrigin.size());

List<User> participants = participantsOrigin.stream()
.map(boardUser -> boardUser.getUser())
.collect(Collectors.toList());

Expand Down

0 comments on commit 0f249ea

Please sign in to comment.