Skip to content

Commit d048217

Browse files
committed
feat: adds endpoints for create and read operations
1 parent 267b814 commit d048217

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
package ao.com.academy.libraryapi.controllers;
22

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;
311
import org.springframework.web.bind.annotation.RequestMapping;
412
import org.springframework.web.bind.annotation.RestController;
513

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+
618

719
@RestController
820
@RequestMapping
921
public class LibraryController {
1022

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+
1144
}

0 commit comments

Comments
 (0)