Compare commits

...

16 Commits

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="WebService" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="WebService" options="-parameters" />
</option>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/WebService/src/main/java" charset="UTF-8" />
</component>
</project>

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/WebService/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="liberica-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Api_Rest_VWeb.iml" filepath="$PROJECT_DIR$/.idea/Api_Rest_VWeb.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -1,44 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>WebService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>tp2</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
</dependencies>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>WebService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>tp2</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

@ -0,0 +1,26 @@
package SAE.ApiREST.WebService.Wrapper;
import SAE.ApiREST.WebService.model.Article;
import SAE.ApiREST.WebService.model.Collect;
public class ArticleCollect {
private Collect collection;
private Article article;
public ArticleCollect() {}
public ArticleCollect(Collect collection, Article article) {
this.collection = collection;
this.article = article;
}
public Collect getCollection() {
return collection;
}
public Article getNewArticle() {
return article;
}
// Setters if necessary
}

@ -0,0 +1,25 @@
package SAE.ApiREST.WebService.Wrapper;
import SAE.ApiREST.WebService.model.Collect;
public class CollectionName {
private Collect collection;
private String newName;
public CollectionName() {}
public CollectionName(Collect collection, String newName) {
this.collection = collection;
this.newName = newName;
}
public Collect getCollection() {
return collection;
}
public String getNewName() {
return newName;
}
// Setters if necessary
}

