Jelajahi Sumber

dev en cours

rajah 1 tahun lalu
induk
melakukan
5f3e27d429

+ 82 - 1
src/main/java/fr/triplea/demovote/persistence/dao/ParticipantRepository.java

@@ -1,13 +1,16 @@
 package fr.triplea.demovote.persistence.dao;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.NativeQuery;
 import org.springframework.data.repository.query.Param;
 
 import fr.triplea.demovote.persistence.model.Participant;
 import fr.triplea.demovote.persistence.model.Role;
+import jakarta.transaction.Transactional;
 
 public interface ParticipantRepository extends JpaRepository<Participant, Integer> 
 {
@@ -32,7 +35,85 @@ public interface ParticipantRepository extends JpaRepository<Participant, Intege
 
   @NativeQuery("SELECT DISTINCT p.* FROM vote.participants AS p WHERE p.flag_dodo_sur_place = :dodo AND p.flag_actif IS TRUE ORDER BYp.nom ASC, p.prenom ASC, p.pseudonyme ASC ")
   List<Participant> findBySleepingOnSite(@Param("dodo") boolean flag_dodo_sur_place);
-
+  
+  @Transactional 
+  @Modifying
+  @NativeQuery("INSERT INTO vote.participants ("
+      + "  nom,"
+      + "  prenom,"
+      + "  pseudonyme,"
+      + "  groupe,"
+      + "  delai_deconnexion,"
+      + "  mot_de_passe,"
+      + "  adresse,"
+      + "  code_postal,"
+      + "  ville,"
+      + "  pays,"
+      + "  numero_telephone,"
+      + "  email,"
+      + "  commentaire,"
+      + "  flag_machine,"
+      + "  flag_jour1,"
+      + "  flag_jour2,"
+      + "  flag_jour3,"
+      + "  flag_dodo_sur_place,"
+      + "  flag_amigabus,"
+      + "  status,"
+      + "  mode_paiement,"
+      + "  somme_recue,"
+      + "  flag_arrive "
+      + ") VALUES ("
+      + "  :nom,"
+      + "  :prenom,"
+      + "  :pseudonyme,n"
+      + "  :groupe,n"
+      + "  :delai_deconnexion,"
+      + "  :mot_de_passe,"
+      + "  :adresse,"
+      + "  :code_postal,"
+      + "  :ville,"
+      + "  :pays,"
+      + "  :numero_telephone,"
+      + "  :email,"
+      + "  :commentaire,"
+      + "  :flag_machine,"
+      + "  :flag_jour1,"
+      + "  :flag_jour2,"
+      + "  :flag_jour3,"
+      + "  :flag_dodo_sur_place,"
+      + "  :flag_amigabus,"
+      + "  :status::vote.status_participant,"
+      + "  :mode_paiement::vote.mode_paiement,"
+      + "  :somme_recue,"
+      + "  :flag_arrive"
+      + ") ")
+  public void create(
+    @Param("nom") String nom,
+    @Param("prenom") String prenom,
+    @Param("pseudonyme") String pseudonyme,
+    @Param("groupe") String groupe,
+    @Param("delai_deconnexion") int delai_deconnexion,
+    @Param("mot_de_passe") String mot_de_passe,
+    @Param("adresse") String adresse,
+    @Param("code_postal") String code_postal,
+    @Param("ville") String ville,
+    @Param("pays") String pays,
+    @Param("numero_telephone") String numero_telephone,
+    @Param("email") String email,
+    @Param("status") String tatus,
+    @Param("flag_machine") boolean flag_machine,
+    @Param("commentaire") String commentaire,
+    @Param("flag_jour1") boolean flag_jour1,
+    @Param("flag_jour2") boolean flag_jour2,
+    @Param("flag_jour3") boolean flag_jour3,
+    @Param("flag_dodo_sur_place") boolean flag_dodo_sur_place,
+    @Param("flag_amigabus") boolean flag_amigabus,
+    @Param("mode_paiement") String mode_paiement,
+    @Param("somme_recue") BigDecimal somme_recue,
+    @Param("flag_arrive") boolean flag_arrive
+    );  
+  
+  
   @Override
   void delete(Participant participant);
 

+ 6 - 0
src/main/java/fr/triplea/demovote/persistence/model/Participant.java

@@ -16,6 +16,7 @@ import com.google.common.collect.Sets;
 
 import jakarta.persistence.CascadeType;
 import jakarta.persistence.Column;
+import jakarta.persistence.Convert;
 import jakarta.persistence.Entity;
 import jakarta.persistence.EnumType;
 import jakarta.persistence.Enumerated;
@@ -103,6 +104,7 @@ public class Participant
   private String email;
 
   @Enumerated(EnumType.STRING) 
+  @Convert(converter = ParticipantStatusConverter.class)
   private ParticipantStatus status;
 
   @Column(name = "flag_machine")
@@ -126,9 +128,11 @@ public class Participant
   private Boolean useAmigabus = false;
 
   @Enumerated(EnumType.STRING) 
+  @Convert(converter = ParticipantModePaiementConverter.class)
   private ParticipantModePaiement modePaiement;
   
   @Temporal(TemporalType.TIMESTAMP)
+  @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="dd/MM/yyyy HH:mm:ss", timezone="Europe/Paris")
   private LocalDateTime dateInscription;
   
   @Column(precision=10, scale=2)
