adding Articles and modifying Collection files

pull/1/head
Roxane ROSSETTO 1 year ago
parent 2ffbeaa359
commit 29abf4d5c9

@ -1,22 +1,30 @@
package SAE.ApiREST.WebService.Data;
package SAE.ApiREST.WebService.model;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
public class Collection{
public class Collect {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private final long isbn
@GeneratedValue(strategy= GenerationType.AUTO)
private final long isbn = 0;
@Column(name = "articles")
private ArrayList<Article> articles
private ArrayList<Article> articles;
@Column(name = "name")
private String name
private String name;
@Column(name = "teacher")
private Teacher teacher
private Teacher teacher;
public Collection(String name, Teacher teacher){
public Collect(String name, Teacher teacher){
this.name = name;
this.teacher = teacher;
this.articles = new ArrayList<Article>();
}
public Collect() {
}
// region Article
public long getId(){
return isbn;

@ -15,7 +15,8 @@ public class Teacher {
private String mail;
private String username;
public Teacher(int id, LocalDate date, String mail, String msGarconManque) {
public Teacher() {
}
public Teacher(int id, String date, String mail, String username) {

@ -1,20 +1,21 @@
package SAE.ApiREST.WebService.service;
import SAE.ApiREST.WebService.model.Collect;
import SAE.ApiREST.WebService.model.Article;
import java.util.Collection;
import java.util.List;
public interface ICollectionService{
public List<Collection> getAllCollections();
public Collection getCollectionById(long isbn);
public List<Collection> getAllCollectionsByName(String name);
public List<Collect> getAllCollections();
public Collect getCollectionById(long isbn);
public List<Collect> 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> collection);
public void modifyCollectionName(Collection collection, String name);
public void addCollection(Collect collection);
public void addCollections(List<Collect> collection);
public void modifyCollectionName(Collect collection, String name);
public void modifyCollectionNameById(long isbn, String name);
public List<Article> getAllArticles(Collection collection);
public void addArticle(Collection collection, Article article);
public void deleteArticle(Collection collection, Article article);
public List<Article> getAllArticles(Collect collection);
public void addArticle(Collect collection, Article article);
public void deleteArticle(Collect collection, Article article);
}

@ -14,7 +14,7 @@ public interface ITeacherService {
public Teacher getTeacherByUsername(String username);
public Teacher getTeacherByMail(String mail);
public Teacher getTeacherByDate(LocalDate date);
public Teacher getTeacherByDate(String date);
public List<Teacher> addTeacher(Teacher t);
public List<Teacher> deleteTeacher(int id);

@ -1,32 +1,34 @@
package SAE.ApiREST.WebService.service;
import SAE.ApiREST.WebService.model.Collect;
import java.util.ArrayList;
import java.util.List;
import SAE.ApiREST.WebService.model.Article;
import org.springframework.stereotype.Service;
@Service
public class CollectionService implements ICollectionService {
private ArrayList<Collection> collections;
public List<Collection> getAllCollections() {
public class StubCollectionService implements ICollectionService {
private ArrayList<Collect> collections;
public List<Collect> getAllCollections() {
return this.collections;
}
// region Collection
// region GET
public Collection getCollectionById(long isbn){
for(Collection collection : this.collections){
if(collection.getId === isbn) {
public Collect getCollectionById(long isbn){
for(Collect collection : this.collections){
if(collection.getId() == isbn) {
return collection;
}
}
return null;
}
public List<Collection> getAllCollectionsByName(String name){
private ArrayList<Collection> repCollections = new ArrayList<Collection>();
for(Collection collection : this.collections){
if(collection.getName === name) {
public List<Collect> getAllCollectionsByName(String name){
ArrayList<Collect> repCollections = new ArrayList<Collect>();
for(Collect collection : this.collections){
if(collection.getName() == name) {
repCollections.add(collection);
}
}
@ -36,49 +38,52 @@ public class CollectionService implements ICollectionService {
// region DELETE
public void deleteColletionById(long isbn){
Collection collection = getCollectionById(isbn);
Collect collection = getCollectionById(isbn);
this.collections.remove(collection);
}
public void deleteColletionByName(String name){
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
this.collections.remove(collectionsByName[0]);
List<Collect> collectionsByName = getAllCollectionsByName(name);
this.collections.remove(collectionsByName.get(0));
}
public void deleteAllColletionByName(String name){
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
List<Collect> collectionsByName = getAllCollectionsByName(name);
this.collections.removeAll(collectionsByName);
}
@Override
public void addCollection(Collect collection) {
this.collections.add(collection);
}
// endregion
// region PUT
public void addCollection(Collection collection){
this.collections.add(collection);
}
public void addCollections(List<Collection> collections){
public void addCollections(List<Collect> collections){
this.collections.addAll(collections);
}
// endregion
// region POST
public void modifyCollectionName(Collection collection, String name){
public void modifyCollectionName(Collect collection, String name){
collection.setName(name);
}
public void modifyCollectionNameById(long isbn, String name){
Collection collection = getCollectionById(isbn);
Collect collection = getCollectionById(isbn);
modifyCollectionName(collection,name);
}
// endregion
// endregion
// region Article
public List<Article> getAllArticles(Collection collection){
return collection.getAllArticles;
public List<Article> getAllArticles(Collect collect){
return collect.getAllArticles();
}
public void addArticle(Collection collection, Article article){
collection.addArticle
public void addArticle(Collect collect, Article article){
collect.addArticle(article);
}
public void deleteArticle(Collection collection, Article article){
collection.deleteArticle(article);
public void deleteArticle(Collect collect, Article article){
collect.removeArticle(article);
}
// endregion
}

@ -17,8 +17,8 @@ public class TeacherServiceStub implements ITeacherService {
public List<Teacher> getAllTeacher() {
List<Teacher> allTeacher = new ArrayList<Teacher>();
allTeacher.add(new Teacher(1, LocalDate.parse("12-01-2023", DateTimeFormatter.ISO_DATE), "aline.alipres@gmail.com", "MsGarconManque"));
allTeacher.add(new Teacher(2, LocalDate.parse("20-08-2023", DateTimeFormatter.ISO_DATE), "Viviane.Delvecchio@gmail.com", "MmeMath"));
allTeacher.add(new Teacher(1, "12-01-2023", "aline.alipres@gmail.com", "MsGarconManque"));
allTeacher.add(new Teacher(2, "20-08-2023", "Viviane.Delvecchio@gmail.com", "MmeMath"));
return allTeacher;
}
@ -41,7 +41,7 @@ public class TeacherServiceStub implements ITeacherService {
}
@Override
public Teacher getTeacherByDate(LocalDate date) {
public Teacher getTeacherByDate(String date) {
return new Teacher(5, date, "doudouda@gmail.com", "username");
}
@ -56,8 +56,8 @@ public class TeacherServiceStub implements ITeacherService {
public List<Teacher> deleteTeacher(int id) {
List<Teacher> allTeacher = new ArrayList<Teacher>();
allTeacher.add(new Teacher(1, LocalDate.parse("12-01-2023", DateTimeFormatter.ISO_DATE), "aline.alipres@gmail.com", "MsGarconManque"));
allTeacher.add(new Teacher(2, LocalDate.parse("20-08-2023", DateTimeFormatter.ISO_DATE), "Viviane.Delvecchio@gmail.com", "MmeMath"));
allTeacher.add(new Teacher(1,"12-01-2023", "aline.alipres@gmail.com", "MsGarconManque"));
allTeacher.add(new Teacher(2, "20-08-2023", "Viviane.Delvecchio@gmail.com", "MmeMath"));
allTeacher.remove(getTeacherById(id));
return allTeacher;

Loading…
Cancel
Save