Compare commits

...

26 Commits

Author SHA1 Message Date
Maxime POINT c133ac27e1 merge Collection Branch
1 year ago
felix c526cfd0ac merge Article + clean code
1 year ago
Roxane ROSSETTO f1340fe6a7 Back to the version without repository
1 year ago
Maxime POINT 9b528b8e95 correctif de bug
1 year ago
Maxime POINT e2cf019437 ajout HATEOS et manque 2 tests
1 year ago
Maxime POINT 194eff0552 ajout HATOES
1 year ago
Maxime POINT 68a9aad682 modif du stub
1 year ago
Roxane ROSSETTO 6a7968d2b5 adding Hateos on the Teacher part
1 year ago
Roxane ROSSETTO d57ed6e020 construct of Tearcher's server part finished
1 year ago
Maxime POINT 808ccbc480 manque tests
1 year ago
Maxime POINT c4f977c45a résolution conflit
1 year ago
Maxime POINT 0fa91cbf59 Merge branch 'feature/ProfSection' into Maxime
1 year ago
Maxime POINT 08d705ea50 conflit
1 year ago
Roxane ROSSETTO 799af18ef7 merging response branch
1 year ago
Roxane ROSSETTO 20ef277c31 modification int to Integer, controller teacher loading
1 year ago
Roxane ROSSETTO 296f34328f cleanning production of the day
1 year ago
Roxane ROSSETTO 29abf4d5c9 adding Articles and modifying Collection files
1 year ago
Maxime POINT 004e52e0f6 modif service
1 year ago
Roxane ROSSETTO 2ffbeaa359 Merge remote-tracking branch 'origin/feature/Article' into feature/ProfSection
1 year ago
Roxane ROSSETTO 8af44d145d adaptation to my work
1 year ago
Roxane ROSSETTO 291fd62529 merging with Maxime's work branch
1 year ago
Maxime POINT c23c0aa7c0 Ajout service Collection
1 year ago
Roxane ROSSETTO a528b354be little modifications in controller Teacher
1 year ago
Roxane ROSSETTO 087421b2da adding model, service, controller Teacher
1 year ago
Maxime POINT f99c586220 ajout Model Article
1 year ago
Roxane ROSSETTO 6be5ebbb51 initiate new branch and adding prof controller
1 year ago

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>

@ -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
}

@ -0,0 +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.stereotype.Controller;
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 {
@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
}

@ -0,0 +1,101 @@
package SAE.ApiREST.WebService.controller;
import SAE.ApiREST.WebService.exception.TeacherException;
import SAE.ApiREST.WebService.model.Teacher;
import SAE.ApiREST.WebService.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.print.attribute.standard.Media;
import java.awt.*;
import java.util.List;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@Controller
@RequestMapping("/ProfWebService")
public class TeacherController {
@Autowired
private ITeacherService iTeacherServ;
public TeacherController(ITeacherService iserv) {
this.iTeacherServ = iserv;
}
@GetMapping(value = "/all", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public @ResponseBody CollectionModel<Teacher> getAllTeacher(){
return CollectionModel.of(
iTeacherServ.getAllTeacher(),
linkTo(methodOn(TeacherController.class).getAllTeacher()).withSelfRel());
}
@PostMapping(value = "addTeacher",produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public @ResponseBody EntityModel<Teacher> createTeacher( @RequestBody Teacher teach){
return EntityModel.of(teach,
linkTo(methodOn(TeacherController.class).createTeacher(teach)).withSelfRel(),
linkTo(methodOn(TeacherController.class).getAllTeacher()).withRel("all"));
}
@GetMapping(value = "/getid/{id}")
public @ResponseBody EntityModel<Teacher> getTeachById(@PathVariable("id") Integer id){
Teacher tt = iTeacherServ.getTeacherById(id);
if( tt == null ){
throw new TeacherException("No teacher found for this id !");
}
return EntityModel.of(tt,
linkTo(methodOn(TeacherController.class).getTeachById(id)).withSelfRel(),
linkTo(methodOn(TeacherController.class).getAllTeacher()).withRel("all"));
}
@GetMapping(value = "/getusername/{username}")
public @ResponseBody EntityModel<Teacher> getTeachByUsername(@PathVariable("username") String username) {
Teacher tt = iTeacherServ.getTeacherByUsername(username);
if (tt == null) {
throw new TeacherException("No teacher found for this username");
}
return EntityModel.of(tt,
linkTo(methodOn(TeacherController.class).getTeachByUsername(username)).withSelfRel(),
linkTo(methodOn(TeacherController.class).getAllTeacher()).withRel("all"));
}
@GetMapping( value = "/getmail/{mail}" )
public @ResponseBody EntityModel<Teacher> getTeachByMail(@PathVariable("mail") String mail) {
Teacher tt = iTeacherServ.getTeacherByMail(mail);
if( tt == null ) {
throw new TeacherException("No teacher found for this mail");
}
return EntityModel.of(tt,
linkTo(methodOn(TeacherController.class).getTeachByMail(mail)).withSelfRel(),
linkTo(methodOn(TeacherController.class).getAllTeacher()).withRel("all"));
}
@GetMapping( value = "/getdate/{date}" )
public @ResponseBody Teacher getTeachByDate(@PathVariable("date") String date) {
Teacher tt = iTeacherServ.getTeacherByMail(date);
if( tt == null ) {
throw new TeacherException("No teacher found for this mail");
}
return tt;
}
@PutMapping( value = "/modify/{username}" )
public @ResponseBody EntityModel<Teacher> modifyTeachUsername(@PathVariable("username") String username, Teacher tt){
if( username == "" ){
throw new TeacherException("Username provided for modification is empty");
}
iTeacherServ.modifyUsername(tt,username);
return EntityModel.of(tt,
linkTo(methodOn(TeacherController.class).modifyTeachUsername(username,tt)).withSelfRel(),
linkTo(methodOn(TeacherController.class).getAllTeacher()).withRel("all"));
}
@DeleteMapping( value = "delete")
public @ResponseBody EntityModel<List<Teacher>> deleteTeacher(Integer id){
return EntityModel.of(iTeacherServ.deleteTeacher(id),
linkTo(methodOn(TeacherController.class).deleteTeacher(id)).withSelfRel(),
linkTo(methodOn(TeacherController.class).getAllTeacher()).withRel("all"));
}
}

@ -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);
}
}