@@ -173,12 +177,14 @@ public class Participant
   
   public void setNom(String str) { if (str != null) { this.nom = StringUtils.truncate(str, 128); } }
   public String getNom() { return this.nom; }
+  public boolean hasNom() { if (this.nom == null) { return false; } if (this.nom.isBlank()) { return false; } return true; }
   
   public void setPrenom(String str) { if (str != null) { this.prenom = StringUtils.truncate(str, 128); } }
   public String getPrenom() { return this.prenom; }
   
   public void setPseudonyme(String str) { if (str != null) { this.pseudonyme = StringUtils.truncate(str, 128); } }
   public String getPseudonyme() { return this.pseudonyme; }
+  public boolean hasPseudonyme() { if (this.pseudonyme == null) { return false; } if (this.pseudonyme.isBlank()) { return false; } return true; }
   
   public void setGroupe(String str) { if (str != null) { this.groupe = StringUtils.truncate(str, 128); } }
   public String getGroupe() { return this.groupe; }

+ 4 - 9
src/main/java/fr/triplea/demovote/persistence/model/ParticipantModePaiement.java

@@ -1,9 +1,5 @@
 package fr.triplea.demovote.persistence.model;
 
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Map;
-
 public enum ParticipantModePaiement 
 {
   
@@ -11,15 +7,14 @@ public enum ParticipantModePaiement
 
   private String mode;
   
-  private static Map<String, ParticipantModePaiement> types = new HashMap<String, ParticipantModePaiement>();
+  private ParticipantModePaiement(String mode) { this.mode = mode; }
 
-  static { for(ParticipantModePaiement r : EnumSet.allOf(ParticipantModePaiement.class)) { types.put(r.toString(), r); } }
+  public String getMode() { return this.mode; }
 
-  public static ParticipantModePaiement getType(String mode) { return types.get(mode); }
-
-  private ParticipantModePaiement(String mode) { this.mode = mode; }
+  public static ParticipantModePaiement getByMode(String str) { for (ParticipantModePaiement enu : ParticipantModePaiement.values()) { if (enu.getMode().equals(str)) { return enu; } } return null; }
 
   @Override
   public String toString() { return mode; }
 
+
 }

+ 14 - 0
src/main/java/fr/triplea/demovote/persistence/model/ParticipantModePaiementConverter.java

@@ -0,0 +1,14 @@
+package fr.triplea.demovote.persistence.model;
+
+import jakarta.persistence.AttributeConverter;
+import jakarta.persistence.Converter;
+
+@Converter(autoApply = true)
+public class ParticipantModePaiementConverter implements AttributeConverter<ParticipantModePaiement, String> 
+{
+  @Override
+  public String convertToDatabaseColumn(ParticipantModePaiement val) { return val != null ? val.getMode() : null; }
+
+  @Override
+  public ParticipantModePaiement convertToEntityAttribute(String str) { return str != null ? ParticipantModePaiement.getByMode(str) : null; }
+}

+ 4 - 10
src/main/java/fr/triplea/demovote/persistence/model/ParticipantStatus.java

