diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/CollectionControlleur.java b/WebService/src/main/java/SAE/ApiREST/WebService/CollectionControlleur.java deleted file mode 100644 index 2e17cad..0000000 --- a/WebService/src/main/java/SAE/ApiREST/WebService/CollectionControlleur.java +++ /dev/null @@ -1,37 +0,0 @@ -@org.springframework.stereotype.Controller - -@Controller -@RequestMapping("/CollectionWebService") -public class CollectionController { - private ArrayList books = new ArrayList<>(); - - public Controller() { - books.add(new Book("titre1", "moi")); - books.add(new Book("titre2", "toi")); - books.add(new Book("titre3", "eux")); - books.add(new Book("titre4", "tout ceux qui le veule")); - } - - @GetMapping(value = "/getAllBooks", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody List getAllBooks() { - return books; - } - - @GetMapping(value = "/getBookById/{isbn}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody Book getBookById(@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); - } - } -} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/Data/Article.java b/WebService/src/main/java/SAE/ApiREST/WebService/Data/Article.java deleted file mode 100644 index 58a2c90..0000000 --- a/WebService/src/main/java/SAE/ApiREST/WebService/Data/Article.java +++ /dev/null @@ -1,2 +0,0 @@ -@Entity -public class Article \ No newline at end of file diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectionControlleur.java b/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectionControlleur.java new file mode 100644 index 0000000..6060b3f --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectionControlleur.java @@ -0,0 +1,107 @@ +@org.springframework.stereotype.Controller + +@Controller +@RequestMapping("/CollectionWebService") +public class CollectionController { + private ArrayList collections = new ArrayList<>(); + + public Controller() { + + } + + @GetMapping(value = "/getAllCollection", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List 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 GET + @GetMapping(value = "/getCollectionById", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody Collection getCollectionById(long isbn){ + for(Collection collection : this.collections){ + if(collection.getId === isbn) { + return collection; + } + } + return null; + } + @GetMapping(value = "/getAllCollectionsByName", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List getAllCollectionsByName(String name){ + private ArrayList repCollections = new ArrayList(); + for(Collection collection : this.collections){ + if(collection.getName === name) { + repCollections.add(collection); + } + } + return repCollections; + } + // endregion + + // region DELETE + @DeleteMaping(value = "/deleteColletionById") + public @ResponseBody void deleteColletionById(long isbn){ + Collection collection = getCollectionById(isbn); + this.collections.remove(collection); + } + + public @ResponseBody void deleteColletionByName(String name){ + ArrayList collectionsByName = getAllCollectionsByName(name); + this.collections.remove(collectionsByName[0]); + } + public @ResponseBody void deleteAllColletionByName(String name){ + ArrayList collectionsByName = getAllCollectionsByName(name); + this.collections.removeAll(collectionsByName); + } + // endregion + + // region PUT + public @ResponseBody void addCollection(Collection collection){ + this.collections.add(collection); + } + public @ResponseBody void addCollections(List collections){ + this.collections.addAll(collections); + } + // endregion + + // region POST + public @ResponseBody void modifyCollectionName(Collection collection, String name){ + collection.setName(name); + } + public @ResponseBody void modifyCollectionNameById(long isbn, String name){ + Collection collection = getCollectionById(isbn); + modifyCollectionName(collection,name); + } + // endregion + // endregion + + // region Article + @GetMapping(value = "/getAllArticles", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getAllArticles(Collection collection){ + return collection.getAllArticles; + } + public @ResponseBody void addArticle(Collection collection, Article article){ + collection.addArticle + } + public @ResponseBody void deleteArticle(Collection collection, Article article){ + collection.deleteArticle(article); + } + // endregion +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/Data/Collection.java b/WebService/src/main/java/SAE/ApiREST/WebService/model/Collection.java similarity index 72% rename from WebService/src/main/java/SAE/ApiREST/WebService/Data/Collection.java rename to WebService/src/main/java/SAE/ApiREST/WebService/model/Collection.java index 3f85887..bf1f6dc 100644 --- a/WebService/src/main/java/SAE/ApiREST/WebService/Data/Collection.java +++ b/WebService/src/main/java/SAE/ApiREST/WebService/model/Collection.java @@ -8,16 +8,27 @@ public class Collection{ private ArrayList
articles @Column(name = "name") private String name + @Column(name = "teacher") + private Teacher teacher - public Collection(String name){ + public Collection(String name, Teacher teacher){ this.name = name; + this.teacher = teacher; this.articles = new ArrayList
(); } + // region Article + public long getId(){ + return isbn; + } + // endregion + + // region Article public List
getAllArticles(){ return articles; } + // region addArticle public void addArticle(Article article){ if(!this.articles.contains(article)){ this.articles.add(article); @@ -28,17 +39,24 @@ public class Collection{ addArticle(article); } } + // endregion + + // region removeArticle public void removeArticle(Article article){ this.articles.remove(article); } public void removeArticles(List
articles){ this.articles.removeAll(articles); } + // endregion + // endregion + // region name public String getName(){ return name; } public void setName(String name){ this.name = name; } + // endregion } \ No newline at end of file diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/ICollectionService.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/ICollectionService.java new file mode 100644 index 0000000..6b82362 --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/ICollectionService.java @@ -0,0 +1,15 @@ +public interface ICollectionService{ + public List getAllCollections(); + public Collection getCollectionById(long isbn); + public List getAllCollectionsByName(String name); + public void deleteColletionById(long isbn); + public void deleteColletionByName(String name); + public void deleteAllColletionByName(String name); + public void addCollection(Collection collection); + public void addCollections(List collection); + public void modifyCollectionName(Collection collection, String name); + public void modifyCollectionNameById(long isbn, String name); + public List
getAllArticles(Collection collection); + public void addArticle(Collection collection, Article article); + public void deleteArticle(Collection collection, Article article); +} \ No newline at end of file diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java new file mode 100644 index 0000000..a335f5f --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java @@ -0,0 +1,87 @@ +package SAE.ApiREST.WebService.service; + +import java.sql.Date; +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Service; + +import SAE.ApiREST.WebService.model.Article; + +@Service +public class CollectionService implements ICollectionService { + private ArrayList collections; + public List getAllCollections() { + return this.collections; + } + + // region Collection + + // region GET + public Collection getCollectionById(long isbn){ + for(Collection collection : this.collections){ + if(collection.getId === isbn) { + return collection; + } + } + return null; + } + public List getAllCollectionsByName(String name){ + private ArrayList repCollections = new ArrayList(); + for(Collection collection : this.collections){ + if(collection.getName === name) { + repCollections.add(collection); + } + } + return repCollections; + } + // endregion + + // region DELETE + public void deleteColletionById(long isbn){ + Collection collection = getCollectionById(isbn); + this.collections.remove(collection); + } + + public void deleteColletionByName(String name){ + ArrayList collectionsByName = getAllCollectionsByName(name); + this.collections.remove(collectionsByName[0]); + } + public void deleteAllColletionByName(String name){ + ArrayList collectionsByName = getAllCollectionsByName(name); + this.collections.removeAll(collectionsByName); + } + // endregion + + // region PUT + public void addCollection(Collection collection){ + this.collections.add(collection); + } + public void addCollections(List collections){ + this.collections.addAll(collections); + } + // endregion + + // region POST + public void modifyCollectionName(Collection collection, String name){ + collection.setName(name); + } + public void modifyCollectionNameById(long isbn, String name){ + Collection collection = getCollectionById(isbn); + modifyCollectionName(collection,name); + } + // endregion + // endregion + + // region Article + public List
getAllArticles(Collection collection){ + return collection.getAllArticles; + } + public void addArticle(Collection collection, Article article){ + collection.addArticle + } + public void deleteArticle(Collection collection, Article article){ + collection.deleteArticle(article); + } + // endregion +} \ No newline at end of file