@ -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 TeacherAdvice {
@ResponseBody
@ExceptionHandler(TeacherException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public String teacherNFHandler( TeacherException e) {
return e.getMessage();
}
}

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

@ -1,5 +1,6 @@
package SAE.ApiREST.WebService.model;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@ -33,6 +34,15 @@ public class Article {
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;
}

@ -0,0 +1,82 @@
package SAE.ApiREST.WebService.model;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
public class Collect {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@Column(name = "articles")
private ArrayList<Article> articles;
@Column(name = "name")
private String name;
@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(String name, Teacher teacher, Integer id){
this.name = name;
this.teacher = teacher;
this.articles = new ArrayList<Article>();
this.id = id;
}
// region Article
public Integer getId(){
return id;
}
// endregion
// region Article
public List<Article> getAllArticles(){
return articles;
}
// region addArticle
public void addArticle(Article article){
if(!this.articles.contains(article)){
this.articles.add(article);
}
}
public void addArticles(List<Article> articles){
for(Article article : articles){
addArticle(article);
}
}
// endregion
// region removeArticle
public void removeArticle(Article article){
this.articles.remove(article);
}
public void removeArticles(List<Article> articles){
this.articles.removeAll(articles);
}
// endregion
// endregion
// region name
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
// endregion
// region teacher
public Teacher getTeacher(){
return teacher;
}
// endregion
}

@ -0,0 +1,59 @@
package SAE.ApiREST.WebService.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@Entity
public class Teacher {
@Id
private Integer id;
private LocalDate date;
private String mail;
private String username;
public Teacher() {
}
public Teacher(Integer id, String date, String mail, String username) {
this.id = id;
this.date = LocalDate.parse(date, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
this.mail = mail;
this.username = username;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public LocalDate getDate() {
return date;
}
public void setDate(String date) {
this.date = LocalDate.parse(date, DateTimeFormatter.ofPattern("dd-MM-yyyy"));
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}

@ -0,0 +1,22 @@
package SAE.ApiREST.WebService.service;
import SAE.ApiREST.WebService.model.Collect;
import SAE.ApiREST.WebService.model.Article;
import java.util.List;
public interface ICollectionService{
public List<Collect> getAllCollections();
public Collect getCollectionById(Integer id);
public List<Collect> getAllCollectionsByName(String name);
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);
}

@ -0,0 +1,17 @@
package SAE.ApiREST.WebService.service;
import SAE.ApiREST.WebService.Response;
import SAE.ApiREST.WebService.model.Teacher;
import java.util.List;
public interface ITeacherService {
public List<Teacher> getAllTeacher();
public Teacher getTeacherById(Integer id);
public Teacher getTeacherByUsername(String username);
public Teacher getTeacherByMail(String mail);
public Teacher getTeacherByDate(String date);
public List<Teacher> addTeacher(Teacher t);
public List<Teacher> deleteTeacher(Integer id);
public Response modifyUsername(Teacher t, String newUsername);
}

@ -0,0 +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 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 collects;
}
// region Collection
// region GET
@Override
public Collect getCollectionById(Integer id){
try {
return collects.get(id);
}catch (Exception e){
return null;
}
}
@Override
public List<Collect> getAllCollectionsByName(String name){
ArrayList<Collect> repCollections = new ArrayList<Collect>();
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
@Override
public boolean deleteColletionById(Integer id){
Collect collection = getCollectionById(id);
if (collection != null) {
collects.remove(collection);
return true;
}
return false;
}
@Override
public boolean deleteColletionByName(String name){
List<Collect> collectionsByName = getAllCollectionsByName(name);
if (!collectionsByName.isEmpty()) {
collects.remove(collectionsByName.get(0));
return true;
}
return false;
}
@Override
public boolean deleteAllColletionByName(String name){
List<Collect> collectionsByName = getAllCollectionsByName(name);
if (!collectionsByName.isEmpty()) {
collects.removeAll(collectionsByName);
return true;
}
return false;
}
@Override
public Collect addCollection(Collect collection) {
collects.add(collection);
return collects.get(collects.lastIndexOf(collection));
}
// endregion
// region PUT
@Override
public List<Collect> addCollections(List<Collect> collections){
collects.addAll(collections);
return collects;
}
// endregion
// region POST
@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
@Override
public List<Article> getAllArticlesById(Integer id){
Collect collect = getCollectionById(id);
List<Article> result = collect.getAllArticles();
if(!result.isEmpty()){
return result;
}
return null;
}
@Override
public Collect addArticle(Collect collect, Article article){
Collect collection = getCollectionById(collect.getId());
collection.addArticle(article);
return collection;
}
@Override
public Collect deleteArticle(Collect collect, Article article){
Collect collection = getCollectionById(collect.getId());
collection.removeArticle(article);
return collection;
}
// endregion
}

@ -0,0 +1,69 @@
package SAE.ApiREST.WebService.service;
import SAE.ApiREST.WebService.Response;
import SAE.ApiREST.WebService.exception.TeacherException;
import SAE.ApiREST.WebService.model.Teacher;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class TeacherServiceStub implements ITeacherService {
@Override
public List<Teacher> getAllTeacher() {
List<Teacher> allTeacher = new ArrayList<Teacher>();
allTeacher.add(new Teacher(1, "12-01-2023", "aline.alipres@gmail.com", "MsGarconManque"));
allTeacher.add(new Teacher(2, "20-08-2023", "Viviane.Delvecchio@gmail.com", "MmeMath"));
return allTeacher;
}
@Override
public Teacher getTeacherById(Integer id) {
return new Teacher(id, "10-01-2021", "exemple.gmail.com", "testest");
}
@Override
public Teacher getTeacherByUsername(String username) { return new Teacher(12, "30-08-2020", "dadadou@gmail.com", username); }
@Override
public Teacher getTeacherByMail(String mail) {
return new Teacher(20, "24-12-2021", mail, "tructruc");
}
@Override
public Teacher getTeacherByDate(String date) {
return new Teacher(5, date, "doudouda@gmail.com", "username");
}
@Override
public List<Teacher> addTeacher(Teacher t) {
List<Teacher> lteach = new ArrayList<Teacher>();
lteach.add(t);
return lteach;
}
@Override
public List<Teacher> deleteTeacher(Integer id) {
List<Teacher> allTeacher = new ArrayList<Teacher>();
allTeacher.add(new Teacher(1,"12-01-2023", "aline.alipres@gmail.com", "MsGarconManque"));
allTeacher.add(new Teacher(2, "20-08-2023", "Viviane.Delvecchio@gmail.com", "MmeMath"));
if(allTeacher.remove(getTeacherById(id))){
return allTeacher;
} else {
throw new TeacherException(String.format("Teacher {id} isn't removed", id));
}
}
public Response modifyUsername(Teacher t, String newUsername){
t.setUsername(newUsername);
return new Response(t.getId(),String.format("This user %s has changed username", t.getMail()));
}
}
Loading…
Cancel
Save