@ -1,16 +1,21 @@
package SAE.ApiREST.WebService.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import SAE.ApiREST.WebService.Response;
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;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@Controller
@RequestMapping("/ArticleWebService")
@ -19,147 +24,561 @@ public class ArticleControler {
IArticleService articleService;
// region POST
@PostMapping(
value = "/addArticle",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> addArticle(
@RequestBody Article article
) {
Response results = articleService.addArticle(article);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).addArticle(article)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("allArticles"),
linkTo(methodOn(ArticleControler.class).getArticleById(article.getId())).withRel("getArticleById"),
linkTo(methodOn(ArticleControler.class).deleteArticleFromId(article.getId())).withRel("deleteArticle")
);
}
// endregion
// region PUT
@PutMapping(
value = "/updateTitle/{title}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Article> updateTitle(
@PathVariable("title") String title,
@RequestBody Article article
) {
Article results = articleService.updateTitle(article, title);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).updateTitle(title, article)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("allArticles"),
linkTo(methodOn(ArticleControler.class).getArticleById(article.getId())).withRel("getArticleById"),
linkTo(methodOn(ArticleControler.class).getArticlesByTitle(article.getTitle())).withRel("getArticlesByTitle"),
linkTo(methodOn(ArticleControler.class).deleteArticleFromId(article.getId())).withRel("deleteArticle")
);
}
@PutMapping(
value = "/updateUrl/{url}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Article> updateUrl(
@PathVariable("url") String url,
@RequestBody Article article
) {
Article results = articleService.updateUrl(article, url);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).updateUrl(url, article)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("allArticles"),
linkTo(methodOn(ArticleControler.class).getArticleById(article.getId())).withRel("getArticleById"),
linkTo(methodOn(ArticleControler.class).getArticlesByUrl(article.getUrl())).withRel("getArticlesByUrl"),
linkTo(methodOn(ArticleControler.class).deleteArticleFromId(article.getId())).withRel("deleteArticle")
);
}
@PutMapping(
value = "/updateDatePublished/{datePublished}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Article> updateDatePublished(
@PathVariable("datePublished") String datePublished,
@RequestBody Article article
) {
Article results = articleService.updateDatePublished(article, datePublished);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).updateDatePublished(datePublished, article)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("allArticles"),
linkTo(methodOn(ArticleControler.class).getArticleById(article.getId())).withRel("getArticleById"),
linkTo(methodOn(ArticleControler.class).getArticlesPublishedBefore(article.getDatePublished().toString())).withRel("getArticlesPublishedBefore"),
linkTo(methodOn(ArticleControler.class).getArticlesPublishedAfter(article.getDatePublished().toString())).withRel("getArticlesPublishedAfter"),
linkTo(methodOn(ArticleControler.class).deleteArticleFromId(article.getId())).withRel("deleteArticle")
);
}
@PutMapping(
value = "/updateDateAdded/{dateAdded}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Article> updateDateAdded(
@PathVariable("dateAdded") String dateAdded,
@RequestBody Article article
) {
Article results = articleService.updateDateAdded(article, dateAdded);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).updateDateAdded(dateAdded, article)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("allArticles"),
linkTo(methodOn(ArticleControler.class).getArticleById(article.getId())).withRel("getArticleById"),
linkTo(methodOn(ArticleControler.class).getArticlesAddedBefore(article.getDateAdded().toString())).withRel("getArticlesAddedBefore"),
linkTo(methodOn(ArticleControler.class).getArticlesAddedAfter(article.getDateAdded().toString())).withRel("getArticlesAddedAfter"),
linkTo(methodOn(ArticleControler.class).deleteArticleFromId(article.getId())).withRel("deleteArticle")
);
}
@PutMapping(
value = "/changeVisibility",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Article> changeVisibility(
@RequestBody Article article
) {
Article results = articleService.changeVisibility(article);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).changeVisibility(article)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("allArticles"),
linkTo(methodOn(ArticleControler.class).getArticleById(article.getId())).withRel("getArticleById"),
linkTo(methodOn(ArticleControler.class).getVisibleArticles()).withRel("getVisibleArticle"),
linkTo(methodOn(ArticleControler.class).getInvisibleArticles()).withRel("getInvisibleArticle"),
linkTo(methodOn(ArticleControler.class).deleteArticleFromId(article.getId())).withRel("deleteArticle")
);
}
@PutMapping(
value = "/updateType/{type}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Article> updateType(
@PathVariable("type") Integer type,
@RequestBody Article article
) {
Article results = articleService.updateType(article, type);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).updateType(type, article)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("allArticles"),
linkTo(methodOn(ArticleControler.class).getArticleById(article.getId())).withRel("getArticleById"),
linkTo(methodOn(ArticleControler.class).getArticlesByType(article.getType())).withRel("getArticlesByType"),
linkTo(methodOn(ArticleControler.class).deleteArticleFromId(article.getId())).withRel("deleteArticle")
);
}
// endregion
// region GET
@GetMapping(value = "/getAllArticle", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getAllArticles() {
@GetMapping(
value = "/getAllArticle",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getAllArticles() {
ArrayList<Article> results = (ArrayList<Article>) articleService.getAllArticles();
if(results.isEmpty()) {
throw new ArticleException("No articles available");
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getAllArticles()).withSelfRel()
);
}
@GetMapping(value = "/getArticleById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Article getArticlesById(@PathVariable(value = "id") Integer id) {
@GetMapping(
value = "/getArticleById/{id}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Article> getArticleById(@PathVariable(value = "id") Integer id) {
Article results = articleService.getArticlesById(id);
if(results == null) {
throw new ArticleException("Undefined id");
}
return results;
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticleById(id)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleFromId(id)).withRel("deleteArticleFromUrl")
);
}
@GetMapping(value = "/getArticlesByTitle/{title}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getArticlesByTitle(@PathVariable(value = "title") String title) {
@GetMapping(
value = "/getArticlesByTitle/{title}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getArticlesByTitle(@PathVariable(value = "title") String title) {
ArrayList<Article> results = (ArrayList<Article>) articleService.getArticlesByTitle(title);
if(results.isEmpty()) {
throw new ArticleException("Undefined title");
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesByTitle(title)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleFromTitle(title)).withRel("deleteArticleFromTitle")
);
}
@GetMapping(
value = "/getArticlesByUrl/{url}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getArticlesByUrl(@PathVariable(value = "url") String url) {
ArrayList<Article> results = (ArrayList<Article>) articleService.getArticlesByUrl(url);
if(results.isEmpty()) {
throw new ArticleException("Undefined title");
}
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesByUrl(url)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleFromUrl(url)).withRel("deleteArticleFromId")
);
}
@GetMapping(value = "/getArticlesByType/{type}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getArticlesByType(@PathVariable(value = "type") Integer type) {
@GetMapping(
value = "/getArticlesByType/{type}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getArticlesByType(@PathVariable(value = "type") Integer type) {
ArrayList<Article> results = (ArrayList<Article>) articleService.getArticlesByType(type);
if (results.isEmpty()) {
throw new ArticleException(String.format("No content of type %d", type));
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesByType(type)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleFromType(type)).withRel("deleteArticleFromType")
);
}
@GetMapping(value = "/getVisibleArticles", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getVisibleArticles() {
@GetMapping(
value = "/getVisibleArticles",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getVisibleArticles() {
ArrayList<Article> results = (ArrayList<Article>) articleService.getVisibleArticles();
if (results.isEmpty()) {
throw new ArticleException("No visible article");
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getVisibleArticles()).withSelfRel()
);
}
@GetMapping(value = "/getInvisibleArticles", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getInvisibleArticles() {
@GetMapping(
value = "/getInvisibleArticles",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getInvisibleArticles() {
ArrayList<Article> results = (ArrayList<Article>) articleService.getInvisibleArticles();
if (results.isEmpty()) {
throw new ArticleException("No invisible article");
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getInvisibleArticles()).withSelfRel()
);
}
@GetMapping(value = "/getArticlesAddedBefore/{dateAdded}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getArticlesAddedBefore(@PathVariable(value = "dateAdded") String dateAdded) {
@GetMapping(
value = "/getArticlesAddedBefore/{dateAdded}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getArticlesAddedBefore(@PathVariable(value = "dateAdded") String dateAdded) {
ArrayList<Article> results = (ArrayList<Article>) articleService.getArticlesAddedBefore(dateAdded);
if (results.isEmpty()) {
throw new ArticleException(String.format("No article added before %t", dateAdded));
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesAddedBefore(dateAdded)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleAddedBefore(dateAdded)).withRel("deleteArticleAddedBefore")
);
}
@GetMapping(value = "/getArticlesAddedAfter/{dateAdded}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getArticlesAddedAfter(@PathVariable(value = "dateAdded") String dateAdded) {
@GetMapping(
value = "/getArticlesAddedAfter/{dateAdded}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getArticlesAddedAfter(@PathVariable(value = "dateAdded") String dateAdded) {
ArrayList<Article> results = (ArrayList<Article>) articleService.getArticlesAddedAfter(dateAdded);
if (results.isEmpty()) {
throw new ArticleException(String.format("No article added after %t", dateAdded));
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesAddedAfter(dateAdded)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleAddedAfter(dateAdded)).withRel("deleteArticleAddedAfter")
);
}
@GetMapping(value = "/getArticlesAddedBetween/{beginning}/{end}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getArticlesAddedAfter(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) {
@GetMapping(
value = "/getArticlesAddedBetween/{beginning}/{end}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getArticlesAddedBetween(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) {
ArrayList<Article> results = (ArrayList<Article>) articleService.getArticlesAddedBetween(beginning, end);
if (results.isEmpty()) {
throw new ArticleException(String.format("No article added between %t and %t", beginning, end));
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesAddedBetween(beginning, end)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleAddedBetween(beginning, end)).withRel("deleteArticleAddedBetween")
);
}
@GetMapping(value = "/getArticlesPublishedBefore/{datePublished}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getArticlesPublishedBefore(@PathVariable(value = "datePublished") String datePublished) {
@GetMapping(
value = "/getArticlesPublishedBefore/{datePublished}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getArticlesPublishedBefore(@PathVariable(value = "datePublished") String datePublished) {
ArrayList<Article> results = (ArrayList<Article>) articleService.getArticlesPublishedBefore(datePublished);
if (results.isEmpty()) {
throw new ArticleException(String.format("No article published before %t", datePublished));
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesPublishedBefore(datePublished)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticlePublishedBefore(datePublished)).withRel("deleteArticlePublishedBefore")
);
}
@GetMapping(value = "/getArticlesPublishedAfter/{datePublished}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getArticlesPublishedAfter(@PathVariable(value = "datePublished") String datePublished) {
@GetMapping(
value = "/getArticlesPublishedAfter/{datePublished}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getArticlesPublishedAfter(@PathVariable(value = "datePublished") String datePublished) {
ArrayList<Article> results = (ArrayList<Article>) articleService.getArticlesPublishedAfter(datePublished);
if (results.isEmpty()) {
throw new ArticleException(String.format("No article published after %t", datePublished));
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesPublishedAfter(datePublished)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticlePublishedAfter(datePublished)).withRel("deleteArticlePublishedAfter")
);
}
@GetMapping(value = "/getArticlesPublishedBetween/{beginning}/{end}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getArticlesPublishedAfter(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) {
@GetMapping(
value = "/getArticlesPublishedBetween/{beginning}/{end}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody CollectionModel<Article> getArticlesPublishedBetween(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) {
ArrayList<Article> results = (ArrayList<Article>) articleService.getArticlesPublishedBetween(beginning, end);
if (results.isEmpty()) {
throw new ArticleException(String.format("No article published between %t and %t", beginning, end));
}
return results;
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesPublishedBetween(beginning, end)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticlePublishedBetween(beginning, end)).withRel("getArticlesPublishedBetween")
);
}
// endregion
// region DELETE
@DeleteMapping(
value = "/deleteArticleFromId/{id}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticleFromId(
@PathVariable("id") Integer id
) {
Response results = articleService.deleteArticleFromId(id);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticleFromId(id)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticleById(id)).withRel("getArticleById")
);
}
@DeleteMapping(
value = "/deleteArticleFromTitle/{title}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticleFromTitle(
@PathVariable("title") String title
) {
Response results = articleService.deleteArticleFromTitle(title);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticleFromTitle(title)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticlesByTitle(title)).withRel("getArticleByTitle")
);
}
@DeleteMapping(
value = "/deleteArticleFromUrl/{url}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticleFromUrl(
@PathVariable("url") String url
) {
Response results = articleService.deleteArticleFromTitle(url);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticleFromUrl(url)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticlesByUrl(url)).withRel("getArticlesByUrl")
);
}
@DeleteMapping(
value = "/deleteArticleFromType/{type}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticleFromType(
@PathVariable("type") Integer type
) {
Response results = articleService.deleteArticleFromType(type);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticleFromType(type)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticlesByType(type)).withRel("getArticlesByType")
);
}
@DeleteMapping(
value = "/deleteArticleAddedBefore/{date}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticleAddedBefore(
@PathVariable("date") String date
) {
Response results = articleService.deleteArticleAddedBefore(date);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticleAddedBefore(date)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticlesAddedBefore(date)).withRel("getArticlesAddedBefore")
);
}
@DeleteMapping(
value = "/deleteArticleAddedAfter/{date}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticleAddedAfter(
@PathVariable("date") String date
) {
Response results = articleService.deleteArticleAddedAfter(date);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticleAddedAfter(date)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticlesAddedAfter(date)).withRel("getArticlesAddedAfter")
);
}
@DeleteMapping(
value = "/deleteArticleAddedBetween/{beginning}/{end}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticleAddedBetween(
@PathVariable("beginning") String beginning,
@PathVariable("end") String end
) {
Response results = articleService.deleteArticleAddedBetween(beginning, end);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticleAddedBetween(beginning, end)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticlesAddedBetween(beginning, end)).withRel("getArticlesAddedBetween")
);
}
@DeleteMapping(
value = "/deleteArticlePublishedBefore/{date}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticlePublishedBefore(
@PathVariable("date") String date
) {
Response results = articleService.deleteArticlePublishedBefore(date);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticlePublishedBefore(date)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticlesPublishedBefore(date)).withRel("getArticlesPublishedBefore")
);
}
@DeleteMapping(
value = "/deleteArticlePublishedAfter/{date}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticlePublishedAfter(
@PathVariable("date") String date
) {
Response results = articleService.deleteArticlePublishedBefore(date);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticlePublishedAfter(date)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticlesPublishedAfter(date)).withRel("getArticlesPublishedAfter")
);
}
@DeleteMapping(
value = "/deleteArticlePublishedBetween/{beginning}/{end}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<Response> deleteArticlePublishedBetween(
@PathVariable("beginning") String beginning,
@PathVariable("end") String end
) {
Response results = articleService.deleteArticlePublishedBetween(beginning, end);
return EntityModel.of(
results,
linkTo(methodOn(ArticleControler.class).deleteArticlePublishedBetween(beginning, end)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getAllArticles()).withRel("getAllArticles"),
linkTo(methodOn(ArticleControler.class).getArticlesPublishedBetween(beginning, end)).withRel("getArticlesPublishedBetween")
);
}
// endregion
}

