|
|
@ -9,33 +9,11 @@ public class CollectionController {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/getAllCollection", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
|
|
|
public @ResponseBody List<Collection> getAllCollection() {
|
|
|
|
|
|
|
|
return collections;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/getCollectionById/{isbn}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
|
|
|
public @ResponseBody Book getCollectionById(@PathVariable(value = "isbn") int isbn) {
|
|
|
|
|
|
|
|
for(Book book : books) {
|
|
|
|
|
|
|
|
if(book.isbn == isbn) {
|
|
|
|
|
|
|
|
return book;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new BookException("Undefined id");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/logBooks")
|
|
|
|
|
|
|
|
public @ResponseBody void logBooks(@RequestParam("title") String title, @RequestParam("author") String author) {
|
|
|
|
|
|
|
|
books.add(new Book(title, author));
|
|
|
|
|
|
|
|
for(Book book : books) {
|
|
|
|
|
|
|
|
System.out.println(book);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// region Collection
|
|
|
|
// region Collection
|
|
|
|
|
|
|
|
|
|
|
|
// region GET
|
|
|
|
// region GET
|
|
|
|
@GetMapping(value = "/getCollectionById", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@GetMapping(value = "/getCollectionById/{isbn}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody Collection getCollectionById(long isbn){
|
|
|
|
public @ResponseBody Collection getCollectionById(@PathVariable(value = "isbn") long isbn){
|
|
|
|
for(Collection collection : this.collections){
|
|
|
|
for(Collection collection : this.collections){
|
|
|
|
if(collection.getId === isbn) {
|
|
|
|
if(collection.getId === isbn) {
|
|
|
|
return collection;
|
|
|
|
return collection;
|
|
|
@ -43,8 +21,8 @@ public class CollectionController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@GetMapping(value = "/getAllCollectionsByName", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@GetMapping(value = "/getAllCollectionsByName/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody List<Collection> getAllCollectionsByName(String name){
|
|
|
|
public @ResponseBody List<Collection> getAllCollectionsByName(@PathVariable(value = "name") String name){
|
|
|
|
private ArrayList<Collection> repCollections = new ArrayList<Collection>();
|
|
|
|
private ArrayList<Collection> repCollections = new ArrayList<Collection>();
|
|
|
|
for(Collection collection : this.collections){
|
|
|
|
for(Collection collection : this.collections){
|
|
|
|
if(collection.getName === name) {
|
|
|
|
if(collection.getName === name) {
|
|
|
@ -56,36 +34,45 @@ public class CollectionController {
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
|
|
// region DELETE
|
|
|
|
// region DELETE
|
|
|
|
@DeleteMaping(value = "/deleteColletionById")
|
|
|
|
@DeleteMapping(value = "/deleteColletionById/{isbn}")
|
|
|
|
public @ResponseBody void deleteColletionById(long isbn){
|
|
|
|
public @ResponseBody void deleteColletionById(@RequestParam("isbn") long isbn){
|
|
|
|
Collection collection = getCollectionById(isbn);
|
|
|
|
Collection collection = getCollectionById(isbn);
|
|
|
|
this.collections.remove(collection);
|
|
|
|
this.collections.remove(collection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public @ResponseBody void deleteColletionByName(String name){
|
|
|
|
@DeleteMapping(value = "/deleteColletionByName/{name}")
|
|
|
|
|
|
|
|
public @ResponseBody void deleteColletionByName(@RequestParam("name") String name){
|
|
|
|
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
|
|
|
|
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
|
|
|
|
this.collections.remove(collectionsByName[0]);
|
|
|
|
this.collections.remove(collectionsByName[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public @ResponseBody void deleteAllColletionByName(String name){
|
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping(value = "/deleteAllColletionByName/{name}")
|
|
|
|
|
|
|
|
public @ResponseBody void deleteAllColletionByName(@RequestParam("name") String name){
|
|
|
|
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
|
|
|
|
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
|
|
|
|
this.collections.removeAll(collectionsByName);
|
|
|
|
this.collections.removeAll(collectionsByName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
|
|
// region PUT
|
|
|
|
// region PUT
|
|
|
|
public @ResponseBody void addCollection(Collection collection){
|
|
|
|
@PutMapping(value = "/addCollection")
|
|
|
|
|
|
|
|
public @ResponseBody void addCollection(@RequestParam("collection") Collection collection){
|
|
|
|
this.collections.add(collection);
|
|
|
|
this.collections.add(collection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public @ResponseBody void addCollections(List<Collection> collections){
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping(value = "/addCollections")
|
|
|
|
|
|
|
|
public @ResponseBody void addCollections(@RequestParam("collections") List<Collection> collections){
|
|
|
|
this.collections.addAll(collections);
|
|
|
|
this.collections.addAll(collections);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
|
|
// region POST
|
|
|
|
// region POST
|
|
|
|
public @ResponseBody void modifyCollectionName(Collection collection, String name){
|
|
|
|
@PostMapping("/modifyCollectionName", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
|
|
|
public @ResponseBody void modifyCollectionName(@RequestParam("collection") Collection collection, @RequestParam("name") String name){
|
|
|
|
collection.setName(name);
|
|
|
|
collection.setName(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public @ResponseBody void modifyCollectionNameById(long isbn, String name){
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/modifyCollectionNameById", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
|
|
|
public @ResponseBody void modifyCollectionNameById(@RequestParam("isbn") long isbn, @RequestParam("name") String name){
|
|
|
|
Collection collection = getCollectionById(isbn);
|
|
|
|
Collection collection = getCollectionById(isbn);
|
|
|
|
modifyCollectionName(collection,name);
|
|
|
|
modifyCollectionName(collection,name);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -94,13 +81,17 @@ public class CollectionController {
|
|
|
|
|
|
|
|
|
|
|
|
// region Article
|
|
|
|
// region Article
|
|
|
|
@GetMapping(value = "/getAllArticles", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@GetMapping(value = "/getAllArticles", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody List<Article> getAllArticles(Collection collection){
|
|
|
|
public @ResponseBody List<Article> getAllArticles(@RequestParam("collection") Collection collection){
|
|
|
|
return collection.getAllArticles;
|
|
|
|
return collection.getAllArticles;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public @ResponseBody void addArticle(Collection collection, Article article){
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping(value = "/addArticle", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
|
|
|
public @ResponseBody void addArticle(@RequestParam("collection") Collection collection, @RequestParam("article") Article article){
|
|
|
|
collection.addArticle
|
|
|
|
collection.addArticle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public @ResponseBody void deleteArticle(Collection collection, Article article){
|
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping(value = "/deleteArticle", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
|
|
|
public @ResponseBody void deleteArticle(@RequestParam("collection") Collection collection, @RequestParam("article") Article article){
|
|
|
|
collection.deleteArticle(article);
|
|
|
|
collection.deleteArticle(article);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|