|
|
@ -6,12 +6,17 @@ import SAE.ApiREST.WebService.model.Article;
|
|
|
|
import SAE.ApiREST.WebService.model.Collect;
|
|
|
|
import SAE.ApiREST.WebService.model.Collect;
|
|
|
|
import SAE.ApiREST.WebService.service.ICollectionService;
|
|
|
|
import SAE.ApiREST.WebService.service.ICollectionService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.hateoas.EntityModel;
|
|
|
|
|
|
|
|
import org.springframework.hateoas.Link;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
|
|
|
|
|
|
|
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
|
|
|
|
|
|
|
|
|
|
|
@Controller
|
|
|
|
@Controller
|
|
|
|
@RequestMapping("/CollectWebService")
|
|
|
|
@RequestMapping("/CollectWebService")
|
|
|
|
public class CollectController {
|
|
|
|
public class CollectController {
|
|
|
@ -34,84 +39,167 @@ public class CollectController {
|
|
|
|
return results;
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@GetMapping(value = "/getCollectionById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@GetMapping(value = "/getCollectionById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody Collect getCollectionById(@PathVariable(value = "id") Integer id){
|
|
|
|
public @ResponseBody EntityModel<Collect> getCollectionById(@PathVariable(value = "id") Integer id){
|
|
|
|
Collect results = collectionService.getCollectionById(id);
|
|
|
|
Collect results = collectionService.getCollectionById(id);
|
|
|
|
if(results == null) {
|
|
|
|
if(results == null) {
|
|
|
|
throw new CollectException("No collections available");
|
|
|
|
throw new CollectException("No collections available");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
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)
|
|
|
|
@GetMapping(value = "/getAllCollectionsByName/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody List<Collect> getAllCollectionsByName(@PathVariable(value = "name") String name){
|
|
|
|
public @ResponseBody EntityModel<List<Collect>> getAllCollectionsByName(@PathVariable(value = "name") String name){
|
|
|
|
List<Collect> results = collectionService.getAllCollectionsByName(name);
|
|
|
|
List<Collect> results = collectionService.getAllCollectionsByName(name);
|
|
|
|
if(results.isEmpty()) {
|
|
|
|
if(results.isEmpty()) {
|
|
|
|
throw new CollectException("No collections available");
|
|
|
|
throw new CollectException("No collections available");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
return EntityModel.of(results,
|
|
|
|
|
|
|
|
linkTo(methodOn(CollectController.class).getAllCollectionsByName(name)).withSelfRel(),
|
|
|
|
|
|
|
|
linkTo(methodOn(CollectController.class).getAllCollection()
|
|
|
|
|
|
|
|
).withRel("getAllCollection"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
|
|
// region DELETE
|
|
|
|
// region DELETE
|
|
|
|
@DeleteMapping(value = "/deleteColletionById/{id}")
|
|
|
|
@DeleteMapping(value = "/deleteColletionById/{id}")
|
|
|
|
public @ResponseBody void deleteColletionById(@RequestParam("id") Integer id){
|
|
|
|
public @ResponseBody EntityModel<Link> deleteColletionById(@RequestParam("id") Integer id){
|
|
|
|
collectionService.deleteColletionById(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}")
|
|
|
|
@DeleteMapping(value = "/deleteColletionByName/{name}")
|
|
|
|
public @ResponseBody void deleteColletionByName(@RequestParam("name") String name){
|
|
|
|
public @ResponseBody EntityModel<Link> deleteColletionByName(@RequestParam("name") String name){
|
|
|
|
collectionService.deleteColletionByName(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}")
|
|
|
|
@DeleteMapping(value = "/deleteAllColletionByName/{name}")
|
|
|
|
public @ResponseBody void deleteAllColletionByName(@RequestParam("name") String name){
|
|
|
|
public @ResponseBody EntityModel<Link> deleteAllColletionByName(@RequestParam("name") String name){
|
|
|
|
collectionService.deleteAllColletionByName(name);
|
|
|
|
if(!collectionService.deleteAllColletionByName(name)) {
|
|
|
|
|
|
|
|
throw new CollectException("No collections available");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return EntityModel.of(linkTo(methodOn(CollectController.class).getAllCollection()
|
|
|
|
|
|
|
|
).withRel("getAllCollection"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
|
|
// region PUT
|
|
|
|
// region PUT
|
|
|
|
@PutMapping(value = "/addCollection")
|
|
|
|
@PutMapping(value = "/addCollection")
|
|
|
|
public @ResponseBody void addCollection(@RequestParam("collection") Collect collection){
|
|
|
|
public @ResponseBody EntityModel<Collect> addCollection(@RequestParam("collection") Collect collection){
|
|
|
|
collectionService.addCollection(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")
|
|
|
|
@PutMapping(value = "/addCollections")
|
|
|
|
public @ResponseBody void addCollections(@RequestParam("collections") List<Collect> collections){
|
|
|
|
public @ResponseBody EntityModel<List<Collect>> addCollections(@RequestParam("collections") List<Collect> collections){
|
|
|
|
collectionService.addCollections(collections);
|
|
|
|
List<Collect> results = collectionService.addCollections(collections);
|
|
|
|
|
|
|
|
return EntityModel.of(results,
|
|
|
|
|
|
|
|
linkTo(methodOn(CollectController.class).getAllCollection()
|
|
|
|
|
|
|
|
).withRel("getAllCollection"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
|
|
// region POST
|
|
|
|
// region POST
|
|
|
|
@PostMapping(value="/modifyCollectionName", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@PostMapping(value="/modifyCollectionName", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody void modifyCollectionName(@RequestParam("collection") Collect collection, @RequestParam("name") String name){
|
|
|
|
public @ResponseBody EntityModel<Collect> modifyCollectionName(@RequestParam("collection") Collect collection, @RequestParam("name") String name){
|
|
|
|
collectionService.modifyCollectionName(collection,name);
|
|
|
|
Collect results = collectionService.modifyCollectionName(collection,name);
|
|
|
|
|
|
|
|
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)
|
|
|
|
@PostMapping(value="/modifyCollectionNameById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody void modifyCollectionNameById(@RequestParam("id") Integer id, @RequestParam("name") String name){
|
|
|
|
public @ResponseBody EntityModel<Collect> modifyCollectionNameById(@RequestParam("id") Integer id, @RequestParam("name") String name){
|
|
|
|
collectionService.modifyCollectionNameById(id,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
|
|
|
|
// endregion
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
|
|
// region Article
|
|
|
|
// region Article
|
|
|
|
@GetMapping(value = "/getAllArticlesById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@GetMapping(value = "/getAllArticlesById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody List<Article> getAllArticlesById(@PathVariable(value = "id") Integer id){
|
|
|
|
public @ResponseBody EntityModel<List<Article>> getAllArticlesById(@PathVariable(value = "id") Integer id){
|
|
|
|
List<Article> results = collectionService.getAllArticlesById(id);
|
|
|
|
List<Article> results = collectionService.getAllArticlesById(id);
|
|
|
|
if(results == null) {
|
|
|
|
if(results == null) {
|
|
|
|
throw new ArticleException("No articles available");
|
|
|
|
throw new ArticleException("No articles available");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
return EntityModel.of(results,
|
|
|
|
|
|
|
|
linkTo(methodOn(CollectController.class).getAllCollection()
|
|
|
|
|
|
|
|
).withRel("getAllCollection"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping(value = "/addArticle", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@PutMapping(value = "/addArticle", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody void addArticle(@RequestParam("collection") Collect collection, @RequestParam("article") Article article){
|
|
|
|
public @ResponseBody EntityModel<Collect> addArticle(@RequestParam("collection") Collect collection, @RequestParam("article") Article article){
|
|
|
|
collectionService.addArticle(collection,article);
|
|
|
|
Collect results = collectionService.addArticle(collection,article);
|
|
|
|
|
|
|
|
Article art = results.getAllArticles().get(results.getAllArticles().indexOf(article));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return EntityModel.of(results,
|
|
|
|
|
|
|
|
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)
|
|
|
|
@DeleteMapping(value = "/deleteArticle", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
public @ResponseBody void deleteArticle(@RequestParam("collection") Collect collection, @RequestParam("article") Article article){
|
|
|
|
public @ResponseBody EntityModel<Collect> deleteArticle(@RequestParam("collection") Collect collection, @RequestParam("article") Article article){
|
|
|
|
collectionService.deleteArticle(collection,article);
|
|
|
|
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
|
|
|
|
// endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|