Skip to content

Commit

Permalink
feat: 목록 인원 가득 찬거 맨 아래로 - #81
Browse files Browse the repository at this point in the history
Feature/#81 목록 인원 가득 찬거 맨 아래로
  • Loading branch information
aaahyunseo authored Aug 19, 2024
2 parents b5c3dfb + 83b93a7 commit 81c26fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

public interface ChattingRoomRepository extends JpaRepository<ChattingRoom, UUID> {
Optional<ChattingRoom> deleteByBoard(Board board);
Optional<ChattingRoom> findByBoard(Board board);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import com.example.swcompetitionproject.exception.NotFoundException;
import com.example.swcompetitionproject.exception.UnauthorizedException;
import com.example.swcompetitionproject.repository.BoardRepository;
import com.example.swcompetitionproject.repository.ChattingRoomRepository;
import com.example.swcompetitionproject.repository.InterestRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
Expand All @@ -25,15 +27,36 @@ public class BoardService {
private final BoardRepository boardRepository;
private final ChattingService chattingService;
private final InterestRepository interestRepository;
private final ChattingRoomRepository chattingRoomRepository;

/**
* 게시글 전체 조회
**/
@Transactional
public BoardListData getBoardList(User user, String dormitory) {
DormitoryType dormitoryType = dormitoryNameValidate(dormitory);
//해당 건물에 대한 모든 게시물
List<Board> boards = boardRepository.findAllByDormitoryOrderByCreatedAtDesc(dormitoryType);
return BoardListData.of(boards, user, interestRepository);

// 가득 찬 게시물과 그렇지 않은 게시물을 저장할 리스트
List<Board> fullBoards = new LinkedList<>();
List<Board> notFullBoards = new LinkedList<>();

// 반복문을 사용해 게시물을 분류
for (Board board : boards) {
if (board.getTotal() == chattingRoomRepository.findByBoard(board).get().getMemberCount()) {
fullBoards.add(board); // 가득 찬 게시물
} else {
notFullBoards.add(board); // 인원 미달 게시물
}
}

// 가득 찬 게시물 리스트와 인원 미달 게시물 리스트를 합침
List<Board> resultBoards = new LinkedList<>();
resultBoards.addAll(notFullBoards);
resultBoards.addAll(fullBoards);

return BoardListData.of(resultBoards, user, interestRepository);
}

/**
Expand Down

0 comments on commit 81c26fc

Please sign in to comment.