@@ -1,24 +1,18 @@
 package fr.triplea.demovote.persistence.model;
 
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Map;
-
 public enum ParticipantStatus 
 {
   
   EN_ATTENTE("En attente"), PAYE_CHEQUE("Payé chèque"), PAYE_ESPECES("Payé espèces"), VIREMENT_BANCAIRE("Virement bancaire"), VIREMENT_PAYPAL("Virement Paypal"), ORGA("Orga"), GUEST("Guest");
 
   private String status;
-  
-  private static Map<String, ParticipantStatus> liste = new HashMap<String, ParticipantStatus>();
 
-  static { for(ParticipantStatus r : EnumSet.allOf(ParticipantStatus.class)) { liste.put(r.toString(), r); } }
+  private ParticipantStatus(String status) { this.status = status; }
 
-  public static ParticipantStatus getType(String s) { return liste.get(s); }
-
-  private ParticipantStatus(String mode) { this.status = mode; }
+  public String getStatus() { return this.status; }
 
+  public static ParticipantStatus getByStatus(String str) { for (ParticipantStatus enu : ParticipantStatus.values()) { if (enu.getStatus().equals(str)) { return enu; } } return null; }
+  
   @Override
   public String toString() { return status; }
 

+ 14 - 0
src/main/java/fr/triplea/demovote/persistence/model/ParticipantStatusConverter.java

@@ -0,0 +1,14 @@
+package fr.triplea.demovote.persistence.model;
+
+import jakarta.persistence.AttributeConverter;
+import jakarta.persistence.Converter;
+
+@Converter(autoApply = true)
+public class ParticipantStatusConverter implements AttributeConverter<ParticipantStatus, String> 
+{
+  @Override
+  public String convertToDatabaseColumn(ParticipantStatus val) { return val != null ? val.getStatus() : null; }
+
+  @Override
+  public ParticipantStatus convertToEntityAttribute(String str) { return str != null ? ParticipantStatus.getByStatus(str) : null; }
+}

+ 2 - 0
src/main/java/fr/triplea/demovote/persistence/model/Production.java

@@ -16,6 +16,7 @@ import io.hypersistence.utils.hibernate.type.basic.Inet;
 import io.hypersistence.utils.hibernate.type.basic.PostgreSQLInetType;
 import jakarta.persistence.CascadeType;
 import jakarta.persistence.Column;
+import jakarta.persistence.Convert;
 import jakarta.persistence.Entity;
 import jakarta.persistence.EnumType;
 import jakarta.persistence.Enumerated;
@@ -64,6 +65,7 @@ public class Production
   private Inet adresseIP;
  
   @Enumerated(EnumType.STRING) 
+  @Convert(converter = ProductionTypeConverter.class)
   private ProductionType type;
   
   @Column(length = 256, nullable = false)

+ 3 - 9
src/main/java/fr/triplea/demovote/persistence/model/ProductionType.java

@@ -1,23 +1,17 @@
 package fr.triplea.demovote.persistence.model;
 
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Map;
-
 public enum ProductionType 
 { 
   
   EXECUTABLE("Exécutable"), GRAPHE("Graphe"), MUSIQUE("Musique"), VIDEO("Vidéo"), TOPIC("Topic"), AUTRE("Autre");
 
   private String type;
-  
-  private static Map<String, ProductionType> types = new HashMap<String, ProductionType>();
 
-  static { for(ProductionType r : EnumSet.allOf(ProductionType.class)) { types.put(r.toString(), r); } }
+  private ProductionType(String type) { this.type = type; }
 
-  public static ProductionType getType(String type) { return types.get(type); }
+  public String getType() { return this.type; }
 
-  private ProductionType(String type) { this.type = type; }
+  public static ProductionType getByType(String str) { for (ProductionType enu : ProductionType.values()) { if (enu.getType().equals(str)) { return enu; } } return null; }
 
   @Override
   public String toString() { return type; }

+ 14 - 0
src/main/java/fr/triplea/demovote/persistence/model/ProductionTypeConverter.java

@@ -0,0 +1,14 @@
+package fr.triplea.demovote.persistence.model;
+
+import jakarta.persistence.AttributeConverter;
+import jakarta.persistence.Converter;
+
+@Converter(autoApply = true)
+public class ProductionTypeConverter implements AttributeConverter<ProductionType, String> 
+{
+  @Override
+  public String convertToDatabaseColumn(ProductionType val) { return val != null ? val.getType() : null; }
+
+  @Override
+  public ProductionType convertToEntityAttribute(String str) { return str != null ? ProductionType.getByType(str) : null; }
+}

+ 6 - 1
src/main/java/fr/triplea/demovote/web/controller/ParticipantController.java

@@ -1,5 +1,6 @@
 package fr.triplea.demovote.web.controller;
 
+import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -62,7 +63,11 @@ public class ParticipantController
     if (participant.getStatus() == null) { participant.setStatus(ParticipantStatus.EN_ATTENTE); }
     if (participant.getModePaiement() == null) { participant.setModePaiement(ParticipantModePaiement.ESPECES); }
     
-    return participantRepository.save(participant);
+    participant.setDateInscription(LocalDateTime.now());
+    
+    if (participant.hasNom() && participant.hasPseudonyme()) { return participantRepository.save(participant); }
+    
+    return null;
   }
 
   @PutMapping(value = "/update/{id}")