Browse Source

dev en cours

rajah 6 tháng trước cách đây
mục cha
commit
55847e5cc4

+ 21 - 2
src/main/java/fr/triplea/demovote/dao/ProductionRepository.java

@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.NativeQuery;
 import org.springframework.data.repository.query.Param;
 
+import fr.triplea.demovote.dto.ProductionChoice;
 import fr.triplea.demovote.dto.ProductionFile;
 import fr.triplea.demovote.dto.ProductionItem;
 import fr.triplea.demovote.dto.ProductionShort;
@@ -148,6 +149,7 @@ public interface ProductionRepository extends JpaRepository<Production, Integer>
       + "ORDER BY p.titre ASC ")
   List<ProductionItem> findUnlinked();
   
+  
   @NativeQuery("SELECT DISTINCT " 
       + "p.numero_production, "
       + "p.type, "
@@ -155,12 +157,29 @@ public interface ProductionRepository extends JpaRepository<Production, Integer>
       + "p.auteurs, "
       + "p.groupes, "
       + "p.plateforme, "
-      + "s.numero_ordre "
+      + "s.numero_ordre, "
+      + "p.vignette "
+      + "FROM vote.productions AS p "
+      + "INNER JOIN vote.presentations AS s ON p.numero_production = s.numero_production "
+      + "WHERE s.numero_categorie = :numero "
+      + "  AND p.flag_actif IS TRUE "
+      + "ORDER BY s.numero_ordre ASC, p.titre ASC ")
+  List<ProductionChoice> findProposed(@Param("numero") int numeroCategorie);
+
+  @NativeQuery("SELECT DISTINCT " 
+      + "p.numero_production, "
+      + "p.type, "
+      + "p.titre, "
+      + "p.auteurs, "
+      + "p.groupes, "
+      + "p.plateforme, "
+      + "s.numero_ordre, "
+      + "p.vignette "
       + "FROM vote.productions AS p "
       + "INNER JOIN vote.presentations AS s ON p.numero_production = s.numero_production "
       + "WHERE s.numero_production = :production AND s.numero_categorie = :categorie "
       + "  AND p.flag_actif IS TRUE ")
-  ProductionItem findChosen(@Param("categorie") int numeroCategorie, @Param("production") int numeroProduction);
+  ProductionChoice findChosen(@Param("categorie") int numeroCategorie, @Param("production") int numeroProduction);
   
   @Override
   void delete(Production production);

+ 52 - 0
src/main/java/fr/triplea/demovote/dto/ProductionChoice.java

@@ -0,0 +1,52 @@
+package fr.triplea.demovote.dto;
+
+import java.util.Base64;
+
+public class ProductionChoice 
+{
+  
+  Integer numeroProduction;
+  String type;
+  String titre;
+  String auteurs;
+  String groupes;
+  String plateforme;
+  Integer numeroOrdre;
+  byte[] vignette;
+  
+  public ProductionChoice(Integer numeroProduction, String type, String titre, String auteurs, String groupes, String plateforme, Integer numeroOrdre, byte[] vignette) {
+    this.numeroProduction = numeroProduction;
+    this.type = type;
+    this.titre = titre;
+    this.auteurs = auteurs;
+    this.groupes = groupes;
+    this.plateforme = plateforme;
+    this.numeroOrdre = numeroOrdre;
+    this.vignette = vignette;
+  }
+
+  public void setNumeroProduction(Integer numeroProduction) { this.numeroProduction = numeroProduction; }
+  public Integer getNumeroProduction() { return numeroProduction; }
+
+  public void setType(String type) { this.type = type; }
+  public String getType() { return type; }
+
+  public void setTitre(String titre) { this.titre = titre; }
+  public String getTitre() { return titre; }
+
+  public void setAuteurs(String auteurs) { this.auteurs = auteurs; }
+  public String getAuteurs() { return auteurs; }
+
+  public void setGroupes(String groupes) { this.groupes = groupes; }
+  public String getGroupes() { return groupes; }
+
+  public void setPlateforme(String plateforme) { this.plateforme = plateforme; }
+  public String getPlateforme() { return plateforme; }
+
+  public void setNumeroOrdre(Integer numeroOrdre) { this.numeroOrdre = numeroOrdre; }
+  public Integer getNumeroOrdre() { return numeroOrdre; }
+
+  public void setVignette(byte[] vignette) { this.vignette = vignette; }
+  public String getVignette() { if (this.vignette == null) { return ""; } return "data:image/png;base64," + Base64.getEncoder().encodeToString(this.vignette); }
+  
+}

