Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rewe.exercise.bookstore.book;
- import com.rewe.exercise.bookstore.bookRequest.BookRequest;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- @RestController
- @RequestMapping("/bookstore")
- public class BookRestController {
- private final BookMapper bookMapper;
- private final BookService bookService;
- private final BookClient bookClient;
- public BookRestController(BookMapper bookMapper, BookService bookService, BookClient bookClient) {
- this.bookMapper = bookMapper;
- this.bookService = bookService;
- this.bookClient = bookClient;
- }
- @GetMapping("/books")
- public List<Book> getAllBooks() {
- List<Book> books = bookMapper.map(bookService.getAllBooks());
- if (books.size() == 0) {
- System.out.println("No books available");
- }
- return books;
- }
- @GetMapping("/books/{title}")
- public List<Book> getBooksByTitle(@PathVariable String title) {
- List<Book> books = bookMapper.map(bookService.getBooksByTitle(title));
- if (books.size() == 0) {
- System.out.println("No books available");
- }
- return books;
- }
- @GetMapping("/books/author/{name}")
- public List<Book> getBooksByAuthorsName(@PathVariable String name) {
- List<Book> books = bookMapper.map(bookService.getBooksByAuthorsName(name));
- if (books.size() == 0) {
- System.out.println("No books available");
- }
- return books;
- }
- @PostMapping("/book-order-request")
- public ResponseEntity sendBookOrderRequestToStorage(@RequestBody List<BookRequest> orderedBooks) {
- bookClient.sendBookOrderRequestToStorage(orderedBooks);
- return new ResponseEntity(HttpStatus.CREATED);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment