init
This commit is contained in:
13
src/main/java/fr/eni/demo/DemoApplication.java
Normal file
13
src/main/java/fr/eni/demo/DemoApplication.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package fr.eni.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
10
src/main/java/fr/eni/demo/bll/EmployeService.java
Normal file
10
src/main/java/fr/eni/demo/bll/EmployeService.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package fr.eni.demo.bll;
|
||||
|
||||
import fr.eni.demo.bo.Employe;
|
||||
import java.util.List;
|
||||
|
||||
public interface EmployeService {
|
||||
void ajouter(Employe employe);
|
||||
|
||||
List<Employe> chargerTousEmployes();
|
||||
}
|
||||
46
src/main/java/fr/eni/demo/bll/EmployeServiceImpl.java
Normal file
46
src/main/java/fr/eni/demo/bll/EmployeServiceImpl.java
Normal file
@@ -0,0 +1,46 @@
|
||||
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 lombok.AllArgsConstructor;
|
||||
|
||||
//Permet de faire injecter la couche DAL associée
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class EmployeServiceImpl implements EmployeService {
|
||||
private EmployeDAO employeRepository;
|
||||
|
||||
@Override
|
||||
public void ajouter(Employe employe) {
|
||||
// Validation des données de l'employé avant sauvegarde
|
||||
if (employe == null) {
|
||||
throw new RuntimeException("L'employé n'est pas renseigné");
|
||||
}
|
||||
validerImmatriculation(employe);
|
||||
validerChaineNonNulle(employe.getNom(), "Vous devez renseigner le nom");
|
||||
validerChaineNonNulle(employe.getPrenom(), "Vous devez renseigner le prénom");
|
||||
validerChaineNonNulle(employe.getEmail(), "Vous devez renseigner un email");
|
||||
employeRepository.create(employe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Employe> chargerTousEmployes() {
|
||||
return employeRepository.findAll();
|
||||
}
|
||||
|
||||
private void validerChaineNonNulle(String chaine, String msgErreur) {
|
||||
if (chaine == null || chaine.isBlank())
|
||||
throw new RuntimeException(msgErreur);
|
||||
}
|
||||
private void validerImmatriculation(Employe employe) {
|
||||
// Valider que l'immatriculation n'est pas nule ou vide
|
||||
validerChaineNonNulle(employe.getImmatriculation(), "L'immatriculation n'a pas été renseignée");
|
||||
// Immatriculation doit être unique
|
||||
Employe employeDB = employeRepository.findByImmatriculation(employe.getImmatriculation());
|
||||
if (employeDB != null) {
|
||||
throw new RuntimeException("L'immatriculation doit être unique");
|
||||
}
|
||||
}
|
||||
}
|
||||
4
src/main/java/fr/eni/demo/bll/TestEmployeService.java
Normal file
4
src/main/java/fr/eni/demo/bll/TestEmployeService.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package fr.eni.demo.bll;
|
||||
|
||||
class TestEmployeService {
|
||||
}
|
||||
39
src/main/java/fr/eni/demo/bo/Employe.java
Normal file
39
src/main/java/fr/eni/demo/bo/Employe.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package fr.eni.demo.bo;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
//@Data
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(of= {"immatriculation"})
|
||||
@ToString
|
||||
//@Builder
|
||||
|
||||
@Entity
|
||||
@Table(name="EMPLOYES")
|
||||
public class Employe {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "EMPLOYEE_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;
|
||||
|
||||
@Column(name= "EMPLOYE_REGISTRATION", nullable = false, unique = true, length = 100)
|
||||
private String immatriculation;
|
||||
|
||||
@Column(name= "HOME_PHONE_NUMBER", nullable = false, length = 12)
|
||||
private String numDom;
|
||||
|
||||
@Column(name= "PHONE_NUMBER", nullable = false, length = 12)
|
||||
private String numPortable;
|
||||
}
|
||||
18
src/main/java/fr/eni/demo/dal/EmployeDAO.java
Normal file
18
src/main/java/fr/eni/demo/dal/EmployeDAO.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package fr.eni.demo.dal;
|
||||
|
||||
import java.util.List;
|
||||
import fr.eni.demo.bo.Employe;
|
||||
|
||||
public interface EmployeDAO {
|
||||
void create(Employe employe);
|
||||
|
||||
Employe read(Integer id);
|
||||
|
||||
Employe findByImmatriculation(String immatriculation);
|
||||
|
||||
List<Employe> findAll();
|
||||
|
||||
void update(Employe employe);
|
||||
|
||||
void delete(Employe employe);
|
||||
}
|
||||
43
src/main/java/fr/eni/demo/dal/EmployeDAOImpl.java
Normal file
43
src/main/java/fr/eni/demo/dal/EmployeDAOImpl.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package fr.eni.demo.dal;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import fr.eni.demo.bo.Employe;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class EmployeDAOImpl implements EmployeDAO {
|
||||
private List<Employe> employes = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void create(Employe employe) {
|
||||
employes.add(employe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Employe read(Integer id) {
|
||||
return employes.stream().filter(item -> item.getId() == id).findAny().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Employe findByImmatriculation(String immatriculation) {
|
||||
return employes.stream().filter(item -> item.getImmatriculation() == immatriculation).findAny().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Employe> findAll() {
|
||||
return employes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Employe employe) {
|
||||
Employe emp = read(employe.getId());
|
||||
if (emp != null) {
|
||||
emp.setEmail(employe.getEmail());
|
||||
emp.setPrenom(employe.getPrenom());
|
||||
}
|
||||
}
|
||||
@Override public void delete(Employe employe) {
|
||||
employes.remove(employe);
|
||||
}
|
||||
}
|
||||
18
src/main/resources/application.yml
Normal file
18
src/main/resources/application.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
spring:
|
||||
application:
|
||||
name: demo1
|
||||
#Connection to DB
|
||||
datasource:
|
||||
url: jdbc:sqlserver://localhost;databasename=ludotheque;integratedSecurity=false;encrypt=false;trustServerCertificate=false
|
||||
username: sa
|
||||
password: Pa$$w0rd
|
||||
|
||||
#Options to DB
|
||||
jpa:
|
||||
show-sql: true
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
hibernate:
|
||||
ddl-auto: create
|
||||
|
||||
Reference in New Issue
Block a user