bizzcuit

BookRestController

Sep 25th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. package com.rewe.exercise.bookstore.book;
  2.  
  3. import com.rewe.exercise.bookstore.bookRequest.BookRequest;
  4. import org.springframework.http.HttpStatus;
  5. import org.springframework.http.ResponseEntity;
  6. import org.springframework.web.bind.annotation.*;
  7.  
  8. import java.util.List;
  9.  
  10. @RestController
  11. @RequestMapping("/bookstore")
  12. public class BookRestController {
  13.  
  14. private final BookMapper bookMapper;
  15. private final BookService bookService;
  16. private final BookClient bookClient;
  17.  
  18. public BookRestController(BookMapper bookMapper, BookService bookService, BookClient bookClient) {
  19. this.bookMapper = bookMapper;
  20. this.bookService = bookService;
  21. this.bookClient = bookClient;
  22. }
  23.  
  24. @GetMapping("/books")
  25. public List<Book> getAllBooks() {
  26. List<Book> books = bookMapper.map(bookService.getAllBooks());
  27. if (books.size() == 0) {
  28. System.out.println("No books available");
  29. }
  30. return books;
  31. }
  32.  
  33. @GetMapping("/books/{title}")
  34. public List<Book> getBooksByTitle(@PathVariable String title) {
  35. List<Book> books = bookMapper.map(bookService.getBooksByTitle(title));
  36. if (books.size() == 0) {
  37. System.out.println("No books available");
  38. }
  39. return books;
  40. }
  41.  
  42. @GetMapping("/books/author/{name}")
  43. public List<Book> getBooksByAuthorsName(@PathVariable String name) {
  44. List<Book> books = bookMapper.map(bookService.getBooksByAuthorsName(name));
  45. if (books.size() == 0) {
  46. System.out.println("No books available");
  47. }
  48. return books;
  49. }
  50.  
  51. @PostMapping("/book-order-request")
  52. public ResponseEntity sendBookOrderRequestToStorage(@RequestBody List<BookRequest> orderedBooks) {
  53. bookClient.sendBookOrderRequestToStorage(orderedBooks);
  54. return new ResponseEntity(HttpStatus.CREATED);
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment