-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathBoardController.java
More file actions
63 lines (52 loc) · 1.87 KB
/
BoardController.java
File metadata and controls
63 lines (52 loc) · 1.87 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.example.demo.controller;
import java.util.List;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.controller.dto.request.BoardCreateRequest;
import com.example.demo.controller.dto.request.BoardUpdateRequest;
import com.example.demo.controller.dto.response.BoardResponse;
import com.example.demo.service.BoardService;
@RestController
public class BoardController {
private final BoardService boardService;
public BoardController(BoardService boardService) {
this.boardService = boardService;
}
@GetMapping("/boards")
public List<BoardResponse> getBoards() {
return boardService.getBoards();
}
@GetMapping("/boards/{id}")
public BoardResponse getBoard(
@PathVariable Long id
) {
return boardService.getBoardById(id);
}
@PostMapping("/boards")
public BoardResponse createBoard(
@Valid @RequestBody BoardCreateRequest request
) {
return boardService.createBoard(request);
}
@PutMapping("/boards/{id}")
public BoardResponse updateBoard(
@PathVariable Long id,
@RequestBody BoardUpdateRequest updateRequest
) {
return boardService.update(id, updateRequest);
}
@DeleteMapping("/boards/{id}")
public ResponseEntity<Void> deleteBoard(
@PathVariable Long id
) {
boardService.deleteBoard(id);
return ResponseEntity.noContent().build();
}
}