modif du stub

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

@ -13,23 +13,24 @@ import SAE.ApiREST.WebService.model.Collect;
@Service
public class StubCollectionService implements ICollectionService {
private List<Collect> collects = new ArrayList<>();
@Override
public List<Collect> getAllCollections() {
List<Collect> 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<Collect> getAllCollections() {
return collects;
}
// region Collection
@ -37,9 +38,8 @@ public class StubCollectionService implements ICollectionService {
// region GET
@Override
public Collect getCollectionById(Integer id){
List<Collect> 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<Collect> getAllCollectionsByName(String name){
List<Collect> collections = getAllCollections();
ArrayList<Collect> repCollections = new ArrayList<Collect>();
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<Collect> collections = getAllCollections();
Collect collection = getCollectionById(id);
collections.remove(collection);
collects.remove(collection);
}
@Override
public void deleteColletionByName(String name){
List<Collect> collections = getAllCollections();
List<Collect> collectionsByName = getAllCollectionsByName(name);
collections.remove(collectionsByName.get(0));
collects.remove(collectionsByName.get(0));
}
@Override
public void deleteAllColletionByName(String name){
List<Collect> collections = getAllCollections();
List<Collect> collectionsByName = getAllCollectionsByName(name);
collections.removeAll(collectionsByName);
collects.removeAll(collectionsByName);
}
@Override
public void addCollection(Collect collection) {
List<Collect> collections = getAllCollections();
collections.add(collection);
collects.add(collection);
}
// endregion
// region PUT
@Override
public void addCollections(List<Collect> collections){
List<Collect> collectionsStub = getAllCollections();
collections.addAll(collectionsStub);
collects.addAll(collections);
}
// endregion

Loading…
Cancel
Save