merging with Maxime's work branch

pull/1/head
Roxane ROSSETTO 1 year ago
commit 291fd62529

@ -1,5 +1,7 @@
import org.springframework.web.bind.annotation.*;
<?xml version="1.0" encoding="UTF-8"?> <?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" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<<<<<<< HEAD
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 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> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
@ -37,14 +39,56 @@
<artifactId>jakarta.persistence-api</artifactId> <artifactId>jakarta.persistence-api</artifactId>
</dependency> </dependency>
</dependencies> </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>
<build> <dependency>
<plugins> <groupId>org.springframework.boot</groupId>
<plugin> <artifactId>spring-boot-starter-test</artifactId>
<groupId>org.springframework.boot</groupId> <scope>test</scope>
<artifactId>spring-boot-maven-plugin</artifactId> </dependency>
</plugin> >>>>>>> origin/Maxime
</plugins>
</build>
<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>
<<<<<<< HEAD
=======
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
>>>>>>> origin/Maxime
</project> </project>

@ -0,0 +1,50 @@
<?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-web</artifactId>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,107 @@
@org.springframework.stereotype.Controller
@Controller
@RequestMapping("/CollectionWebService")
public class CollectionController {
private ArrayList<Collection> collections = new ArrayList<>();
public Controller() {
}
@GetMapping(value = "/getAllCollection", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Collection> getAllCollection() {
return collections;
}
@GetMapping(value = "/getCollectionById/{isbn}", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Book getCollectionById(@PathVariable(value = "isbn") int isbn) {
for(Book book : books) {
if(book.isbn == isbn) {
return book;
}
}
throw new BookException("Undefined id");
}
@PostMapping("/logBooks")
public @ResponseBody void logBooks(@RequestParam("title") String title, @RequestParam("author") String author) {
books.add(new Book(title, author));
for(Book book : books) {
System.out.println(book);
}
}
// region Collection
// region GET
@GetMapping(value = "/getCollectionById", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Collection getCollectionById(long isbn){
for(Collection collection : this.collections){
if(collection.getId === isbn) {
return collection;
}
}
return null;
}
@GetMapping(value = "/getAllCollectionsByName", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Collection> getAllCollectionsByName(String name){
private ArrayList<Collection> repCollections = new ArrayList<Collection>();
for(Collection collection : this.collections){
if(collection.getName === name) {
repCollections.add(collection);
}
}
return repCollections;
}
// endregion
// region DELETE
@DeleteMaping(value = "/deleteColletionById")
public @ResponseBody void deleteColletionById(long isbn){
Collection collection = getCollectionById(isbn);
this.collections.remove(collection);
}
public @ResponseBody void deleteColletionByName(String name){
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
this.collections.remove(collectionsByName[0]);
}
public @ResponseBody void deleteAllColletionByName(String name){
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
this.collections.removeAll(collectionsByName);
}
// endregion
// region PUT
public @ResponseBody void addCollection(Collection collection){
this.collections.add(collection);
}
public @ResponseBody void addCollections(List<Collection> collections){
this.collections.addAll(collections);
}
// endregion
// region POST
public @ResponseBody void modifyCollectionName(Collection collection, String name){
collection.setName(name);
}
public @ResponseBody void modifyCollectionNameById(long isbn, String name){
Collection collection = getCollectionById(isbn);
modifyCollectionName(collection,name);
}
// endregion
// endregion
// region Article
@GetMapping(value = "/getAllArticles", produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Article> getAllArticles(Collection collection){
return collection.getAllArticles;
}
public @ResponseBody void addArticle(Collection collection, Article article){
collection.addArticle
}
public @ResponseBody void deleteArticle(Collection collection, Article article){
collection.deleteArticle(article);
}
// endregion
}

@ -0,0 +1,62 @@
package SAE.ApiREST.WebService.Data;
@Entity
public class Collection{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private final long isbn
@Column(name = "articles")
private ArrayList<Article> articles
@Column(name = "name")
private String name
@Column(name = "teacher")
private Teacher teacher
public Collection(String name, Teacher teacher){
this.name = name;
this.teacher = teacher;
this.articles = new ArrayList<Article>();
}
// region Article
public long getId(){
return isbn;
}
// 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
}

@ -0,0 +1,15 @@
public interface ICollectionService{
public List<Collection> getAllCollections();
public Collection getCollectionById(long isbn);
public List<Collection> getAllCollectionsByName(String name);
public void deleteColletionById(long isbn);
public void deleteColletionByName(String name);
public void deleteAllColletionByName(String name);
public void addCollection(Collection collection);
public void addCollections(List<Collection> collection);
public void modifyCollectionName(Collection collection, String name);
public void modifyCollectionNameById(long isbn, String name);
public List<Article> getAllArticles(Collection collection);
public void addArticle(Collection collection, Article article);
public void deleteArticle(Collection collection, Article article);
}

@ -0,0 +1,87 @@
package SAE.ApiREST.WebService.service;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import SAE.ApiREST.WebService.model.Article;
@Service
public class CollectionService implements ICollectionService {
private ArrayList<Collection> collections;
public List<Collection> getAllCollections() {
return this.collections;
}
// region Collection
// region GET
public Collection getCollectionById(long isbn){
for(Collection collection : this.collections){
if(collection.getId === isbn) {
return collection;
}
}
return null;
}
public List<Collection> getAllCollectionsByName(String name){
private ArrayList<Collection> repCollections = new ArrayList<Collection>();
for(Collection collection : this.collections){
if(collection.getName === name) {
repCollections.add(collection);
}
}
return repCollections;
}
// endregion
// region DELETE
public void deleteColletionById(long isbn){
Collection collection = getCollectionById(isbn);
this.collections.remove(collection);
}
public void deleteColletionByName(String name){
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
this.collections.remove(collectionsByName[0]);
}
public void deleteAllColletionByName(String name){
ArrayList<Collection> collectionsByName = getAllCollectionsByName(name);
this.collections.removeAll(collectionsByName);
}
// endregion
// region PUT
public void addCollection(Collection collection){
this.collections.add(collection);
}
public void addCollections(List<Collection> collections){
this.collections.addAll(collections);
}
// endregion
// region POST
public void modifyCollectionName(Collection collection, String name){
collection.setName(name);
}
public void modifyCollectionNameById(long isbn, String name){
Collection collection = getCollectionById(isbn);
modifyCollectionName(collection,name);
}
// endregion
// endregion
// region Article
public List<Article> getAllArticles(Collection collection){
return collection.getAllArticles;
}
public void addArticle(Collection collection, Article article){
collection.addArticle
}
public void deleteArticle(Collection collection, Article article){
collection.deleteArticle(article);
}
// endregion
}
Loading…
Cancel
Save