implementation du code

This commit is contained in:
2026-06-14 12:45:05 +02:00
committed by Marvin AUBERT
parent 1ac8896253
commit a5c26c62e3
@@ -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));
}
}