-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardService.java
More file actions
26 lines (26 loc) · 972 Bytes
/
Copy pathBoardService.java
File metadata and controls
26 lines (26 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.*;
public class BoardService {
private List<Board> boards = new ArrayList<>();
public List<Board> findAll() { return boards; }
public Board findById(int id) {
return boards.stream()
.filter(b -> b.getId() == id)
.findFirst().orElse(null);
}
}
// feature/B: 삭제 기능 추가
public boolean delete(int id) {
Board board = findById(id);
if (board == null)
throw new IllegalArgumentException("게시글을 찾을 수 없습니다. ID: " + id);
return boards.remove(board);
}
// 수정 기능 추가
public Board update(int id, String newTitle, String newContent) {
Board board = findById(id);
if (board == null)
throw new IllegalArgumentException("게시글을 찾을 수 없습니다. ID: " + id);
board.setTitle(newTitle);
board.setContent(newContent);
return board;
}