modif du stub

Maxime
Maxime POINT 1 year ago
parent 808ccbc480
commit 68a9aad682

@ -13,23 +13,24 @@ import SAE.ApiREST.WebService.model.Collect;
@Service @Service
public class StubCollectionService implements ICollectionService { public class StubCollectionService implements ICollectionService {
private List<Collect> collects = new ArrayList<>();
@Override public StubCollectionService(){
public List<Collect> getAllCollections() { this.collects.add(new Collect("collect1", new Teacher(1, "12-03-2023", "aline.alipres@gmail.com", "MsGarconManque"),0));
List<Collect> collections = new ArrayList<>();
collections.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); 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)); 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); 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));
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<Collect> getAllCollections() {
return collects;
} }
// region Collection // region Collection
@ -37,9 +38,8 @@ public class StubCollectionService implements ICollectionService {
// region GET // region GET
@Override @Override
public Collect getCollectionById(Integer id){ public Collect getCollectionById(Integer id){
List<Collect> collections = getAllCollections();
try { try {
return collections.get(id); return collects.get(id);
}catch (Exception e){ }catch (Exception e){
return null; return null;
} }
@ -47,9 +47,8 @@ public class StubCollectionService implements ICollectionService {
@Override @Override
public List<Collect> getAllCollectionsByName(String name){ public List<Collect> getAllCollectionsByName(String name){
List<Collect> collections = getAllCollections();
ArrayList<Collect> repCollections = new ArrayList<Collect>(); ArrayList<Collect> repCollections = new ArrayList<Collect>();
for(Collect collection : collections){ for(Collect collection : collects){
if(Objects.equals(collection.getName(), name)) { if(Objects.equals(collection.getName(), name)) {
repCollections.add(collection); repCollections.add(collection);
} }
@ -61,37 +60,32 @@ public class StubCollectionService implements ICollectionService {
// region DELETE // region DELETE
@Override @Override
public void deleteColletionById(Integer id){ public void deleteColletionById(Integer id){
List<Collect> collections = getAllCollections();
Collect collection = getCollectionById(id); Collect collection = getCollectionById(id);
collections.remove(collection); collects.remove(collection);
} }
@Override @Override
public void deleteColletionByName(String name){ public void deleteColletionByName(String name){
List<Collect> collections = getAllCollections();
List<Collect> collectionsByName = getAllCollectionsByName(name); List<Collect> collectionsByName = getAllCollectionsByName(name);
collections.remove(collectionsByName.get(0)); collects.remove(collectionsByName.get(0));
} }
@Override @Override
public void deleteAllColletionByName(String name){ public void deleteAllColletionByName(String name){
List<Collect> collections = getAllCollections();
List<Collect> collectionsByName = getAllCollectionsByName(name); List<Collect> collectionsByName = getAllCollectionsByName(name);
collections.removeAll(collectionsByName); collects.removeAll(collectionsByName);
} }
@Override @Override
public void addCollection(Collect collection) { public void addCollection(Collect collection) {
List<Collect> collections = getAllCollections(); collects.add(collection);
collections.add(collection);
} }
// endregion // endregion
// region PUT // region PUT
@Override @Override
public void addCollections(List<Collect> collections){ public void addCollections(List<Collect> collections){
List<Collect> collectionsStub = getAllCollections(); collects.addAll(collections);
collections.addAll(collectionsStub);
} }
// endregion // endregion

Loading…
Cancel
Save