modif service

Maxime
Maxime POINT 1 year ago
parent c23c0aa7c0
commit 004e52e0f6

@ -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

@ -7,10 +7,13 @@ import java.util.List;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import SAE.ApiREST.WebService.model.Article; import SAE.ApiREST.WebService.model.Article;
import SAE.ApiREST.WebService.model.Collection;
@Service @Service
public class CollectionService implements ICollectionService { public class CollectionService implements ICollectionService {
private ArrayList<Collection> collections; private ArrayList<Collection> collections;
@Override
public List<Collection> getAllCollections() { public List<Collection> getAllCollections() {
return this.collections; return this.collections;
} }
@ -18,18 +21,21 @@ public class CollectionService implements ICollectionService {
// region Collection // region Collection
// region GET // region GET
@Override
public Collection getCollectionById(long isbn){ public Collection getCollectionById(long isbn){
for(Collection collection : this.collections){ for(Collection collection : this.collections){
if(collection.getId === isbn) { if(collection.getId() == isbn) {
return collection; return collection;
} }
} }
return null; return null;
} }
@Override
public List<Collection> getAllCollectionsByName(String name){ public List<Collection> getAllCollectionsByName(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) {
repCollections.add(collection); repCollections.add(collection);
} }
} }
@ -38,15 +44,19 @@ public class CollectionService implements ICollectionService {
// endregion // endregion
// region DELETE // region DELETE
@Override
public void deleteColletionById(long isbn){ public void deleteColletionById(long isbn){
Collection collection = getCollectionById(isbn); Collection collection = getCollectionById(isbn);
this.collections.remove(collection); this.collections.remove(collection);
} }
@Override
public void deleteColletionByName(String name){ public void deleteColletionByName(String name){
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name); ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
this.collections.remove(collectionsByName[0]); this.collections.remove(collectionsByName[0]);
} }
@Override
public void deleteAllColletionByName(String name){ public void deleteAllColletionByName(String name){
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name); ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
this.collections.removeAll(collectionsByName); this.collections.removeAll(collectionsByName);
@ -54,18 +64,24 @@ public class CollectionService implements ICollectionService {
// endregion // endregion
// region PUT // region PUT
@Override
public void addCollection(Collection collection){ public void addCollection(Collection collection){
this.collections.add(collection); this.collections.add(collection);
} }
@Override
public void addCollections(List<Collection> collections){ public void addCollections(List<Collection> collections){
this.collections.addAll(collections); this.collections.addAll(collections);
} }
// endregion // endregion
// region POST // region POST
@Override
public void modifyCollectionName(Collection collection, String name){ public void modifyCollectionName(Collection collection, String name){
collection.setName(name); collection.setName(name);
} }
@Override
public void modifyCollectionNameById(long isbn, String name){ public void modifyCollectionNameById(long isbn, String name){
Collection collection = getCollectionById(isbn); Collection collection = getCollectionById(isbn);
modifyCollectionName(collection,name); modifyCollectionName(collection,name);
@ -74,12 +90,17 @@ public class CollectionService implements ICollectionService {
// endregion // endregion
// region Article // region Article
@Override
public List<Article> getAllArticles(Collection collection){ public List<Article> getAllArticles(Collection collection){
return collection.getAllArticles; return collection.getAllArticles;
} }
@Override
public void addArticle(Collection collection, Article article){ public void addArticle(Collection collection, Article article){
collection.addArticle collection.addArticle
} }
@Override
public void deleteArticle(Collection collection, Article article){ public void deleteArticle(Collection collection, Article article){
collection.deleteArticle(article); collection.deleteArticle(article);
} }

Loading…
Cancel
Save