forked from pierront/mylibrary-template
suite de l'impementation
This commit is contained in:
+11
@@ -41,4 +41,15 @@ public final class CommandeConverter {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CommandeDTO toDTO(Commande commande) {
|
||||
return CommandeDTO.builder()
|
||||
.lignesCommande(commande.getLignesCommande())
|
||||
.rue(commande.getRue())
|
||||
.ville(commande.getVille())
|
||||
.codePostal(commande.getCodePostal())
|
||||
.pays(commande.getPays())
|
||||
.modePaiement(commande.getModePaiement())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
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.repository.CommandeRepository;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.validator.CommandeValidator;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandeUseCase {
|
||||
|
||||
private final CommandeRepository commandeRepository;
|
||||
|
||||
public CommandeUseCase(CommandeRepository commandeRepository) {
|
||||
this.commandeRepository = commandeRepository;
|
||||
}
|
||||
|
||||
|
||||
public UUID registerCommande(CommandeInfo validCommandeInfo, AdresseInfo validAdresseInfo){
|
||||
CommandeValidator.validate(validCommandeInfo);
|
||||
CommandeValidator.validate(validAdresseInfo);
|
||||
|
||||
Commande commandeToRegister = CommandeConverter.toDomain(validCommandeInfo,validAdresseInfo);
|
||||
Commande commandeToRegistered = commandeRepository.save(commandeToRegister) ;
|
||||
return commandeToRegistered.getCommandeId();
|
||||
|
||||
}
|
||||
|
||||
public Optional<CommandeDTO> findCommandByUUID(UUID uuid) {
|
||||
Optional<Commande> optionalCommande = commandeRepository.findById(uuid);
|
||||
return optionalCommande.map(CommandeConverter::toDTO);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-7
@@ -2,10 +2,7 @@ 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.entity.Book;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.AdresseInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.CommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.ModePaiement;
|
||||
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.NotValidCommandeException;
|
||||
import fr.iut_fbleau.but3.dev62.mylibrary.commande.repository.CommandeRepository;
|
||||
@@ -117,10 +114,10 @@ public class TestCommandeUseCase {
|
||||
void testFindCommandByUUID() {
|
||||
when(commandeRepository.findById(testCommande.getCommandeId())).thenReturn(Optional.of(testCommande));
|
||||
|
||||
Optional<BookDTO> foundCommande = commandeUseCase.findCommandByUUID(testCommande.getCommandeId());
|
||||
Optional<CommandeDTO> foundCommande = commandeUseCase.findCommandByUUID(testCommande.getCommandeId());
|
||||
|
||||
assertTrue(foundCommande.isPresent());
|
||||
assertEquals(testCommande.getCommandeId(), foundCommande.get().getIsbn());
|
||||
assertEquals(testCommande.getCommandeId(), foundCommande.get().getCommandeId());
|
||||
verify(commandeRepository, times(1)).findById(testCommande.getCommandeId());
|
||||
}
|
||||
|
||||
@@ -131,7 +128,7 @@ public class TestCommandeUseCase {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
when(commandeRepository.findById(uuid)).thenReturn(Optional.empty());
|
||||
|
||||
Optional<BookDTO> foundCommande = commandeUseCase.findCommandByUUID(uuid);
|
||||
Optional<CommandeDTO> foundCommande = commandeUseCase.findCommandByUUID(uuid);
|
||||
|
||||
assertTrue(foundCommande.isEmpty());
|
||||
verify(commandeRepository, times(1)).findById(uuid);
|
||||
|
||||
Reference in New Issue
Block a user