-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooksController.java
More file actions
106 lines (56 loc) · 2.56 KB
/
BooksController.java
File metadata and controls
106 lines (56 loc) · 2.56 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.getdata.restcall_test1.Controller;
import com.getdata.restcall_test1.Entity.Books;
import com.getdata.restcall_test1.Service.BooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import java.util.List;
@RestController
@RequestMapping("/books")
public class BooksController {
@Autowired
private BooksService booksService;
@GetMapping("/genre/{genre}")
public ResponseEntity<List<Books>> getBooksByGenre(@PathVariable String genre) {
List<Books> books = booksService.getBooksByGenre(genre);
return ResponseEntity.ok(books);
}
@GetMapping("/best-sellers")
public ResponseEntity<List<Books>> getBestSellingBooks() {
List<Books> books = booksService.getBestSellingBooks();
return ResponseEntity.ok(books);
}
@PutMapping("/update-prices/{publisher}/{discountPercent}")
public ResponseEntity<Void> updateBookPrices(
@PathVariable String publisher,
@PathVariable double discountPercent
) {
booksService.updateBookPrices(publisher, discountPercent);
return ResponseEntity.ok().build();
}
@GetMapping("/isbn/{isbn}")
public ResponseEntity<Books> getBookByISBN(@PathVariable String isbn) {
Books book = booksService.getBookByISBN(isbn);
if (book != null) {
return ResponseEntity.ok(book);
} else {
return ResponseEntity.notFound().build();
}
}
@PostMapping("/createBook")
public ResponseEntity<Void> createBook(@RequestBody Books book) {
booksService.createBook(book);
return new ResponseEntity<>(HttpStatus.CREATED);
}
}
//http://localhost:8080/books/Fantasy for genre
//http://localhost:8080/books/Best Sellers for best-seller
//http://localhost:8080/books/publisher/discount?publisher=Bantam&discountPercent=5 discount for publisher
//http://localhost:8080/books/Vintage/5 a more simple way to update price
//GET http://localhost:8080/books/isbn/9780743210898 for isbn
//http://localhost:8080/books/genre/Fantasy for genre
//http://localhost:8080/books/best-sellers for best-seller
//http://localhost:8080/books/publisher/discount?publisher=Bantam&discountPercent=5 discount for publisher
//http://localhost:8080/books/Vintage/5 a more simple way to update price
//GET http://localhost:8080/books/isbn/9780743210898 for isbn