Service fix, add Location and add location to client done

This commit is contained in:
Olivier PARPAILLON
2025-07-09 10:09:17 +02:00
parent b2fffa9f9f
commit 36b6313335
3 changed files with 40 additions and 18 deletions

View File

@@ -12,14 +12,6 @@ public class ClientService {
private ClientRepository clientRepository;
public void add(Client client) {
if (client.getPrenom() == null) {
Client clientTest = new Client();
clientTest.setPrenom("Olivier");
clientTest.setNom("Parpaillon");
clientTest.setEmail("olivier@test.fr");
clientRepository.save(clientTest);
} else {
clientRepository.save(client);
}
clientRepository.save(client);
}
}

View File

@@ -12,14 +12,6 @@ public class LocationService {
LocationRepository locationRepository;
public void add(Location location) {
if (location.getRue() == null || location.getCodePostal() == null || location.getVille() == null) {
Location locationTest = new Location();
locationTest.setRue("18 Rue de la Paix");
locationTest.setCodePostal("75000");
locationTest.setVille("Paris");
locationRepository.save(locationTest);
} else {
locationRepository.save(location);
}
locationRepository.save(location);
}
}

View File

@@ -3,6 +3,7 @@ package fr.eni.demo;
import fr.eni.demo.bll.ClientService;
import fr.eni.demo.bll.LocationService;
import fr.eni.demo.bo.Client;
import fr.eni.demo.bo.Location;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +28,43 @@ class DemoApplicationTests {
client.setPrenom("Olivier");
clientService.add(client);
System.out.println(client);
}
@Test
@DisplayName("-- Test add Location --")
void testAddLocation() {
Location location = new Location();
location.setRue("18 Rue de la Paix");
location.setCodePostal("75000");
location.setVille("Paris");
locationService.add(location);
System.out.println(location);
}
@Test
@DisplayName("-- Test add Client with Location --")
void testAddClientWithLocation() {
// Création du client
Client client = new Client();
client.setEmail("julien@test.fr");
client.setNom("Chateau");
client.setPrenom("Julien");
//Création de la location
Location location = new Location();
location.setRue("666 Rue des Enfers");
location.setCodePostal("44000");
location.setVille("Nantes");
locationService.add(location);
//Ajout de la location au client
client.setLocation(location);
clientService.add(client);
System.out.println(client);
System.out.println(location);
}
}