diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 95ca769..09f4eec 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -10,4 +10,9 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..e218625
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 9af8f2b..d5507dc 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,7 +8,7 @@
-
+
\ No newline at end of file
diff --git a/WebService/pom.xml b/WebService/pom.xml
index 0f7f3be..56b8716 100644
--- a/WebService/pom.xml
+++ b/WebService/pom.xml
@@ -1,34 +1,6 @@
- 4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 3.2.2
-
-
- com.example
- WebService
- 0.0.1-SNAPSHOT
- tp2
- Demo project for Spring Boot
-
- 17
-
-
-
- org.springframework.boot
- spring-boot-starter
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-=======
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
@@ -66,17 +38,6 @@
jakarta.persistence-api
->>>>>>> origin/feature/response
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
- jakarta.persistence
- jakarta.persistence-api
-
-
diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectController.java b/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectController.java
index 99b3545..c42c182 100644
--- a/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectController.java
+++ b/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectController.java
@@ -1,16 +1,98 @@
package SAE.ApiREST.WebService.controller;
+import SAE.ApiREST.WebService.model.Article;
+import SAE.ApiREST.WebService.model.Collect;
+import SAE.ApiREST.WebService.service.ICollectionService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.GetMapping;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
@Controller
- @RequestMapping("/CollectWebService")
- public class CollectController {
+@RequestMapping("/CollectWebService")
+public class CollectController {
+ @Autowired
+ ICollectionService collectionService;
+
+ public CollectController() {
+
+ }
+
+ // region Collection
+
+ // region GET
+ @GetMapping(value = "/getAllCollection", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody List getAllCollection(){
+ return collectionService.getAllCollections();
+ }
+ @GetMapping(value = "/getCollectionById/{isbn}", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody Collect getCollectionById(@PathVariable(value = "isbn") long isbn){
+ return collectionService.getCollectionById(isbn);
+ }
+ @GetMapping(value = "/getAllCollectionsByName/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody List getAllCollectionsByName(@PathVariable(value = "name") String name){
+ return collectionService.getAllCollectionsByName(name);
+ }
+ // endregion
+
+ // region DELETE
+ @DeleteMapping(value = "/deleteColletionById/{isbn}")
+ public @ResponseBody void deleteColletionById(@RequestParam("isbn") long isbn){
+ collectionService.deleteColletionById(isbn);
+ }
+
+ @DeleteMapping(value = "/deleteColletionByName/{name}")
+ public @ResponseBody void deleteColletionByName(@RequestParam("name") String name){
+ collectionService.deleteColletionByName(name);
+ }
+
+ @DeleteMapping(value = "/deleteAllColletionByName/{name}")
+ public @ResponseBody void deleteAllColletionByName(@RequestParam("name") String name){
+ collectionService.deleteAllColletionByName(name);
+ }
+ // endregion
+
+ // region PUT
+ @PutMapping(value = "/addCollection")
+ public @ResponseBody void addCollection(@RequestParam("collection") Collect collection){
+ collectionService.addCollection(collection);
+ }
+
+ @PutMapping(value = "/addCollections")
+ public @ResponseBody void addCollections(@RequestParam("collections") List collections){
+ collectionService.addCollections(collections);
+ }
+ // endregion
+ // region POST
+ @PostMapping(value="/modifyCollectionName", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody void modifyCollectionName(@RequestParam("collection") Collect collection, @RequestParam("name") String name){
+ collectionService.modifyCollectionName(collection,name);
}
+ @PostMapping(value="/modifyCollectionNameById", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody void modifyCollectionNameById(@RequestParam("isbn") long isbn, @RequestParam("name") String name){
+ collectionService.modifyCollectionNameById(isbn,name);
+ }
+ // endregion
+ // endregion
+
+ // region Article
+ @GetMapping(value = "/getAllArticles", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody List getAllArticles(@RequestParam("collection") Collect collection){
+ return collectionService.getAllArticles(collection);
+ }
+
+ @PutMapping(value = "/addArticle", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody void addArticle(@RequestParam("collection") Collect collection, @RequestParam("article") Article article){
+ collectionService.addArticle(collection,article);
+ }
+
+ @DeleteMapping(value = "/deleteArticle", produces = MediaType.APPLICATION_JSON_VALUE)
+ public @ResponseBody void deleteArticle(@RequestParam("collection") Collect collection, @RequestParam("article") Article article){
+ collectionService.deleteArticle(collection,article);
+ }
+ // endregion
+}
diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectionControlleur.java b/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectionControlleur.java
deleted file mode 100644
index bf1fbbc..0000000
--- a/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectionControlleur.java
+++ /dev/null
@@ -1,98 +0,0 @@
-@org.springframework.stereotype.Controller
-
-@Controller
-@RequestMapping("/CollectionWebService")
-public class CollectionController {
- private ArrayList collections = new ArrayList<>();
-
- public Controller() {
-
- }
-
- // region Collection
-
- // region GET
- @GetMapping(value = "/getCollectionById/{isbn}", produces = MediaType.APPLICATION_JSON_VALUE)
- public @ResponseBody Collection getCollectionById(@PathVariable(value = "isbn") long isbn){
- for(Collection collection : this.collections){
- if(collection.getId === isbn) {
- return collection;
- }
- }
- return null;
- }
- @GetMapping(value = "/getAllCollectionsByName/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
- public @ResponseBody List getAllCollectionsByName(@PathVariable(value = "name") String name){
- private ArrayList repCollections = new ArrayList();
- for(Collection collection : this.collections){
- if(collection.getName === name) {
- repCollections.add(collection);
- }
- }
- return repCollections;
- }
- // endregion
-
- // region DELETE
- @DeleteMapping(value = "/deleteColletionById/{isbn}")
- public @ResponseBody void deleteColletionById(@RequestParam("isbn") long isbn){
- Collection collection = getCollectionById(isbn);
- this.collections.remove(collection);
- }
-
- @DeleteMapping(value = "/deleteColletionByName/{name}")
- public @ResponseBody void deleteColletionByName(@RequestParam("name") String name){
- ArrayList collectionsByName = getAllCollectionsByName(name);
- this.collections.remove(collectionsByName[0]);
- }
-
- @DeleteMapping(value = "/deleteAllColletionByName/{name}")
- public @ResponseBody void deleteAllColletionByName(@RequestParam("name") String name){
- ArrayList collectionsByName = getAllCollectionsByName(name);
- this.collections.removeAll(collectionsByName);
- }
- // endregion
-
- // region PUT
- @PutMapping(value = "/addCollection")
- public @ResponseBody void addCollection(@RequestParam("collection") Collection collection){
- this.collections.add(collection);
- }
-
- @PutMapping(value = "/addCollections")
- public @ResponseBody void addCollections(@RequestParam("collections") List collections){
- this.collections.addAll(collections);
- }
- // endregion
-
- // region POST
- @PostMapping("/modifyCollectionName", produces = MediaType.APPLICATION_JSON_VALUE)
- public @ResponseBody void modifyCollectionName(@RequestParam("collection") Collection collection, @RequestParam("name") String name){
- collection.setName(name);
- }
-
- @PostMapping("/modifyCollectionNameById", produces = MediaType.APPLICATION_JSON_VALUE)
- public @ResponseBody void modifyCollectionNameById(@RequestParam("isbn") long isbn, @RequestParam("name") 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(@RequestParam("collection") Collection collection){
- return collection.getAllArticles;
- }
-
- @PutMapping(value = "/addArticle", produces = MediaType.APPLICATION_JSON_VALUE)
- public @ResponseBody void addArticle(@RequestParam("collection") Collection collection, @RequestParam("article") Article article){
- collection.addArticle
- }
-
- @DeleteMapping(value = "/deleteArticle", produces = MediaType.APPLICATION_JSON_VALUE)
- public @ResponseBody void deleteArticle(@RequestParam("collection") Collection collection, @RequestParam("article") Article article){
- collection.deleteArticle(article);
- }
- // endregion
-}
diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/model/Article.java b/WebService/src/main/java/SAE/ApiREST/WebService/model/Article.java
index dc3876f..550d3b0 100644
--- a/WebService/src/main/java/SAE/ApiREST/WebService/model/Article.java
+++ b/WebService/src/main/java/SAE/ApiREST/WebService/model/Article.java
@@ -12,11 +12,7 @@ import jakarta.persistence.Id;
public class Article {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
-<<<<<<< HEAD
-
-=======
String id;
->>>>>>> origin/feature/response
String title;
String URL;
LocalDate dateAdded;
diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java
index 3c8d9f8..42b6801 100644
--- a/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java
+++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java
@@ -1,25 +1,44 @@
package SAE.ApiREST.WebService.service;
import SAE.ApiREST.WebService.model.Collect;
+import SAE.ApiREST.WebService.model.Teacher;
+import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
import SAE.ApiREST.WebService.model.Article;
import org.springframework.stereotype.Service;
-import SAE.ApiREST.WebService.model.Collection;
+import SAE.ApiREST.WebService.model.Collect;
@Service
public class StubCollectionService implements ICollectionService {
- private ArrayList collections;
+
+ @Override
public List getAllCollections() {
- return this.collections;
+ List collections = new ArrayList<>();
+
+ collections.add(new Collect("collect1", new Teacher(1, "12-01-2023", "aline.alipres@gmail.com", "MsGarconManque")));
+
+ Collect collection2 = new Collect("collect2", new Teacher(1, "12-01-2023", "aline.alipres@gmail.com", "MsGarconManque"));
+ collection2.addArticle(new Article("toi","azezeaea", LocalDate.now().minusMonths(1),LocalDate.now().minusMonths(2),true,1));
+ collections.add(collection2);
+
+ Collect collection3 = new Collect("collect3", new Teacher(1, "12-01-2023", "aline.alipres@gmail.com", "MsGarconManque"));
+ collection3.addArticle(new Article("toi","azezeaea",LocalDate.now().minusMonths(1),LocalDate.now().minusMonths(2),true,1));
+ collection3.addArticle(new Article("toi","azezeaea",LocalDate.now().minusMonths(1),LocalDate.now().minusMonths(2),true,1));
+ collections.add(collection3);
+
+ return collections;
}
// region Collection
// region GET
+ @Override
public Collect getCollectionById(long isbn){
- for(Collect collection : this.collections){
+ List collections = getAllCollections();
+ for(Collect collection : collections){
if(collection.getId() == isbn) {
return collection;
}
@@ -28,14 +47,11 @@ public class StubCollectionService implements ICollectionService {
}
@Override
- public List getAllCollectionsByName(String name){
- private ArrayList repCollections = new ArrayList();
- for(Collection collection : this.collections){
- if(collection.getName() == name) {
public List getAllCollectionsByName(String name){
+ List collections = getAllCollections();
ArrayList repCollections = new ArrayList();
- for(Collect collection : this.collections){
- if(collection.getName() == name) {
+ for(Collect collection : collections){
+ if(Objects.equals(collection.getName(), name)) {
repCollections.add(collection);
}
}
@@ -46,35 +62,42 @@ public class StubCollectionService implements ICollectionService {
// region DELETE
@Override
public void deleteColletionById(long isbn){
+ List collections = getAllCollections();
Collect collection = getCollectionById(isbn);
- this.collections.remove(collection);
+ collections.remove(collection);
}
@Override
public void deleteColletionByName(String name){
+ List collections = getAllCollections();
List collectionsByName = getAllCollectionsByName(name);
- this.collections.remove(collectionsByName.get(0));
+ collections.remove(collectionsByName.get(0));
}
@Override
public void deleteAllColletionByName(String name){
+ List collections = getAllCollections();
List collectionsByName = getAllCollectionsByName(name);
- this.collections.removeAll(collectionsByName);
+ collections.removeAll(collectionsByName);
}
@Override
public void addCollection(Collect collection) {
- this.collections.add(collection);
+ List collections = getAllCollections();
+ collections.add(collection);
}
// endregion
// region PUT
+ @Override
public void addCollections(List collections){
- this.collections.addAll(collections);
+ List collectionsStub = getAllCollections();
+ collections.addAll(collectionsStub);
}
// endregion
// region POST
+ @Override
public void modifyCollectionName(Collect collection, String name){
collection.setName(name);
}
@@ -88,12 +111,15 @@ public class StubCollectionService implements ICollectionService {
// endregion
// region Article
+ @Override
public List getAllArticles(Collect collect){
return collect.getAllArticles();
}
+ @Override
public void addArticle(Collect collect, Article article){
collect.addArticle(article);
}
+ @Override
public void deleteArticle(Collect collect, Article article){
collect.removeArticle(article);
}