parent
cad18cf306
commit
f99c586220
@ -0,0 +1,37 @@
|
|||||||
|
@org.springframework.stereotype.Controller
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/CollectionWebService")
|
||||||
|
public class CollectionController {
|
||||||
|
private ArrayList<Collection> books = new ArrayList<>();
|
||||||
|
|
||||||
|
public Controller() {
|
||||||
|
books.add(new Book("titre1", "moi"));
|
||||||
|
books.add(new Book("titre2", "toi"));
|
||||||
|
books.add(new Book("titre3", "eux"));
|
||||||
|
books.add(new Book("titre4", "tout ceux qui le veule"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/getAllBooks", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public @ResponseBody List<Book> getAllBooks() {
|
||||||
|
return books;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/getBookById/{isbn}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public @ResponseBody Book getBookById(@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
@Entity
|
||||||
|
public class Article
|
@ -0,0 +1,44 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
public Collection(String name){
|
||||||
|
this.name = name;
|
||||||
|
this.articles = new ArrayList<Article>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Article> getAllArticles(){
|
||||||
|
return articles;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void removeArticle(Article article){
|
||||||
|
this.articles.remove(article);
|
||||||
|
}
|
||||||
|
public void removeArticles(List<Article> articles){
|
||||||
|
this.articles.removeAll(articles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue