diff --git a/WebService/pom.xml b/WebService/pom.xml index 0ed24c0..0f7f3be 100644 --- a/WebService/pom.xml +++ b/WebService/pom.xml @@ -1,7 +1,7 @@ -import org.springframework.web.bind.annotation.*; +<<<<<<< HEAD + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot @@ -28,6 +28,45 @@ import org.springframework.web.bind.annotation.*; 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 + + 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 + + + + org.springframework.boot + spring-boot-starter-web + + + jakarta.persistence + jakarta.persistence-api + + +>>>>>>> origin/feature/response org.springframework.boot diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/Response.java b/WebService/src/main/java/SAE/ApiREST/WebService/Response.java new file mode 100644 index 0000000..760d292 --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/Response.java @@ -0,0 +1,30 @@ +package SAE.ApiREST.WebService; + +public class Response { + + Integer id; + String statusMessage; + + public Response() {} + + public Response(Integer id, String statusMessage) { + this.id = id; + this.statusMessage = statusMessage; + } + + public Integer getId() { + return this.id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getStatusMessage() { + return this.statusMessage; + } + + public void setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + } +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java b/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java new file mode 100644 index 0000000..4449e34 --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java @@ -0,0 +1,165 @@ +package SAE.ApiREST.WebService.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import SAE.ApiREST.WebService.exception.ArticleException; +import SAE.ApiREST.WebService.model.Article; +import SAE.ApiREST.WebService.service.IArticleService; + +import java.util.ArrayList; +import java.util.List; + +@Controller +@RequestMapping("/ArticleWebService") +public class ArticleControler { + @Autowired + IArticleService articleService; + + // region POST + + // endregion + + // region PUT + + // endregion + + // region GET + + @GetMapping(value = "/getAllArticle", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getAllArticles() { + ArrayList
results = (ArrayList
) articleService.getAllArticles(); + + if(results.isEmpty()) { + throw new ArticleException("No articles available"); + } + + return results; + } + + @GetMapping(value = "/getArticleById/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody Article getArticlesById(@PathVariable(value = "id") Integer id) { + Article results = articleService.getArticlesById(id); + + if(results == null) { + throw new ArticleException("Undefined id"); + } + + return results; + } + + @GetMapping(value = "/getArticlesByTitle/{title}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getArticlesByTitle(@PathVariable(value = "title") String title) { + ArrayList
results = (ArrayList
) articleService.getArticlesByTitle(title); + + if(results.isEmpty()) { + throw new ArticleException("Undefined title"); + } + + return results; + } + + @GetMapping(value = "/getArticlesByType/{type}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getArticlesByType(@PathVariable(value = "type") Integer type) { + ArrayList
results = (ArrayList
) articleService.getArticlesByType(type); + + if (results.isEmpty()) { + throw new ArticleException(String.format("No content of type %d", type)); + } + + return results; + } + + @GetMapping(value = "/getVisibleArticles", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getVisibleArticles() { + ArrayList
results = (ArrayList
) articleService.getVisibleArticles(); + + if (results.isEmpty()) { + throw new ArticleException("No visible article"); + } + + return results; + } + + @GetMapping(value = "/getInvisibleArticles", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getInvisibleArticles() { + ArrayList
results = (ArrayList
) articleService.getInvisibleArticles(); + + if (results.isEmpty()) { + throw new ArticleException("No invisible article"); + } + + return results; + } + + @GetMapping(value = "/getArticlesAddedBefore/{dateAdded}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getArticlesAddedBefore(@PathVariable(value = "dateAdded") String dateAdded) { + ArrayList
results = (ArrayList
) articleService.getArticlesAddedBefore(dateAdded); + + if (results.isEmpty()) { + throw new ArticleException(String.format("No article added before %t", dateAdded)); + } + return results; + } + + @GetMapping(value = "/getArticlesAddedAfter/{dateAdded}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getArticlesAddedAfter(@PathVariable(value = "dateAdded") String dateAdded) { + ArrayList
results = (ArrayList
) articleService.getArticlesAddedAfter(dateAdded); + + if (results.isEmpty()) { + throw new ArticleException(String.format("No article added after %t", dateAdded)); + } + return results; + } + + @GetMapping(value = "/getArticlesAddedBetween/{beginning}/{end}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getArticlesAddedAfter(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) { + ArrayList
results = (ArrayList
) articleService.getArticlesAddedBetween(beginning, end); + + if (results.isEmpty()) { + throw new ArticleException(String.format("No article added between %t and %t", beginning, end)); + } + return results; + } + + @GetMapping(value = "/getArticlesPublishedBefore/{datePublished}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getArticlesPublishedBefore(@PathVariable(value = "datePublished") String datePublished) { + ArrayList
results = (ArrayList
) articleService.getArticlesPublishedBefore(datePublished); + + if (results.isEmpty()) { + throw new ArticleException(String.format("No article published before %t", datePublished)); + } + + return results; + } + + @GetMapping(value = "/getArticlesPublishedAfter/{datePublished}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getArticlesPublishedAfter(@PathVariable(value = "datePublished") String datePublished) { + ArrayList
results = (ArrayList
) articleService.getArticlesPublishedAfter(datePublished); + + if (results.isEmpty()) { + throw new ArticleException(String.format("No article published after %t", datePublished)); + } + + return results; + } + + @GetMapping(value = "/getArticlesPublishedBetween/{beginning}/{end}", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody List
getArticlesPublishedAfter(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) { + ArrayList
results = (ArrayList
) articleService.getArticlesPublishedBetween(beginning, end); + + if (results.isEmpty()) { + throw new ArticleException(String.format("No article published between %t and %t", beginning, end)); + } + + return results; + } + + // endregion + + // region DELETE + + // endregion +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectController.java b/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectController.java new file mode 100644 index 0000000..99b3545 --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/controller/CollectController.java @@ -0,0 +1,16 @@ +package SAE.ApiREST.WebService.controller; + +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; + +@Controller + @RequestMapping("/CollectWebService") + public class CollectController { + + } + diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/controller/TeacherController.java b/WebService/src/main/java/SAE/ApiREST/WebService/controller/TeacherController.java new file mode 100644 index 0000000..5d44e1b --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/controller/TeacherController.java @@ -0,0 +1,40 @@ +package SAE.ApiREST.WebService.controller; + +import SAE.ApiREST.WebService.model.Teacher; +import SAE.ApiREST.WebService.service.ITeacherService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.print.attribute.standard.Media; +import java.awt.*; +import java.util.List; + +@Controller +@RequestMapping("/ProfWebService") +public class TeacherController { + @Autowired + private ITeacherService iTeacherServ; + + + public TeacherController(ITeacherService iserv) { + this.iTeacherServ = iserv; + } + + @GetMapping(value = "/all", produces = MediaType.APPLICATION_JSON_VALUE) + @ResponseStatus(HttpStatus.OK) + public List getAllTeacher(){ + return iTeacherServ.getAllTeacher(); + } + + @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + @ResponseStatus(HttpStatus.CREATED) + public Teacher createTeacher( @RequestBody Teacher teach){ + return teach; + } + + //@GetMapping(value = "/{id}") + //public +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/exception/ArticleAdvice.java b/WebService/src/main/java/SAE/ApiREST/WebService/exception/ArticleAdvice.java new file mode 100644 index 0000000..9e57124 --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/exception/ArticleAdvice.java @@ -0,0 +1,17 @@ +package SAE.ApiREST.WebService.exception; + +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.http.HttpStatus; + +@ControllerAdvice +public class ArticleAdvice { + @ResponseBody + @ExceptionHandler(ArticleException.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + String articleHandler(ArticleException ex) { + return ex.getMessage(); + } +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/exception/ArticleException.java b/WebService/src/main/java/SAE/ApiREST/WebService/exception/ArticleException.java new file mode 100644 index 0000000..9de657d --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/exception/ArticleException.java @@ -0,0 +1,7 @@ +package SAE.ApiREST.WebService.exception; + +public class ArticleException extends RuntimeException { + public ArticleException(String exception) { + super(exception); + } +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/model/Article.java b/WebService/src/main/java/SAE/ApiREST/WebService/model/Article.java new file mode 100644 index 0000000..dc3876f --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/model/Article.java @@ -0,0 +1,104 @@ +package SAE.ApiREST.WebService.model; + + +import java.time.LocalDate; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Article { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) +<<<<<<< HEAD + +======= + String id; +>>>>>>> origin/feature/response + String title; + String URL; + LocalDate dateAdded; + LocalDate datePublished; + Boolean isVisible; + Integer type; + // ArrayList keywords = new ArrayList<>(); + + public Article() {} + + public Article(String title, String URL, LocalDate dateAdded, LocalDate datePublished, Boolean visibility, Integer type) { + this.id = "1"; + this.title = title; + this.URL = URL; + this.dateAdded = dateAdded; + this.datePublished = datePublished; + this.isVisible = visibility; + this.type = type; + } + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getURL() { + return this.URL; + } + + public void setURL(String URL) { + this.URL = URL; + } + + public LocalDate getDateAdded() { + return this.dateAdded; + } + + public void setDateAdded(LocalDate dateAdded) { + this.dateAdded = dateAdded; + } + + public LocalDate getDatePublished() { + return this.datePublished; + } + + public void setDatePublished(LocalDate datePublished) { + this.datePublished = datePublished; + } + + public Boolean isVisible() { + return this.isVisible; + } + + public void setVisibility(Boolean isVisible) { + this.isVisible = isVisible; + } + + public Integer getType() { + return this.type; + } + + public void setType(Integer type) { + this.type = type; + } +/* + public List getKeywords() { + return this.keywords; + } + + public void setKeywords(List keywords) { + this.keywords = keywords; + } +*/ +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/model/Collection.java b/WebService/src/main/java/SAE/ApiREST/WebService/model/Collect.java similarity index 74% rename from WebService/src/main/java/SAE/ApiREST/WebService/model/Collection.java rename to WebService/src/main/java/SAE/ApiREST/WebService/model/Collect.java index bf1f6dc..2c8e85e 100644 --- a/WebService/src/main/java/SAE/ApiREST/WebService/model/Collection.java +++ b/WebService/src/main/java/SAE/ApiREST/WebService/model/Collect.java @@ -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
articles + private ArrayList
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
(); } + public Collect() { + } + // region Article public long getId(){ return isbn; diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/model/Teacher.java b/WebService/src/main/java/SAE/ApiREST/WebService/model/Teacher.java new file mode 100644 index 0000000..a121920 --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/model/Teacher.java @@ -0,0 +1,60 @@ +package SAE.ApiREST.WebService.model; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Date; + +@Entity + +public class Teacher { + @Id + private Integer id; + private LocalDate date; + private String mail; + private String username; + + public Teacher() { + + } + + public Teacher(Integer id, String date, String mail, String username) { + this.id = id; + this.date = LocalDate.parse(date, DateTimeFormatter.ISO_DATE); + this.mail = mail; + this.username = username; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public LocalDate getDate() { + return date; + } + + public void setDate(LocalDate date) { + this.date = date; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/IArticleService.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/IArticleService.java new file mode 100644 index 0000000..427d987 --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/IArticleService.java @@ -0,0 +1,24 @@ +package SAE.ApiREST.WebService.service; + +import java.util.List; + +import SAE.ApiREST.WebService.model.Article; + +public interface IArticleService { + + // region GET + public List
getAllArticles(); + Article getArticlesById(Integer id); + public List
getArticlesByTitle(String title); + public List
getArticlesByType(Integer type); + public List
getVisibleArticles(); + public List
getInvisibleArticles(); + public List
getArticlesAddedBefore(String dateAdded); + public List
getArticlesAddedAfter(String dateAdded); + public List
getArticlesAddedBetween(String beginning, String end); + public List
getArticlesPublishedBefore(String datePublished); + public List
getArticlesPublishedAfter(String datePublished); + public List
getArticlesPublishedBetween(String beginning, String end); + // endregion + +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/ICollectionService.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/ICollectionService.java index 6b82362..8e3cec6 100644 --- a/WebService/src/main/java/SAE/ApiREST/WebService/service/ICollectionService.java +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/ICollectionService.java @@ -1,15 +1,21 @@ +package SAE.ApiREST.WebService.service; +import SAE.ApiREST.WebService.model.Collect; +import SAE.ApiREST.WebService.model.Article; + +import java.util.List; + public interface ICollectionService{ - public List getAllCollections(); - public Collection getCollectionById(long isbn); - public List getAllCollectionsByName(String name); + public List getAllCollections(); + public Collect getCollectionById(long isbn); + public List 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); - public void modifyCollectionName(Collection collection, String name); + public void addCollection(Collect collection); + public void addCollections(List collection); + public void modifyCollectionName(Collect collection, String name); public void modifyCollectionNameById(long isbn, String name); - public List
getAllArticles(Collection collection); - public void addArticle(Collection collection, Article article); - public void deleteArticle(Collection collection, Article article); + public List
getAllArticles(Collect collection); + public void addArticle(Collect collection, Article article); + public void deleteArticle(Collect collection, Article article); } \ No newline at end of file diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/ITeacherService.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/ITeacherService.java new file mode 100644 index 0000000..329a2de --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/ITeacherService.java @@ -0,0 +1,21 @@ +package SAE.ApiREST.WebService.service; + +import SAE.ApiREST.WebService.model.Teacher; + +import java.time.LocalDate; +import java.util.List; + +public interface ITeacherService { + + //Todo() by id, by mail, by username, allProf, by date (order), suppression, ajout, FAIRE DES REGIONS! + public List getAllTeacher(); + + Teacher getTeacherById(Integer id); + + public Teacher getTeacherByUsername(String username); + public Teacher getTeacherByMail(String mail); + public Teacher getTeacherByDate(String date); + public List addTeacher(Teacher t); + + public List deleteTeacher(Integer id); +} diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/StubArticleService.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubArticleService.java new file mode 100644 index 0000000..2ea238a --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubArticleService.java @@ -0,0 +1,227 @@ +package SAE.ApiREST.WebService.service; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Service; + +import SAE.ApiREST.WebService.model.Article; + +@Service +public class StubArticleService implements IArticleService { + + // region GET + @Override + public List
getAllArticles() { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "toi", + "azezeaea", + LocalDate.now().minusMonths(1), + LocalDate.now().minusMonths(2), + true, + 1) + ); + articles.add(new Article( + "moi", + "zaeaeaeazeza", + LocalDate.now().minusMonths(2), + LocalDate.now().minusMonths(3), + false, + 1) + ); + articles.add(new Article( + "eux", + "erfdhdh", + LocalDate.now().minusMonths(3), + LocalDate.now().minusMonths(4), + true, + 1) + ); + articles.add(new Article( + "tout ceux qui le veulent", + "azersdfgg", + LocalDate.now().minusMonths(4), + LocalDate.now().minusMonths(5), + false, + 2) + ); + + return articles; + } + + @Override + public Article getArticlesById(Integer id) { + return new Article( + "azeaeaze", + "azezeaea", + LocalDate.now().minusMonths(1), + LocalDate.now().minusMonths(2), + true, + 1); + } + + @Override + public List
getArticlesByTitle(String title) { + List
articles = new ArrayList<>(); + + articles.add(new Article( + title, + "azezeaea", + LocalDate.now().minusMonths(1), + LocalDate.now().minusMonths(2), + true, + 1) + ); + + return articles; + } + + @Override + public List
getArticlesByType(Integer type) { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "aeazeazeaz", + "azezeaea", + LocalDate.now().minusMonths(1), + LocalDate.now().minusMonths(2), + true, + type) + ); + + return articles; + } + + @Override + public List
getVisibleArticles() { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "toi", + "azezeaea", + LocalDate.now().minusMonths(1), + LocalDate.now().minusMonths(2), + true, + 1) + ); + + return articles; + } + + @Override + public List
getInvisibleArticles() { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "toi", + "azezeaea", + LocalDate.now().minusMonths(1), + LocalDate.now().minusMonths(2), + false, + 1) + ); + + return articles; + } + + @Override + public List
getArticlesAddedBefore(String dateAdded) { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "toi", + "azezeaea", + LocalDate.parse(dateAdded, DateTimeFormatter.ISO_DATE).minusMonths(1), + LocalDate.now().minusMonths(2), + true, + 1) + ); + + return articles; + } + + @Override + public List
getArticlesAddedAfter(String dateAdded) { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "toi", + "azezeaea", + LocalDate.parse(dateAdded, DateTimeFormatter.ISO_DATE).plusMonths(1), + LocalDate.now().minusMonths(2), + true, + 1) + ); + + return articles; + } + + @Override + public List
getArticlesAddedBetween(String beginning, String end) { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "toi", + "azezeaea", + LocalDate.parse(beginning, DateTimeFormatter.ISO_DATE), + LocalDate.now().minusMonths(2), + true, + 1) + ); + + return articles; + } + + @Override + public List
getArticlesPublishedBefore(String datePublished) { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "toi", + "azezeaea", + LocalDate.now().minusMonths(1), + LocalDate.parse(datePublished, DateTimeFormatter.ISO_DATE).plusMonths(2), + true, + 1) + ); + + return articles; + } + + @Override + public List
getArticlesPublishedAfter(String datePublished) { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "toi", + "azezeaea", + LocalDate.now().minusMonths(1), + LocalDate.parse(datePublished, DateTimeFormatter.ISO_DATE).plusMonths(2), + true, + 1) + ); + + return articles; + } + + @Override + public List
getArticlesPublishedBetween(String beginning, String end) { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "toi", + "azezeaea", + LocalDate.now().minusMonths(1), + LocalDate.parse(end, DateTimeFormatter.ISO_DATE), + true, + 1) + ); + + return articles; + } + // endregion +} 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 320d08c..3c8d9f8 100644 --- a/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubCollectionService.java @@ -1,41 +1,41 @@ package SAE.ApiREST.WebService.service; +import SAE.ApiREST.WebService.model.Collect; -import java.sql.Date; import java.util.ArrayList; import java.util.List; -import org.springframework.stereotype.Service; - import SAE.ApiREST.WebService.model.Article; +import org.springframework.stereotype.Service; import SAE.ApiREST.WebService.model.Collection; @Service -public class CollectionService implements ICollectionService { - private ArrayList collections; - - @Override - public List getAllCollections() { +public class StubCollectionService implements ICollectionService { + private ArrayList collections; + public List getAllCollections() { return this.collections; } // region Collection // region GET - @Override - public Collection getCollectionById(long isbn){ - for(Collection collection : this.collections){ + public Collect getCollectionById(long isbn){ + for(Collect collection : this.collections){ if(collection.getId() == isbn) { return collection; } } return null; } - + @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){ + ArrayList repCollections = new ArrayList(); + for(Collect collection : this.collections){ + if(collection.getName() == name) { repCollections.add(collection); } } @@ -43,66 +43,59 @@ public class CollectionService implements ICollectionService { } // endregion - // region DELETE + // region DELETE @Override public void deleteColletionById(long isbn){ - Collection collection = getCollectionById(isbn); + Collect collection = getCollectionById(isbn); this.collections.remove(collection); } - + @Override public void deleteColletionByName(String name){ - ArrayList collectionsByName = getAllCollectionsByName(name); - this.collections.remove(collectionsByName[0]); + List collectionsByName = getAllCollectionsByName(name); + this.collections.remove(collectionsByName.get(0)); } @Override public void deleteAllColletionByName(String name){ - ArrayList collectionsByName = getAllCollectionsByName(name); + List collectionsByName = getAllCollectionsByName(name); this.collections.removeAll(collectionsByName); } - // endregion - // region PUT @Override - public void addCollection(Collection collection){ - this.collections.add(collection); + public void addCollection(Collect collection) { + this.collections.add(collection); } + // endregion - @Override - public void addCollections(List collections){ + // region PUT + public void addCollections(List collections){ this.collections.addAll(collections); } // endregion // region POST - @Override - public void modifyCollectionName(Collection collection, String name){ + public void modifyCollectionName(Collect collection, String name){ collection.setName(name); } @Override public void modifyCollectionNameById(long isbn, String name){ - Collection collection = getCollectionById(isbn); + Collect collection = getCollectionById(isbn); modifyCollectionName(collection,name); } // endregion // endregion // region Article - @Override - public List
getAllArticles(Collection collection){ - return collection.getAllArticles; + public List
getAllArticles(Collect collect){ + return collect.getAllArticles(); } - - @Override - public void addArticle(Collection collection, Article article){ - collection.addArticle + public void addArticle(Collect collect, Article article){ + collect.addArticle(article); } - - @Override - public void deleteArticle(Collection collection, Article article){ - collection.deleteArticle(article); + public void deleteArticle(Collect collect, Article article){ + collect.removeArticle(article); } // endregion } \ No newline at end of file diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/TeacherServiceStub.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/TeacherServiceStub.java new file mode 100644 index 0000000..0b494f8 --- /dev/null +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/TeacherServiceStub.java @@ -0,0 +1,65 @@ +package SAE.ApiREST.WebService.service; + +import SAE.ApiREST.WebService.model.Teacher; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class TeacherServiceStub implements ITeacherService { + + //todo() recevoir collections, ajouter collections, supprimer collections + @Override + public List getAllTeacher() { + List allTeacher = new ArrayList(); + + 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; + } + + + + @Override + public Teacher getTeacherById(Integer id) { + return new Teacher(id, "10-01-2021", "exemple.gmail.com", "testest"); + } + + @Override + public Teacher getTeacherByUsername(String username) { + return new Teacher(12, "30-08-2020", "dadadou@gmail.com", username); + } + + @Override + public Teacher getTeacherByMail(String mail) { + return new Teacher(20, "24-12-2021", mail, "tructruc"); + } + + @Override + public Teacher getTeacherByDate(String date) { + return new Teacher(5, date, "doudouda@gmail.com", "username"); + } + + @Override + public List addTeacher(Teacher t) { + List lteach = new ArrayList(); + lteach.add(t); + return lteach; + } + + @Override + public List deleteTeacher(Integer id) { + List allTeacher = new ArrayList(); + + 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; + } +}