forked from pierront/mylibrary-template
✅ test passé
This commit is contained in:
@@ -16,10 +16,8 @@ public class CommandeDTO {
|
||||
private String codePostal;
|
||||
private String pays;
|
||||
private String modePaiement;
|
||||
|
||||
|
||||
private UUID commandeId ;
|
||||
private double montantTotal ;
|
||||
private double montantTotal ;
|
||||
private Integer pointsFideliteGagnes ;
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -49,6 +49,10 @@ public final class CommandeConverter {
|
||||
.codePostal(commande.getCodePostal())
|
||||
.pays(commande.getPays())
|
||||
.modePaiement(commande.getModePaiement())
|
||||
.commandeId(commande.getCommandeId())
|
||||
.clientId(commande.getClientId())
|
||||
.montantTotal(commande.getMontantTotal())
|
||||
.pointsFideliteGagnes(commande.getPointsFideliteGagnes())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandeNotFoundException extends RuntimeException {
|
||||
|
||||
public static final String THE_COMMANDE_WITH_ID_DOES_NOT_EXIST_MESSAGE = "The commande with id {0} does not exist";
|
||||
|
||||
public CommandeNotFoundException(UUID uuid) {
|
||||
super(MessageFormat.format(THE_COMMANDE_WITH_ID_DOES_NOT_EXIST_MESSAGE, uuid));
|
||||
}
|
||||
}
|
||||
+35
-3
@@ -1,13 +1,12 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.usecase;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.BookDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.converter.BookConverter;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.book.entity.Book;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.AdresseInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.CommandeDTO;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.CommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.converter.CommandeConverter;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.CommandeNotFoundException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidCommandeException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.repository.CommandeRepository;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.validator.CommandeValidator;
|
||||
|
||||
@@ -38,4 +37,37 @@ public class CommandeUseCase {
|
||||
return optionalCommande.map(CommandeConverter::toDTO);
|
||||
}
|
||||
|
||||
public CommandeDTO updateCommande(UUID uuid, CommandeInfo commandeInfo, AdresseInfo adresseInfo)
|
||||
throws CommandeNotFoundException, NotValidCommandeException {
|
||||
CommandeValidator.validate(commandeInfo);
|
||||
CommandeValidator.validate(adresseInfo);
|
||||
Commande commandeByUUID = getCommandeIfDoesNotExistThrowCommandeNotFoundException(
|
||||
uuid);
|
||||
Commande commande = Commande.builder()
|
||||
.clientId(commandeByUUID.getClientId())
|
||||
.lignesCommande(commandeInfo.listeLigne())
|
||||
.rue(adresseInfo.rue())
|
||||
.ville(adresseInfo.ville())
|
||||
.codePostal(adresseInfo.codePostal())
|
||||
.pays(adresseInfo.pays())
|
||||
.modePaiement(commandeInfo.modePayement())
|
||||
.commandeId(uuid)
|
||||
.build();
|
||||
Commande updatedCommande = commandeRepository.save(commande);
|
||||
return CommandeConverter.toDTO(updatedCommande);
|
||||
}
|
||||
|
||||
public void deleteCommande(UUID uuid) throws CommandeNotFoundException {
|
||||
Commande commandeToDelete = getCommandeIfDoesNotExistThrowCommandeNotFoundException(uuid);
|
||||
this.commandeRepository.delete(commandeToDelete);
|
||||
}
|
||||
|
||||
private Commande getCommandeIfDoesNotExistThrowCommandeNotFoundException(UUID uuid)
|
||||
throws CommandeNotFoundException {
|
||||
Optional<Commande> optionalCommandeById = commandeRepository.findById(uuid);
|
||||
if (optionalCommandeById.isEmpty()) {
|
||||
throw new CommandeNotFoundException(uuid);
|
||||
}
|
||||
return optionalCommandeById.get();
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -1,5 +1,6 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.valid;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.CommandeNotFoundException;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
+1
@@ -2,6 +2,7 @@ package fr.iut_fbleau.but3.dev62.mylibrary.commande.usecase;
|
||||
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.*;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.entity.Commande;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.CommandeNotFoundException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.exception.NotValidCommandeException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.repository.CommandeRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
Reference in New Issue
Block a user