forked from pierront/mylibrary-template
implementation du code
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.commande.repository;
|
||||||
|
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||||
|
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ComandeRepository {
|
||||||
|
|
||||||
|
private final List<Commande> commande = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<Commande> findAll(){return commande;}
|
||||||
|
|
||||||
|
public Commande save(Commande newCommande){
|
||||||
|
Optional<Commande> optionalCommandeWithSameIsbn = this.findById(newCommande.getCommandeId());
|
||||||
|
optionalCommandeWithSameIsbn.ifPresent(commande::remove);
|
||||||
|
this.commande.add(newCommande);
|
||||||
|
return newCommande;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Commande> findById(UUID uuid){
|
||||||
|
return this.commande.stream()
|
||||||
|
.filter(customer -> customer.getCommandeId().equals(uuid))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean existsById(UUID uuid) {
|
||||||
|
return this.commande.stream()
|
||||||
|
.anyMatch(customer -> customer.getCommandeId().equals(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user