diff --git a/WebService/pom.xml b/WebService/pom.xml index de41c7d..23c71db 100644 --- a/WebService/pom.xml +++ b/WebService/pom.xml @@ -1,50 +1,50 @@ - 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 - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - + 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-hateoas + + + org.springframework.boot + spring-boot-starter-web + + + jakarta.persistence + jakarta.persistence-api + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java b/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java index 222846c..6f524c7 100644 --- a/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java +++ b/WebService/src/main/java/SAE/ApiREST/WebService/controller/ArticleControler.java @@ -1,6 +1,7 @@ package SAE.ApiREST.WebService.controller; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.hateoas.EntityModel; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @@ -13,6 +14,9 @@ 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") public class ArticleControler { @@ -25,10 +29,18 @@ public class ArticleControler { consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody Response addArticle( + public @ResponseBody EntityModel addArticle( @RequestBody Article article ) { - return articleService.addArticle(article); + Response res = articleService.addArticle(article); + + return EntityModel.of( + res, + 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 @@ -38,11 +50,20 @@ public class ArticleControler { consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody Article updateTitle( + public @ResponseBody EntityModel
updateTitle( @PathVariable("title") String title, @RequestBody Article article ) { - return articleService.updateTitle(article, title); + Article res = articleService.updateTitle(article, title); + + return EntityModel.of( + res, + 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( @@ -50,11 +71,20 @@ public class ArticleControler { consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody Article updateUrl( + public @ResponseBody EntityModel
updateUrl( @PathVariable("url") String url, @RequestBody Article article ) { - return articleService.updateUrl(article, url); + Article res = articleService.updateUrl(article, url); + + return EntityModel.of( + res, + 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( @@ -62,11 +92,21 @@ public class ArticleControler { consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody Article updateDatePublished( + public @ResponseBody EntityModel
updateDatePublished( @PathVariable("datePublished") String datePublished, @RequestBody Article article ) { - return articleService.updateDatePublished(article, datePublished); + Article res = articleService.updateDatePublished(article, datePublished); + + return EntityModel.of( + res, + 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( @@ -74,11 +114,21 @@ public class ArticleControler { consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody Article updateDateAdded( + public @ResponseBody EntityModel
updateDateAdded( @PathVariable("dateAdded") String dateAdded, @RequestBody Article article ) { - return articleService.updateDateAdded(article, dateAdded); + Article res = articleService.updateDateAdded(article, dateAdded); + + return EntityModel.of( + res, + 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( @@ -86,10 +136,20 @@ public class ArticleControler { consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody Article changeVisibility( + public @ResponseBody EntityModel
changeVisibility( @RequestBody Article article ) { - return articleService.changeVisibility(article); + Article res = articleService.changeVisibility(article); + + return EntityModel.of( + res, + 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( @@ -97,142 +157,214 @@ public class ArticleControler { consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody Article updateType( + public @ResponseBody EntityModel
updateType( @PathVariable("type") Integer type, @RequestBody Article article ) { - return articleService.updateType(article, type); + Article res = articleService.updateType(article, type); + + return EntityModel.of( + res, + 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
getAllArticles() { + public @ResponseBody EntityModel> getAllArticles() { ArrayList
results = (ArrayList
) articleService.getAllArticles(); if(results.isEmpty()) { throw new ArticleException("No articles available"); } - return results; + return EntityModel.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) { + public @ResponseBody EntityModel
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
getArticlesByTitle(@PathVariable(value = "title") String title) { + public @ResponseBody EntityModel> getArticlesByTitle(@PathVariable(value = "title") String title) { ArrayList
results = (ArrayList
) articleService.getArticlesByTitle(title); if(results.isEmpty()) { throw new ArticleException("Undefined title"); } - return results; + return EntityModel.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 EntityModel> getArticlesByUrl(@PathVariable(value = "url") String url) { + ArrayList
results = (ArrayList
) articleService.getArticlesByUrl(url); + + if(results.isEmpty()) { + throw new ArticleException("Undefined title"); + } + + return EntityModel.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
getArticlesByType(@PathVariable(value = "type") Integer type) { + public @ResponseBody EntityModel> 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; + + return EntityModel.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
getVisibleArticles() { + public @ResponseBody EntityModel> getVisibleArticles() { ArrayList
results = (ArrayList
) articleService.getVisibleArticles(); if (results.isEmpty()) { throw new ArticleException("No visible article"); } - - return results; + + return EntityModel.of( + results, + linkTo(methodOn(ArticleControler.class).getVisibleArticles()).withSelfRel() + ); } @GetMapping(value = "/getInvisibleArticles", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody List
getInvisibleArticles() { + public @ResponseBody EntityModel> getInvisibleArticles() { ArrayList
results = (ArrayList
) articleService.getInvisibleArticles(); if (results.isEmpty()) { throw new ArticleException("No invisible article"); } - - return results; + + return EntityModel.of( + results, + linkTo(methodOn(ArticleControler.class).getInvisibleArticles()).withSelfRel() + ); } @GetMapping(value = "/getArticlesAddedBefore/{dateAdded}", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody List
getArticlesAddedBefore(@PathVariable(value = "dateAdded") String dateAdded) { + public @ResponseBody EntityModel> 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; + + return EntityModel.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
getArticlesAddedAfter(@PathVariable(value = "dateAdded") String dateAdded) { + public @ResponseBody EntityModel> 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; + + return EntityModel.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
getArticlesAddedAfter(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) { + public @ResponseBody EntityModel> getArticlesAddedBetween(@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; + + return EntityModel.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
getArticlesPublishedBefore(@PathVariable(value = "datePublished") String datePublished) { + public @ResponseBody EntityModel> 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; + + return EntityModel.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
getArticlesPublishedAfter(@PathVariable(value = "datePublished") String datePublished) { + public @ResponseBody EntityModel> 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; + + return EntityModel.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
getArticlesPublishedAfter(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) { + public @ResponseBody EntityModel> getArticlesPublishedBetween(@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; + + return EntityModel.of( + results, + linkTo(methodOn(ArticleControler.class).getArticlesPublishedBetween(beginning, end)).withSelfRel(), + linkTo(methodOn(ArticleControler.class).deleteArticlePublishedBetween(beginning, end)).withRel("getArticlesPublishedBetween") + ); } // endregion @@ -242,90 +374,172 @@ public class ArticleControler { value = "/deleteArticleFromId/{id}", produces = MediaType.APPLICATION_JSON_VALUE ) - public @ResponseBody Response deleteArticleFromId( + public @ResponseBody EntityModel deleteArticleFromId( @PathVariable("id") Integer id ) { - return articleService.deleteArticleFromId(id); + Response res = articleService.deleteArticleFromId(id); + + return EntityModel.of( + res, + 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 Response deleteArticleFromTitle( + public @ResponseBody EntityModel deleteArticleFromTitle( @PathVariable("title") String title ) { - return articleService.deleteArticleFromTitle(title); + Response res = articleService.deleteArticleFromTitle(title); + + return EntityModel.of( + res, + 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 Response deleteArticleFromUrl( + public @ResponseBody EntityModel deleteArticleFromUrl( @PathVariable("url") String url ) { - return articleService.deleteArticleFromUrl(url); + Response res = articleService.deleteArticleFromTitle(url); + + return EntityModel.of( + res, + 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 deleteArticleFromType( + @PathVariable("type") Integer type + ) { + Response res = articleService.deleteArticleFromType(type); + + return EntityModel.of( + res, + 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 Response deleteArticleAddedBefore( + public @ResponseBody EntityModel deleteArticleAddedBefore( @PathVariable("date") String date ) { - return articleService.deleteArticleAddedBefore(date); + Response res = articleService.deleteArticleAddedBefore(date); + + return EntityModel.of( + res, + 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 Response deleteArticleAddedAfter( + public @ResponseBody EntityModel deleteArticleAddedAfter( @PathVariable("date") String date ) { - return articleService.deleteArticleAddedAfter(date); - }@DeleteMapping( + Response res = articleService.deleteArticleAddedAfter(date); + + return EntityModel.of( + res, + 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 Response deleteArticleAddedBetween( + public @ResponseBody EntityModel deleteArticleAddedBetween( @PathVariable("beginning") String beginning, @PathVariable("end") String end ) { - return articleService.deleteArticleAddedBetween(beginning, end); + Response res = articleService.deleteArticleAddedBetween(beginning, end); + + return EntityModel.of( + res, + 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 Response deleteArticlePublishedBefore( + public @ResponseBody EntityModel deleteArticlePublishedBefore( @PathVariable("date") String date ) { - return articleService.deleteArticlePublishedBefore(date); + Response res = articleService.deleteArticlePublishedBefore(date); + + return EntityModel.of( + res, + 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 Response deleteArticlePublishedAfter( + public @ResponseBody EntityModel deleteArticlePublishedAfter( @PathVariable("date") String date ) { - return articleService.deleteArticlePublishedAfter(date); + Response res = articleService.deleteArticlePublishedBefore(date); + + return EntityModel.of( + res, + 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 Response deleteArticlePublishedBetween( + public @ResponseBody EntityModel deleteArticlePublishedBetween( @PathVariable("beginning") String beginning, @PathVariable("end") String end ) { - return articleService.deleteArticlePublishedBetween(beginning, end); + Response res = articleService.deleteArticlePublishedBetween(beginning, end); + + return EntityModel.of( + res, + 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 } diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/IArticleService.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/IArticleService.java index eaa12ff..38d0f82 100644 --- a/WebService/src/main/java/SAE/ApiREST/WebService/service/IArticleService.java +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/IArticleService.java @@ -24,6 +24,7 @@ public interface IArticleService { public List
getAllArticles(); Article getArticlesById(Integer id); public List
getArticlesByTitle(String title); + public List
getArticlesByUrl(String url); public List
getArticlesByType(Integer type); public List
getVisibleArticles(); public List
getInvisibleArticles(); @@ -39,6 +40,7 @@ public interface IArticleService { 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); diff --git a/WebService/src/main/java/SAE/ApiREST/WebService/service/StubArticleService.java b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubArticleService.java index 026dcbc..9c17905 100644 --- a/WebService/src/main/java/SAE/ApiREST/WebService/service/StubArticleService.java +++ b/WebService/src/main/java/SAE/ApiREST/WebService/service/StubArticleService.java @@ -135,6 +135,22 @@ public class StubArticleService implements IArticleService { return articles; } + @Override + public List
getArticlesByUrl(String url) { + List
articles = new ArrayList<>(); + + articles.add(new Article( + "title", + url, + LocalDate.now().minusMonths(1), + LocalDate.now().minusMonths(2), + true, + 1) + ); + + return articles; + } + @Override public List
getArticlesByType(Integer type) { List
articles = new ArrayList<>(); @@ -296,6 +312,14 @@ public class StubArticleService implements IArticleService { "Article successfully deleted" ); } + + @Override + public Response deleteArticleFromType(Integer type) { + return new Response( + 1, + "Article successfully deleted" + ); + } @Override public Response deleteArticleFromTitle(String title) {