From 68a9aad68243bf7a3313a7a61b39a8431bf1e41f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 27 Feb 2024 18:36:30 +0100 Subject: [PATCH] modif du stub --- .../service/StubCollectionService.java | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) 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 8c8feed..c2bcff3 100644 --- a/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java @@ -13,23 +13,24 @@ import SAE.ApiREST.WebService.model.Collect; @Service public class StubCollectionService implements ICollectionService { + private List collects = new ArrayList<>(); - @Override - public List getAllCollections() { - List collections = new ArrayList<>(); - - collections.add(new Collect("collect1", new Teacher(1, "12-03-2023", "aline.alipres@gmail.com", "MsGarconManque"),0)); + public StubCollectionService(){ + this.collects.add(new Collect("collect1", new Teacher(1, "12-03-2023", "aline.alipres@gmail.com", "MsGarconManque"),0)); Collect collection2 = new Collect("collect2", new Teacher(1, "12-03-2023", "aline.alipres@gmail.com", "MsGarconManque"),1); collection2.addArticle(new Article("toi","azezeaea", LocalDate.now().minusMonths(1),LocalDate.now().minusMonths(2),true,1)); - collections.add(collection2); + this.collects.add(collection2); Collect collection3 = new Collect("collect3", new Teacher(1, "12-03-2023", "aline.alipres@gmail.com", "MsGarconManque"),3); 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); + this.collects.add(collection3); + } - return collections; + @Override + public List getAllCollections() { + return collects; } // region Collection @@ -37,9 +38,8 @@ public class StubCollectionService implements ICollectionService { // region GET @Override public Collect getCollectionById(Integer id){ - List collections = getAllCollections(); try { - return collections.get(id); + return collects.get(id); }catch (Exception e){ return null; } @@ -47,9 +47,8 @@ public class StubCollectionService implements ICollectionService { @Override public List getAllCollectionsByName(String name){ - List collections = getAllCollections(); ArrayList repCollections = new ArrayList(); - for(Collect collection : collections){ + for(Collect collection : collects){ if(Objects.equals(collection.getName(), name)) { repCollections.add(collection); } @@ -61,37 +60,32 @@ public class StubCollectionService implements ICollectionService { // region DELETE @Override public void deleteColletionById(Integer id){ - List collections = getAllCollections(); Collect collection = getCollectionById(id); - collections.remove(collection); + collects.remove(collection); } @Override public void deleteColletionByName(String name){ - List collections = getAllCollections(); List collectionsByName = getAllCollectionsByName(name); - collections.remove(collectionsByName.get(0)); + collects.remove(collectionsByName.get(0)); } @Override public void deleteAllColletionByName(String name){ - List collections = getAllCollections(); List collectionsByName = getAllCollectionsByName(name); - collections.removeAll(collectionsByName); + collects.removeAll(collectionsByName); } @Override public void addCollection(Collect collection) { - List collections = getAllCollections(); - collections.add(collection); + collects.add(collection); } // endregion // region PUT @Override public void addCollections(List collections){ - List collectionsStub = getAllCollections(); - collections.addAll(collectionsStub); + collects.addAll(collections); } // endregion