fix EntityModel<List<Article>> to CollectionModel<>

feature/Article
felix 1 year ago
parent 1cd2e8d714
commit 630a1c0813

@ -1,6 +1,7 @@
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;
@ -12,7 +13,6 @@ 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;
@ -179,14 +179,14 @@ public class ArticleControler {
value = "/getAllArticle",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getAllArticles() {
public @ResponseBody CollectionModel<Article> getAllArticles() {
ArrayList<Article> results = (ArrayList<Article>) articleService.getAllArticles();
if(results.isEmpty()) {
throw new ArticleException("No articles available");
}
return EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getAllArticles()).withSelfRel()
);
@ -214,14 +214,14 @@ public class ArticleControler {
value = "/getArticlesByTitle/{title}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getArticlesByTitle(@PathVariable(value = "title") String title) {
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 EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesByTitle(title)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleFromTitle(title)).withRel("deleteArticleFromTitle")
@ -232,14 +232,14 @@ public class ArticleControler {
value = "/getArticlesByUrl/{url}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getArticlesByUrl(@PathVariable(value = "url") String url) {
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 EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesByUrl(url)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleFromUrl(url)).withRel("deleteArticleFromId")
@ -250,14 +250,14 @@ public class ArticleControler {
value = "/getArticlesByType/{type}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getArticlesByType(@PathVariable(value = "type") Integer type) {
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 EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesByType(type)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleFromType(type)).withRel("deleteArticleFromType")
@ -268,14 +268,14 @@ public class ArticleControler {
value = "/getVisibleArticles",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getVisibleArticles() {
public @ResponseBody CollectionModel<Article> getVisibleArticles() {
ArrayList<Article> results = (ArrayList<Article>) articleService.getVisibleArticles();
if (results.isEmpty()) {
throw new ArticleException("No visible article");
}
return EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getVisibleArticles()).withSelfRel()
);
@ -285,14 +285,14 @@ public class ArticleControler {
value = "/getInvisibleArticles",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getInvisibleArticles() {
public @ResponseBody CollectionModel<Article> getInvisibleArticles() {
ArrayList<Article> results = (ArrayList<Article>) articleService.getInvisibleArticles();
if (results.isEmpty()) {
throw new ArticleException("No invisible article");
}
return EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getInvisibleArticles()).withSelfRel()
);
@ -302,14 +302,14 @@ public class ArticleControler {
value = "/getArticlesAddedBefore/{dateAdded}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getArticlesAddedBefore(@PathVariable(value = "dateAdded") String dateAdded) {
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 EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesAddedBefore(dateAdded)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleAddedBefore(dateAdded)).withRel("deleteArticleAddedBefore")
@ -320,14 +320,14 @@ public class ArticleControler {
value = "/getArticlesAddedAfter/{dateAdded}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getArticlesAddedAfter(@PathVariable(value = "dateAdded") String dateAdded) {
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 EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesAddedAfter(dateAdded)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleAddedAfter(dateAdded)).withRel("deleteArticleAddedAfter")
@ -338,14 +338,14 @@ public class ArticleControler {
value = "/getArticlesAddedBetween/{beginning}/{end}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getArticlesAddedBetween(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) {
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 EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesAddedBetween(beginning, end)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticleAddedBetween(beginning, end)).withRel("deleteArticleAddedBetween")
@ -356,14 +356,14 @@ public class ArticleControler {
value = "/getArticlesPublishedBefore/{datePublished}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getArticlesPublishedBefore(@PathVariable(value = "datePublished") String datePublished) {
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 EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesPublishedBefore(datePublished)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticlePublishedBefore(datePublished)).withRel("deleteArticlePublishedBefore")
@ -374,14 +374,14 @@ public class ArticleControler {
value = "/getArticlesPublishedAfter/{datePublished}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getArticlesPublishedAfter(@PathVariable(value = "datePublished") String datePublished) {
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 EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesPublishedAfter(datePublished)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticlePublishedAfter(datePublished)).withRel("deleteArticlePublishedAfter")
@ -392,14 +392,14 @@ public class ArticleControler {
value = "/getArticlesPublishedBetween/{beginning}/{end}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public @ResponseBody EntityModel<List<Article>> getArticlesPublishedBetween(@PathVariable(value = "beginning") String beginning, @PathVariable(value = "end") String end) {
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 EntityModel.of(
return CollectionModel.of(
results,
linkTo(methodOn(ArticleControler.class).getArticlesPublishedBetween(beginning, end)).withSelfRel(),
linkTo(methodOn(ArticleControler.class).deleteArticlePublishedBetween(beginning, end)).withRel("getArticlesPublishedBetween")

Loading…
Cancel
Save