-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBookController.java
More file actions
43 lines (35 loc) · 1.16 KB
/
Copy pathBookController.java
File metadata and controls
43 lines (35 loc) · 1.16 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
package org.example.controller;
import lombok.RequiredArgsConstructor;
import org.example.dto.BookDto;
import org.example.dto.CreateBookRequestDto;
import org.example.service.BookService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/books")
public class BookController {
private final BookService bookService;
@GetMapping
public List<BookDto> getAll() {
return bookService.findAll();
}
@GetMapping("/{id}")
public BookDto getBookById(@PathVariable Long id) {
return bookService.findById(id);
}
@PostMapping
public BookDto createBook(@RequestBody CreateBookRequestDto createBookRequestDto) {
return bookService.save(createBookRequestDto);
}
@ResponseStatus(HttpStatus.NO_CONTENT)
@DeleteMapping("/{id}")
public void deleteBookById(@PathVariable Long id) {
bookService.deleteById(id);
}
@PutMapping("/{id}")
public void updateBookById(@PathVariable Long id, @RequestBody BookDto bookDto) {
bookService.updateBookById(id, bookDto);
}
}