1 package civitas.bboard.server;
2
3 import java.util.Optional;
4
5 import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.stereotype.Controller;
7
8 @Controller
9 public class GetBoardForId {
10
11 @Autowired
12 BoardRepository boardRepository;
13
14 public Board apply(final String bbid, final boolean mustBeOpen) {
15 Optional<Board> boardp = boardRepository.findById(bbid);
16 if (!boardp.isPresent()) {
17 throw new IllegalArgumentException("no such board is open");
18 }
19 Board board = boardp.get();
20 if (mustBeOpen && !board.isOpen) {
21 throw new IllegalArgumentException("No such board is open");
22 }
23 return board;
24 }
25 }