Create Service, Entity and Repository for Client and Location. Client add test to BDD done
This commit is contained in:
25
src/main/java/fr/eni/demo/bll/ClientService.java
Normal file
25
src/main/java/fr/eni/demo/bll/ClientService.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package fr.eni.demo.bll;
|
||||
|
||||
import fr.eni.demo.bo.Client;
|
||||
import fr.eni.demo.dal.ClientRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ClientService {
|
||||
|
||||
@Autowired
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,14 @@ package fr.eni.demo.bll;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
import fr.eni.demo.bo.Employe;
|
||||
import fr.eni.demo.dal.EmployeDAO;
|
||||
import fr.eni.demo.dal.EmployeRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
//Permet de faire injecter la couche DAL associée
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class EmployeServiceImpl implements EmployeService {
|
||||
private EmployeDAO employeRepository;
|
||||
private EmployeRepository employeRepository;
|
||||
|
||||
@Override
|
||||
public void ajouter(Employe employe) {
|
||||
|
||||
25
src/main/java/fr/eni/demo/bll/LocationService.java
Normal file
25
src/main/java/fr/eni/demo/bll/LocationService.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package fr.eni.demo.bll;
|
||||
|
||||
import fr.eni.demo.bo.Location;
|
||||
import fr.eni.demo.dal.LocationRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class LocationService {
|
||||
|
||||
@Autowired
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package fr.eni.demo.bll;
|
||||
|
||||
class TestEmployeService {
|
||||
}
|
||||
33
src/main/java/fr/eni/demo/bo/Client.java
Normal file
33
src/main/java/fr/eni/demo/bo/Client.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package fr.eni.demo.bo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
|
||||
@Entity
|
||||
@Table(name="CLIENTS")
|
||||
public class Client {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "CLIENT_ID")
|
||||
private Integer id;
|
||||
|
||||
@Column(name= "LAST_NAME", nullable = false, length = 90)
|
||||
private String nom;
|
||||
|
||||
@Column(name= "FIRST_NAME", nullable = false, length = 150)
|
||||
private String prenom;
|
||||
|
||||
@Column(nullable = false, unique = true)
|
||||
private String email;
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "LOCATION_ID")
|
||||
private Location location;
|
||||
}
|
||||
31
src/main/java/fr/eni/demo/bo/Location.java
Normal file
31
src/main/java/fr/eni/demo/bo/Location.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package fr.eni.demo.bo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Builder
|
||||
|
||||
@Entity
|
||||
@Table(name="LOCATIONS")
|
||||
public class Location {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "LOCATION_ID")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "STREET",nullable = false, length = 250)
|
||||
private String rue;
|
||||
|
||||
@Column(name = "POSTAL_CODE",nullable = false, length = 5)
|
||||
private String codePostal;
|
||||
|
||||
@Column(name = "CITY",nullable = false, length = 150)
|
||||
private String ville;
|
||||
|
||||
}
|
||||
9
src/main/java/fr/eni/demo/dal/ClientRepository.java
Normal file
9
src/main/java/fr/eni/demo/dal/ClientRepository.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package fr.eni.demo.dal;
|
||||
|
||||
import fr.eni.demo.bo.Client;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ClientRepository extends JpaRepository<Client, Integer> {
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package fr.eni.demo.dal;
|
||||
import java.util.List;
|
||||
import fr.eni.demo.bo.Employe;
|
||||
|
||||
public interface EmployeDAO {
|
||||
public interface EmployeRepository {
|
||||
void create(Employe employe);
|
||||
|
||||
Employe read(Integer id);
|
||||
@@ -6,7 +6,7 @@ import fr.eni.demo.bo.Employe;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class EmployeDAOImpl implements EmployeDAO {
|
||||
public class EmployeRepositoryImpl implements EmployeRepository {
|
||||
private List<Employe> employes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
9
src/main/java/fr/eni/demo/dal/LocationRepository.java
Normal file
9
src/main/java/fr/eni/demo/dal/LocationRepository.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package fr.eni.demo.dal;
|
||||
|
||||
import fr.eni.demo.bo.Location;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface LocationRepository extends JpaRepository<Location, Long> {
|
||||
}
|
||||
Reference in New Issue
Block a user