+ 27 - 15
src/main/java/fr/triplea/demovote/web/controller/BulletinController.java

@@ -23,7 +23,7 @@ import fr.triplea.demovote.dao.ProductionRepository;
 import fr.triplea.demovote.dao.VariableRepository;
 import fr.triplea.demovote.dto.BulletinShort;
 import fr.triplea.demovote.dto.MessagesTransfer;
-import fr.triplea.demovote.dto.ProductionItem;
+import fr.triplea.demovote.dto.ProductionChoice;
 import fr.triplea.demovote.model.Bulletin;
 import fr.triplea.demovote.model.Categorie;
 import fr.triplea.demovote.model.Participant;
@@ -119,30 +119,42 @@ public class BulletinController
   }
 
   
-  @GetMapping(value = "/list/{id}")
-  @PreAuthorize("hasRole('ADMIN')")
-  public List<ProductionItem> getChosenList(@PathVariable("id") int numeroCategorie, final Authentication authentication, HttpServletRequest request) 
+  
+  @GetMapping(value = "/list-linked/{id}")
+  @PreAuthorize("hasRole('USER')")
+  public List<ProductionChoice> getProductionListLinked(@PathVariable("id") int numeroCategorie) 
+  {
+    List<ProductionChoice> prods = productionRepository.findProposed(numeroCategorie); 
+    
+    if (prods == null) { prods = new ArrayList<ProductionChoice>(); }
+
+    return prods;
+  }
+
+  @GetMapping(value = "/list-chosen/{id}")
+  @PreAuthorize("hasRole('USER')")
+  public List<ProductionChoice> getChosenList(@PathVariable("id") int numeroCategorie, final Authentication authentication, HttpServletRequest request) 
   {
     int numeroParticipant = this.getNumeroUser(authentication);
     
     BulletinShort bulletin = bulletinRepository.findByCategorieAndParticipant(numeroCategorie, numeroParticipant); 
     
-    List<ProductionItem> prods = new ArrayList<ProductionItem>();
+    List<ProductionChoice> prods = new ArrayList<ProductionChoice>();
 
     if (bulletin != null) 
     { 
       int nombreMax = Math.max(1, Math.min(Integer.parseInt(variableRepository.findByTypeAndCode("Résultats", "NOMBRE_CHOIX")), 10));        
 
-      ProductionItem prod01 = (nombreMax >= 1) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction01()) : null;
-      ProductionItem prod02 = (nombreMax >= 2) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction02()) : null;
-      ProductionItem prod03 = (nombreMax >= 3) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction03()) : null;
-      ProductionItem prod04 = (nombreMax >= 4) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction04()) : null;
-      ProductionItem prod05 = (nombreMax >= 5) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction05()) : null;
-      ProductionItem prod06 = (nombreMax >= 6) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction06()) : null;
-      ProductionItem prod07 = (nombreMax >= 7) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction07()) : null;
-      ProductionItem prod08 = (nombreMax >= 8) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction08()) : null;
-      ProductionItem prod09 = (nombreMax >= 9) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction09()) : null;
-      ProductionItem prod10 = (nombreMax >= 10) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction10()) : null;
+      ProductionChoice prod01 = (nombreMax >= 1) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction01()) : null;
+      ProductionChoice prod02 = (nombreMax >= 2) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction02()) : null;
+      ProductionChoice prod03 = (nombreMax >= 3) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction03()) : null;
+      ProductionChoice prod04 = (nombreMax >= 4) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction04()) : null;
+      ProductionChoice prod05 = (nombreMax >= 5) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction05()) : null;
+      ProductionChoice prod06 = (nombreMax >= 6) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction06()) : null;
+      ProductionChoice prod07 = (nombreMax >= 7) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction07()) : null;
+      ProductionChoice prod08 = (nombreMax >= 8) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction08()) : null;
+      ProductionChoice prod09 = (nombreMax >= 9) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction09()) : null;
+      ProductionChoice prod10 = (nombreMax >= 10) ? productionRepository.findChosen(numeroCategorie, bulletin.getNumeroProduction10()) : null;
       
       if ((prod01 != null) && (nombreMax >= 1)) { prods.add(prod01); }
       if ((prod02 != null) && (nombreMax >= 2)) { prods.add(prod02); }