@ -1,16 +1,240 @@
package SAE.ApiREST.WebService.controller;
import SAE.ApiREST.WebService.Wrapper.ArticleCollect;
import SAE.ApiREST.WebService.Wrapper.CollectionName;
import SAE.ApiREST.WebService.exception.ArticleException;
import SAE.ApiREST.WebService.exception.CollectException;
import SAE.ApiREST.WebService.model.Article;
import SAE.ApiREST.WebService.model.Collect;
import SAE.ApiREST.WebService.service.ICollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.Link;
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;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@Controller
@RequestMapping("/CollectWebService")
public class CollectController {
@RequestMapping("/CollectWebService")
public class CollectController {
@Autowired
ICollectionService collectionService;
public CollectController() {
}
// region Collection
// region GET
@GetMapping(value = "/getAllCollection", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Collect> getAllCollection(){
List<Collect> results = collectionService.getAllCollections();
if(results.isEmpty()) {
throw new CollectException("No collections available");
}
return results;
}
@GetMapping(value = "/getCollectionById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody EntityModel<Collect> getCollectionById(@PathVariable(value = "id") Integer id){
Collect results = collectionService.getCollectionById(id);
if(results == null) {
throw new CollectException("No collections available");
}
return EntityModel.of(results,
linkTo(methodOn(CollectController.class).getCollectionById(id)).withSelfRel(),
linkTo(methodOn(CollectController.class).getAllArticlesById(id)
).withRel("getAllArticlesById"),
linkTo(methodOn(CollectController.class).deleteColletionById(id)
).withRel("deleteColletionById"),
linkTo(methodOn(CollectController.class).deleteAllColletionByName(results.getName())
).withRel("deleteAllColletionByName"),
linkTo(methodOn(CollectController.class).getAllCollection()
).withRel("getAllCollection"));
}
@GetMapping(value = "/getAllCollectionsByName/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody CollectionModel<EntityModel<Collect>> getAllCollectionsByName(@PathVariable(value = "name") String name){
List<Collect> results = collectionService.getAllCollectionsByName(name);
if(results.isEmpty()) {
throw new CollectException("No collections available");
}
List<EntityModel<Collect>> collectModels = results.stream()
.map(collect -> EntityModel.of(collect,
linkTo(methodOn(CollectController.class).getAllCollectionsByName(name)).withSelfRel(),
linkTo(methodOn(CollectController.class).getAllCollection()
).withRel("getAllCollection")))
.collect(Collectors.toList());
return CollectionModel.of(collectModels);
}
// endregion
// region DELETE
@DeleteMapping(value = "/deleteColletionById/{id}")
public @ResponseBody EntityModel<Link> deleteColletionById(@PathVariable("id") Integer id){
if(!collectionService.deleteColletionById(id)) {
throw new CollectException("No collections available");
}
return EntityModel.of(linkTo(methodOn(CollectController.class).getAllCollection()
).withRel("getAllCollection"));
}
@DeleteMapping(value = "/deleteColletionByName/{name}")
public @ResponseBody EntityModel<Link> deleteColletionByName(@PathVariable("name") String name){
if(!collectionService.deleteColletionByName(name)) {
throw new CollectException("No collections available");
}
return EntityModel.of(linkTo(methodOn(CollectController.class).getAllCollection()
).withRel("getAllCollection"));
}
@DeleteMapping(value = "/deleteAllColletionByName/{name}")
public @ResponseBody EntityModel<Link> deleteAllColletionByName(@PathVariable("name") String name){
if(!collectionService.deleteAllColletionByName(name)) {
throw new CollectException("No collections available");
}
return EntityModel.of(linkTo(methodOn(CollectController.class).getAllCollection()
).withRel("getAllCollection"));
}
// endregion
// region PUT
@PutMapping(value = "/addCollection")
public @ResponseBody EntityModel<Collect> addCollection(@RequestBody Collect collection){
Collect results = collectionService.addCollection(collection);
return EntityModel.of(results,
linkTo(methodOn(CollectController.class).getCollectionById(results.getId())).withSelfRel(),
linkTo(methodOn(CollectController.class).getAllArticlesById(results.getId())
).withRel("getAllArticlesById"),
linkTo(methodOn(CollectController.class).deleteColletionById(results.getId())
).withRel("deleteColletionById"),
linkTo(methodOn(CollectController.class).deleteAllColletionByName(results.getName())
).withRel("deleteAllColletionByName"),
linkTo(methodOn(CollectController.class).getAllCollection()
).withRel("getAllCollection"));
}
@PutMapping(value = "/addCollections")
public @ResponseBody CollectionModel<EntityModel<Collect>> addCollections(@RequestBody List<Collect> collections){
List<Collect> results = collectionService.addCollections(collections);
List<EntityModel<Collect>> collectModels = results.stream()
.map(collect -> EntityModel.of(collect,
linkTo(methodOn(CollectController.class).getAllCollection()).withRel("getAllCollection")))
.collect(Collectors.toList());
return CollectionModel.of(collectModels);
}
// endregion
// region POST
@PostMapping(value="/modifyCollectionName", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody EntityModel<Collect> modifyCollectionName(@RequestBody CollectionName request) {
String newName = request.getNewName();
Collect collection = request.getCollection();
if(collection == null) {
throw new ArticleException("No articles available");
}
Collect results = collectionService.modifyCollectionName(collection, newName);
// Assuming your modification logic here
return EntityModel.of(results,
linkTo(methodOn(CollectController.class).getCollectionById(results.getId())).withSelfRel(),
linkTo(methodOn(CollectController.class).getAllArticlesById(results.getId())).withRel("getAllArticlesById"),
linkTo(methodOn(CollectController.class).deleteColletionById(results.getId())).withRel("deleteColletionById"),
linkTo(methodOn(CollectController.class).deleteAllColletionByName(results.getName())).withRel("deleteAllColletionByName"),
linkTo(methodOn(CollectController.class).getAllCollection()).withRel("getAllCollection"));
}
@PostMapping(value="/modifyCollectionNameById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody EntityModel<Collect> modifyCollectionNameById(@PathVariable("id") Integer id, @RequestBody String name){
Collect results = collectionService.modifyCollectionNameById(id,name);
return EntityModel.of(results,
linkTo(methodOn(CollectController.class).getCollectionById(id)).withSelfRel(),
linkTo(methodOn(CollectController.class).getAllArticlesById(id)
).withRel("getAllArticlesById"),
linkTo(methodOn(CollectController.class).deleteColletionById(id)
).withRel("deleteColletionById"),
linkTo(methodOn(CollectController.class).deleteAllColletionByName(results.getName())
).withRel("deleteAllColletionByName"),
linkTo(methodOn(CollectController.class).getAllCollection()
).withRel("getAllCollection"));
}
// endregion
// endregion
// region Article
@GetMapping(value = "/getAllArticlesById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody CollectionModel<EntityModel<Article>> getAllArticlesById(@PathVariable(value = "id") Integer id){
List<Article> results = collectionService.getAllArticlesById(id);
if(results == null) {
throw new ArticleException("No articles available");
}
List<EntityModel<Article>> collectModels = results.stream()
.map(collect -> EntityModel.of(collect,
linkTo(methodOn(CollectController.class).getCollectionById(id)).withRel("getCollection"),
linkTo(methodOn(CollectController.class).getAllCollection()).withRel("getAllCollection")))
.collect(Collectors.toList());
return CollectionModel.of(collectModels);
}
@PutMapping(value = "/addArticle", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody EntityModel<Article> addArticle(@RequestBody ArticleCollect request) {
Article article = request.getNewArticle();
Collect collection = request.getCollection();
if(article == null) {
throw new ArticleException("Invalid article");
}
if(collection == null) {
throw new CollectException("No articles available");
}
Collect results = collectionService.addArticle(collection,article);
Article art = results.getAllArticles().get(results.getAllArticles().indexOf(article));
return EntityModel.of(art,
linkTo(methodOn(CollectController.class).getCollectionById(results.getId())).withSelfRel(),
linkTo(methodOn(TeacherController.class).getTeachById(results.getTeacher().getId())).withSelfRel(),
linkTo(methodOn(ArticleControler.class).getArticleById(art.getId())).withSelfRel(),
linkTo(methodOn(CollectController.class).getAllArticlesById(results.getId())
).withRel("getAllArticlesById"),
linkTo(methodOn(CollectController.class).deleteColletionById(results.getId())
).withRel("deleteColletionById"),
linkTo(methodOn(CollectController.class).deleteAllColletionByName(results.getName())
).withRel("deleteAllColletionByName"),
linkTo(methodOn(CollectController.class).getAllCollection()
).withRel("getAllCollection"));
}
@DeleteMapping(value = "/deleteArticle", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody EntityModel<Collect> deleteArticle(@RequestBody ArticleCollect request) {
Article article = request.getNewArticle();
Collect collection = request.getCollection();
if(article == null) {
throw new ArticleException("Invalid article");
}
if(collection == null) {
throw new CollectException("No articles available");
}
Collect results = collectionService.deleteArticle(collection,article);
return EntityModel.of(results,
linkTo(methodOn(CollectController.class).getCollectionById(results.getId())).withSelfRel(),
linkTo(methodOn(CollectController.class).getAllArticlesById(results.getId())
).withRel("getAllArticlesById"),
linkTo(methodOn(CollectController.class).deleteColletionById(results.getId())
).withRel("deleteColletionById"),
linkTo(methodOn(CollectController.class).deleteAllColletionByName(results.getName())
).withRel("deleteAllColletionByName"),
linkTo(methodOn(CollectController.class).getAllCollection()
).withRel("getAllCollection"));
}
// endregion
}

@ -1,10 +1,8 @@
package SAE.ApiREST.WebService.controller;
import SAE.ApiREST.WebService.exception.TeacherAdvice;
import SAE.ApiREST.WebService.exception.TeacherException;
import SAE.ApiREST.WebService.model.Teacher;
import SAE.ApiREST.WebService.service.ITeacherService;
import jakarta.persistence.Entity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
@ -15,7 +13,6 @@ import org.springframework.web.bind.annotation.*;
import javax.print.attribute.standard.Media;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;

@ -0,0 +1,17 @@
package SAE.ApiREST.WebService.exception;
import org.springframework.http.HttpStatus;
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;
@ControllerAdvice
public class CollectAdvice {
@ResponseBody
@ExceptionHandler(CollectException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
String collectHandler(CollectException ex) {
return ex.getMessage();
}
}

@ -0,0 +1,7 @@
package SAE.ApiREST.WebService.exception;
public class CollectException extends RuntimeException {
public CollectException(String exception) {
super(exception);
}
}

@ -2,6 +2,7 @@ package SAE.ApiREST.WebService.model;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@ -12,28 +13,36 @@ import jakarta.persistence.Id;
public class Article {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Integer id;
String title;
String URL;
String url;
LocalDate dateAdded;
LocalDate datePublished;
Boolean isVisible;
Boolean visible;
Integer type;
// ArrayList<Keyword> keywords = new ArrayList<>();
public Article() {}
public Article(String title, String URL, LocalDate dateAdded, LocalDate datePublished, Boolean visibility, Integer type) {
public Article(String title, String url, LocalDate dateAdded, LocalDate datePublished, Boolean visibility, Integer type) {
this.id = 1;
this.title = title;
this.URL = URL;
this.url = url;
this.dateAdded = dateAdded;
this.datePublished = datePublished;
this.isVisible = visibility;
this.visible = visibility;
this.type = type;
}
public Article(String title, String url, String dateAdded, String datePublished, Boolean visibility, Integer type) {
this.id = 1;
this.title = title;
this.url = url;
this.dateAdded = LocalDate.parse(dateAdded, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
this.datePublished = LocalDate.parse(datePublished, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
this.visible = visibility;
this.type = type;
}
public Integer getId() {
return this.id;
}
@ -50,36 +59,36 @@ public class Article {
this.title = title;
}
public String getURL() {
return this.URL;
public String getUrl() {
return this.url;
}
public void setURL(String URL) {
this.URL = URL;
public void setUrl(String url) {
this.url = url;
}
public LocalDate getDateAdded() {
return this.dateAdded;
}
public void setDateAdded(LocalDate dateAdded) {
this.dateAdded = dateAdded;
public void setDateAdded(String dateAdded) {
this.dateAdded = LocalDate.parse(dateAdded, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
}
public LocalDate getDatePublished() {
return this.datePublished;
}
public void setDatePublished(LocalDate datePublished) {
this.datePublished = datePublished;
public void setDatePublished(String datePublished) {
this.datePublished = LocalDate.parse(datePublished, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
}
public Boolean isVisible() {
return this.isVisible;
public Boolean getVisible() {
return this.visible;
}
public void setVisibility(Boolean isVisible) {
this.isVisible = isVisible;
public void setVisibility(Boolean visible) {
this.visible = visible;
}
public Integer getType() {

@ -7,8 +7,8 @@ import java.util.List;
@Entity
public class Collect {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private final long isbn = 0;
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@Column(name = "articles")
private ArrayList<Article> articles;
@Column(name = "name")
@ -16,18 +16,24 @@ public class Collect {
@Column(name = "teacher")
private Teacher teacher;
public Collect() {
}
public Collect(String name, Teacher teacher){
this.name = name;
this.teacher = teacher;
this.articles = new ArrayList<Article>();
}
public Collect() {
public Collect(String name, Teacher teacher, Integer id){
this.name = name;
this.teacher = teacher;
this.articles = new ArrayList<Article>();
this.id = id;
}
// region Article
public long getId(){
return isbn;
public Integer getId(){
return id;
}
// endregion
@ -67,4 +73,10 @@ public class Collect {
this.name = name;
}
// endregion
// region teacher
public Teacher getTeacher(){
return teacher;
}
// endregion
}

@ -4,7 +4,6 @@ import jakarta.persistence.Id;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
@Entity

@ -2,14 +2,29 @@ package SAE.ApiREST.WebService.service;
import java.util.List;
import SAE.ApiREST.WebService.Response;
import SAE.ApiREST.WebService.model.Article;
public interface IArticleService {
// region POST
public Response addArticle(Article article);
// endregion
// region PUT
public Article updateTitle(Article article, String title);
public Article updateUrl(Article article, String url);
public Article updateDatePublished(Article article, String datePublished);
public Article updateDateAdded(Article article, String dateAdded);
public Article changeVisibility(Article article);
public Article updateType(Article article, Integer type);
// endregion
// region GET
public List<Article> getAllArticles();
Article getArticlesById(Integer id);
public List<Article> getArticlesByTitle(String title);
public List<Article> getArticlesByUrl(String url);
public List<Article> getArticlesByType(Integer type);
public List<Article> getVisibleArticles();
public List<Article> getInvisibleArticles();
@ -21,4 +36,16 @@ public interface IArticleService {
public List<Article> getArticlesPublishedBetween(String beginning, String end);
// endregion
// region DELETE
public Response deleteArticleFromId(Integer id);
public Response deleteArticleFromTitle(String title);
public Response deleteArticleFromUrl(String url);
public Response deleteArticleFromType(Integer type);
public Response deleteArticleAddedBefore(String date);
public Response deleteArticleAddedAfter(String date);
public Response deleteArticleAddedBetween(String beginning, String end);
public Response deleteArticlePublishedBefore(String date);
public Response deleteArticlePublishedAfter(String date);
public Response deleteArticlePublishedBetween(String beginning, String end);
// endregion
}

@ -6,16 +6,17 @@ import java.util.List;
public interface ICollectionService{
public List<Collect> getAllCollections();
public Collect getCollectionById(long isbn);
public Collect getCollectionById(Integer id);
public List<Collect> getAllCollectionsByName(String name);
public void deleteColletionById(long isbn);
public void deleteColletionByName(String name);
public void deleteAllColletionByName(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(Collect collection);
public void addArticle(Collect collection, Article article);
public void deleteArticle(Collect collection, Article article);
public Collect getCollection(Collect collect);
public boolean deleteColletionById(Integer id);
public boolean deleteColletionByName(String name);
public boolean deleteAllColletionByName(String name);
public Collect addCollection(Collect collection);
public List<Collect> addCollections(List<Collect> collection);
public Collect modifyCollectionName(Collect collection, String name);
public Collect modifyCollectionNameById(Integer id, String name);
public List<Article> getAllArticlesById(Integer id);
public Collect addArticle(Collect collection, Article article);
public Collect deleteArticle(Collect collection, Article article);
}

@ -3,7 +3,6 @@ package SAE.ApiREST.WebService.service;
import SAE.ApiREST.WebService.Response;
import SAE.ApiREST.WebService.model.Teacher;
import java.time.LocalDate;
import java.util.List;
public interface ITeacherService {

@ -7,11 +7,66 @@ import java.util.List;
import org.springframework.stereotype.Service;
import SAE.ApiREST.WebService.Response;
import SAE.ApiREST.WebService.model.Article;
@Service
public class StubArticleService implements IArticleService {
// region POST
@Override
public Response addArticle(Article article) {
return new Response(
article.getId(),
"Article successfully created"
);
}
// endregion
// region PUT
@Override
public Article updateTitle(Article article, String title) {
Article newArticle = article;
newArticle.setTitle(title);
return newArticle;
}
@Override
public Article updateUrl(Article article, String url) {
Article newArticle = article;
newArticle.setUrl(url);
return newArticle;
}
@Override
public Article updateDatePublished(Article article, String datePublished) {
Article newArticle = article;
newArticle.setDatePublished(datePublished);
return newArticle;
}
@Override
public Article updateDateAdded(Article article, String dateAdded) {
Article newArticle = article;
newArticle.setDateAdded(dateAdded);
return newArticle;
}
@Override
public Article changeVisibility(Article article) {
Article newArticle = article;
newArticle.setVisibility(!article.getVisible());
return newArticle;
}
@Override
public Article updateType(Article article, Integer type) {
Article newArticle = article;
newArticle.setType(type);
return newArticle;
}
// endregion
// region GET
@Override
public List<Article> getAllArticles() {
@ -80,6 +135,22 @@ public class StubArticleService implements IArticleService {
return articles;
}
@Override
public List<Article> getArticlesByUrl(String url) {
List<Article> articles = new ArrayList<>();
articles.add(new Article(
"title",
url,
LocalDate.now().minusMonths(1),
LocalDate.now().minusMonths(2),
true,
1)
);
return articles;
}
@Override
public List<Article> getArticlesByType(Integer type) {
List<Article> articles = new ArrayList<>();
@ -224,4 +295,86 @@ public class StubArticleService implements IArticleService {
return articles;
}
// endregion
// region DELETE
@Override
public Response deleteArticleFromId(Integer id) {
return new Response(
id,
"Article successfully deleted"
);
}
@Override
public Response deleteArticleFromUrl(String url) {
return new Response(
1,
"Article successfully deleted"
);
}
@Override
public Response deleteArticleFromType(Integer type) {
return new Response(
1,
"Article successfully deleted"
);
}
@Override
public Response deleteArticleFromTitle(String title) {
return new Response(
1,
"Article successfully deleted"
);
}
@Override
public Response deleteArticleAddedBefore(String url) {
return new Response(
1,
"Article successfully deleted"
);
}
@Override
public Response deleteArticleAddedAfter(String url) {
return new Response(
1,
"Article successfully deleted"
);
}
@Override
public Response deleteArticleAddedBetween(String beginning, String end) {
return new Response(
1,
"Article successfully deleted"
);
}
@Override
public Response deleteArticlePublishedBefore(String url) {
return new Response(
1,
"Article successfully deleted"
);
}
@Override
public Response deleteArticlePublishedAfter(String url) {
return new Response(
1,
"Article successfully deleted"
);
}
@Override
public Response deleteArticlePublishedBetween(String beginning, String end) {
return new Response(
1,
"Article successfully deleted"
);
}
// endregion
}

@ -1,89 +1,150 @@
package SAE.ApiREST.WebService.service;
import SAE.ApiREST.WebService.model.Collect;
import SAE.ApiREST.WebService.model.Teacher;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import SAE.ApiREST.WebService.model.Article;
import org.springframework.stereotype.Service;
@Service
public class StubCollectionService implements ICollectionService {
private ArrayList<Collect> collections;
private List<Collect> collects = new ArrayList<>();
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));
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));
this.collects.add(collection3);
}
@Override
public List<Collect> getAllCollections() {
return this.collections;
return collects;
}
// region Collection
// region GET
public Collect getCollectionById(long isbn){
for(Collect collection : this.collections){
if(collection.getId() == isbn) {
return collection;
}
@Override
public Collect getCollectionById(Integer id){
try {
return collects.get(id);
}catch (Exception e){
return null;
}
return null;
}
@Override
public List<Collect> getAllCollectionsByName(String name){
ArrayList<Collect> repCollections = new ArrayList<Collect>();
for(Collect collection : this.collections){
if(collection.getName() == name) {
for(Collect collection : collects){
if(Objects.equals(collection.getName(), name)) {
repCollections.add(collection);
}
}
return repCollections;
}
@Override
public Collect getCollection(Collect collect){
return getCollectionById(collect.getId());
}
// endregion
// region DELETE
public void deleteColletionById(long isbn){
Collect collection = getCollectionById(isbn);
this.collections.remove(collection);
@Override
public boolean deleteColletionById(Integer id){
Collect collection = getCollectionById(id);
if (collection != null) {
collects.remove(collection);
return true;
}
return false;
}
public void deleteColletionByName(String name){
@Override
public boolean deleteColletionByName(String name){
List<Collect> collectionsByName = getAllCollectionsByName(name);
this.collections.remove(collectionsByName.get(0));
if (!collectionsByName.isEmpty()) {
collects.remove(collectionsByName.get(0));
return true;
}
return false;
}
public void deleteAllColletionByName(String name){
@Override
public boolean deleteAllColletionByName(String name){
List<Collect> collectionsByName = getAllCollectionsByName(name);
this.collections.removeAll(collectionsByName);
if (!collectionsByName.isEmpty()) {
collects.removeAll(collectionsByName);
return true;
}
return false;
}
@Override
public void addCollection(Collect collection) {
this.collections.add(collection);
public Collect addCollection(Collect collection) {
collects.add(collection);
return collects.get(collects.lastIndexOf(collection));
}
// endregion
// region PUT
public void addCollections(List<Collect> collections){
this.collections.addAll(collections);
@Override
public List<Collect> addCollections(List<Collect> collections){
collects.addAll(collections);
return collects;
}
// endregion
// region POST
public void modifyCollectionName(Collect collection, String name){
collection.setName(name);
}
public void modifyCollectionNameById(long isbn, String name){
Collect collection = getCollectionById(isbn);
modifyCollectionName(collection,name);
@Override
public Collect modifyCollectionName(Collect collection, String name){
Collect collect = getCollectionById(collection.getId());
collect.setName(name);
return collect;
}
@Override
public Collect modifyCollectionNameById(Integer id, String name){
Collect collect = getCollectionById(id);
collect.setName(name);
return collect;
}
// endregion
// endregion
// region Article
public List<Article> getAllArticles(Collect collect){
return collect.getAllArticles();
@Override
public List<Article> getAllArticlesById(Integer id){
Collect collect = getCollectionById(id);
List<Article> result = collect.getAllArticles();
if(!result.isEmpty()){
return result;
}
return null;
}
public void addArticle(Collect collect, Article article){
collect.addArticle(article);
@Override
public Collect addArticle(Collect collect, Article article){
Collect collection = getCollectionById(collect.getId());
collection.addArticle(article);
return collection;
}
public void deleteArticle(Collect collect, Article article){
collect.removeArticle(article);
@Override
public Collect deleteArticle(Collect collect, Article article){
Collect collection = getCollectionById(collect.getId());
collection.removeArticle(article);
return collection;
}
// endregion
}

@ -5,16 +5,12 @@ import SAE.ApiREST.WebService.exception.TeacherException;
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<Teacher> getAllTeacher() {
List<Teacher> allTeacher = new ArrayList<Teacher>();
@ -40,7 +36,6 @@ public class TeacherServiceStub implements ITeacherService {
return new Teacher(20, "24-12-2021", mail, "tructruc");
}
//Todo() Before date, After date, between date
@Override
public Teacher getTeacherByDate(String date) {
return new Teacher(5, date, "doudouda@gmail.com", "username");

Loading…
Cancel
Save