File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
src/main/java/ao/com/academy/libraryapi/controllers Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1
1
package ao .com .academy .libraryapi .controllers ;
2
2
3
+ import java .util .List ;
4
+
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .http .ResponseEntity ;
7
+ import org .springframework .web .bind .annotation .GetMapping ;
8
+ import org .springframework .web .bind .annotation .PathVariable ;
9
+ import org .springframework .web .bind .annotation .PostMapping ;
10
+ import org .springframework .web .bind .annotation .RequestBody ;
3
11
import org .springframework .web .bind .annotation .RequestMapping ;
4
12
import org .springframework .web .bind .annotation .RestController ;
5
13
14
+ import ao .com .academy .libraryapi .bookdto .BookDTO ;
15
+ import ao .com .academy .libraryapi .exceptions .BookNotFoundException ;
16
+ import ao .com .academy .libraryapi .services .BookService ;
17
+
6
18
7
19
@ RestController
8
20
@ RequestMapping
9
21
public class LibraryController {
10
22
23
+ @ Autowired
24
+ BookService bookService ;
25
+
26
+ // Get all books
27
+ @ GetMapping ("/library/books" )
28
+ public List <BookDTO > getAllBooks (){
29
+ return bookService .getBooks ();
30
+ }
31
+
32
+ // Find book by Id
33
+ @ GetMapping ("/library/books/{id}" )
34
+ public BookDTO getBookById (@ PathVariable (name ="id" ) Long bookId ) throws BookNotFoundException {
35
+ return bookService .getBookById (bookId );
36
+ }
37
+
38
+ // Create Book
39
+ @ PostMapping ("/library/books/new" )
40
+ public ResponseEntity <?> createBook (@ RequestBody BookDTO book ){
41
+ return bookService .createBook (book );
42
+ }
43
+
11
44
}
You can’t perform that action at this time.
0 commit comments