parent
29abf4d5c9
commit
296f34328f
@ -1,50 +0,0 @@
|
|||||||
<?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,16 @@
|
|||||||
|
package SAE.ApiREST.WebService.controller;
|
||||||
|
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/CollectWebService")
|
||||||
|
public class CollectController {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,109 +0,0 @@
|
|||||||
package SAE.ApiREST.WebService.controller;
|
|
||||||
|
|
||||||
@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
|
|
||||||
}
|
|
Loading…
Reference in new issue