rajah 11 месяцев назад
Родитель
Сommit
49bd4e85f6

+ 8 - 3
src/main/java/fr/triplea/demovote/dao/PresentationRepository.java

@@ -6,13 +6,18 @@ 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.model.Categorie;
 import fr.triplea.demovote.model.Presentation;
 
 public interface PresentationRepository extends JpaRepository<Presentation, Integer> 
 {
   
-  @NativeQuery("SELECT DISTINCT p.* FROM vote.presentations AS p WHERE p.numero_categorie = :categorie ")
-  List<Presentation> findByCategorie(@Param("categorie") Categorie categorie);
+  @NativeQuery("SELECT DISTINCT MAX(p.numero_ordre) FROM vote.presentations AS p WHERE p.numero_categorie = :numero ")
+  Integer countByCategorie(@Param("numero") int numeroCategorie);
+  
+  @NativeQuery("SELECT DISTINCT p.* FROM vote.presentations AS p WHERE p.numero_categorie = :numero_cat AND p.numero_production = :numero_prod ")
+  Presentation findByCategorieAndProduction(@Param("numero_cat") int numeroCategorie, @Param("numero_prod") int numeroProduction);
+  
+  @NativeQuery("SELECT DISTINCT p.* FROM vote.presentations AS p WHERE p.numero_categorie = :numero ORDER BY p.numero_ordre ASC ")
+  List<Presentation> findByCategorie(@Param("numero") int numeroCategorie);
 
 }

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

@@ -7,8 +7,8 @@ import org.springframework.data.jpa.repository.NativeQuery;
 import org.springframework.data.repository.query.Param;
 
 import fr.triplea.demovote.dto.ProductionFile;
+import fr.triplea.demovote.dto.ProductionItem;
 import fr.triplea.demovote.dto.ProductionShort;
-import fr.triplea.demovote.model.Participant;
 import fr.triplea.demovote.model.Production;
 
 
@@ -34,12 +34,13 @@ public interface ProductionRepository extends JpaRepository<Production, Integer>
               + "CONCAT(g.pseudonyme, ' = ', g.nom, ' ', g.prenom) AS nom_gestionnaire, "
               + "p.nom_archive, "
               + "p.vignette, "
-              + "p.numero_version "
+              + "p.numero_version,"
+              + "0 AS numero_categorie "
               + "FROM vote.productions AS p "
               + "INNER JOIN vote.participants AS g ON p.numero_participant = g.numero_participant "
               + "WHERE p.flag_actif IS TRUE "
-              + "AND ((:numero = 0) OR (:numero = p.numero_participant)) "
-              + "AND ((:type IS NULL) OR (p.type = (:type)::vote.type_production)) "
+              + "  AND ((:numero = 0) OR (:numero = p.numero_participant)) "
+              + "  AND ((:type IS NULL) OR (p.type = (:type)::vote.type_production)) "
               + "ORDER BY p.titre ASC ")
   List<ProductionShort> findAllWithoutArchive(@Param("numero") int numeroGestionnaire, @Param("type") String type);
   
@@ -59,10 +60,12 @@ public interface ProductionRepository extends JpaRepository<Production, Integer>
               + "CONCAT(g.pseudonyme, ' = ', g.nom, ' ', g.prenom) AS nom_gestionnaire, "
               + "p.nom_archive, "
               + "p.vignette, "
-              + "p.numero_version "
+              + "p.numero_version,"
+              + "0 AS numero_categorie "
               + "FROM vote.productions AS p "
               + "INNER JOIN vote.participants AS g ON p.numero_participant = g.numero_participant "
-              + "WHERE p.numero_production = :numeroProduction AND p.flag_actif IS TRUE ")
+              + "WHERE p.numero_production = :numeroProduction "
+              + "  AND p.flag_actif IS TRUE ")
   ProductionShort findByIdWithoutArchive(@Param("numeroProduction") Integer numeroProduction);
 
   @NativeQuery("SELECT DISTINCT " 
@@ -72,31 +75,38 @@ public interface ProductionRepository extends JpaRepository<Production, Integer>
       + "p.nom_archive, "
       + "'' AS archive "
       + "FROM vote.productions AS p "
-      + "WHERE p.numero_production = :numeroProduction AND p.flag_actif IS TRUE ")
+      + "WHERE p.numero_production = :numeroProduction "
+      + "  AND p.flag_actif IS TRUE ")
   ProductionFile findByIdForUpload(@Param("numeroProduction") Integer numeroProduction);
   
   @NativeQuery("SELECT DISTINCT " 
-      + "TO_CHAR(p.date_creation, 'DD/MM/YYYY HH24:MI:SS') as date_creation, "
-      + "TO_CHAR(p.date_modification, 'DD/MM/YYYY HH24:MI:SS') as date_modification, "
       + "p.numero_production, "
-      + "CAST(p.adresse_ip AS VARCHAR) AS adresse_ip, "
       + "p.type, "
       + "p.titre, "
       + "p.auteurs, "
       + "p.groupes, "
       + "p.plateforme, "
-      + "p.commentaire, "
-      + "p.informations_privees, "
-      + "p.numero_participant AS numero_gestionnaire, "
-      + "CONCAT(g.pseudonyme, ' = ', g.nom, ' ', g.prenom) AS nom_gestionnaire, "
-      + "p.nom_archive, "
-      + "p.vignette, "
-      + "p.numero_version "
+      + "s.numero_ordre "
       + "FROM vote.productions AS p "
-      + "INNER JOIN vote.participants AS g ON p.numero_participant = g.numero_participant "
-      + "WHERE p.numero_participant = :participant AND p.flag_actif IS TRUE ORDER BY p.titre ASC ")
-  List<ProductionShort> findByParticipantWithoutArchive(@Param("participant") Participant participant);
-  
+      + "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<ProductionItem> findLinked(@Param("numero") int numeroCategorie);
+ 
+  @NativeQuery("SELECT DISTINCT " 
+      + "p.numero_production, "
+      + "p.type, "
+      + "p.titre, "
+      + "p.auteurs, "
+      + "p.groupes, "
+      + "p.plateforme, "
+      + "0 AS numero_ordre "
+      + "FROM vote.productions AS p "
+      + "WHERE p.numero_production IN (SELECT p.numero_production FROM vote.productions AS p WHERE p.flag_actif IS TRUE EXCEPT SELECT s.numero_production FROM vote.presentations AS s) "
+      + "  AND p.flag_actif IS TRUE "
+      + "ORDER BY p.titre ASC ")
+  List<ProductionItem> findUnlinked();
   
   @Override
   void delete(Production production);

+ 14 - 0
src/main/java/fr/triplea/demovote/dto/ProductionItem.java

@@ -0,0 +1,14 @@
+package fr.triplea.demovote.dto;
+
+public record ProductionItem
+(
+  Integer numeroProduction,
+  String type,
+  String titre,
+  String auteurs,
+  String groupes,
+  String plateforme,
+  Integer numeroOrdre
+) 
+{ 
+}

+ 3 - 1
src/main/java/fr/triplea/demovote/dto/ProductionShort.java

@@ -20,7 +20,8 @@ public record ProductionShort
   String nomGestionnaire,
   String nomArchive,
   byte[] vignette,
-  Integer numeroVersion
+  Integer numeroVersion,
+  Integer numeroCategorie
 ) 
 { 
   public Production toProduction() 
@@ -50,6 +51,7 @@ public record ProductionShort
     p.setNomArchive(nomArchive);
     p.setVignette(vignette);
     p.setNumeroVersion(numeroVersion);
+    p.setNumeroCategorie(numeroCategorie);
     
     return p;
   }  

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

@@ -256,6 +256,13 @@ public class Production
   public void setNumeroVersion(int n) { this.numeroVersion = Integer.valueOf(n); }
   public Integer getNumeroVersion() { return this.numeroVersion; }
   
+  @Transient
+  private Integer numeroCategorie = 0;
+  @Transient
+  public void setNumeroCategorie(int n) { this.numeroCategorie = Integer.valueOf(n); }
+  @Transient
+  public Integer getNumeroCategorie() { return this.numeroCategorie; }
+
 
   @Override
   public int hashCode() 

+ 2 - 0
src/main/java/fr/triplea/demovote/web/controller/AuthController.java

@@ -38,6 +38,8 @@ import jakarta.validation.Valid;
 @RequestMapping("/sign")
 public class AuthController 
 {
+  // TODO: captcha ?
+  
   @SuppressWarnings("unused") 
   private static final Logger LOG = LoggerFactory.getLogger(AuthController.class);
 

+ 1 - 2
src/main/java/fr/triplea/demovote/web/controller/MessageController.java

@@ -26,8 +26,7 @@ import fr.triplea.demovote.model.Participant;
 @RequestMapping("/chat")
 public class MessageController 
 {
-  // TODO
-
+  
   @SuppressWarnings("unused") 
   private static final Logger LOG = LoggerFactory.getLogger(AccountController.class);
 

+ 228 - 6
src/main/java/fr/triplea/demovote/web/controller/PresentationController.java

@@ -1,16 +1,31 @@
 package fr.triplea.demovote.web.controller;
 
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.MessageSource;
+import org.springframework.http.ResponseEntity;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.servlet.LocaleResolver;
 
+import fr.triplea.demovote.dao.CategorieRepository;
 import fr.triplea.demovote.dao.PresentationRepository;
+import fr.triplea.demovote.dao.ProductionRepository;
+import fr.triplea.demovote.dto.MessagesTransfer;
+import fr.triplea.demovote.dto.ProductionItem;
+import fr.triplea.demovote.model.Categorie;
 import fr.triplea.demovote.model.Presentation;
+import fr.triplea.demovote.model.Production;
+import jakarta.servlet.http.HttpServletRequest;
 
 @RestController
 @RequestMapping("/presentation")
@@ -18,15 +33,222 @@ public class PresentationController
 {
 
   // TODO
-  
+
   @Autowired
   private PresentationRepository presentationRepository;
- 
-  @GetMapping(value = "/list")
+
+  @Autowired
+  private CategorieRepository categorieRepository;
+
+  @Autowired
+  private ProductionRepository productionRepository;
+
+  @Autowired
+  private LocaleResolver localeResolver;
+  
+  @Autowired
+  private MessageSource messageSource;
+
+  
+  @GetMapping(value = "/list-linked/{id}")
   @PreAuthorize("hasRole('ADMIN')")
-  public List<Presentation> getList() 
+  public List<ProductionItem> getProductionList(@PathVariable int id) 
   {
-    return presentationRepository.findAll(); 
+    List<ProductionItem> prods = productionRepository.findLinked(id); 
+    
+    if (prods == null) { prods = new ArrayList<ProductionItem>(); }
+
+    return prods;
   }
-  
+
+  @GetMapping(value = "/list-unlinked")
+  @PreAuthorize("hasRole('ADMIN')")
+  public List<ProductionItem> getProductionList() 
+  {
+    List<ProductionItem> prods = productionRepository.findUnlinked();
+    
+    if (prods == null) { prods = new ArrayList<ProductionItem>(); }
+    
+    return prods;
+  }
+
+  @PutMapping(value = "/add")
+  @PreAuthorize("hasRole('ADMIN')")
+  public ResponseEntity<Object> addProduction(@RequestParam(required = true) int numeroCategorie, @RequestParam(required = true) int numeroProduction, HttpServletRequest request) 
+  {
+    Locale locale = localeResolver.resolveLocale(request);
+
+    Categorie categorie = categorieRepository.findById(numeroCategorie);
+    
+    if (categorie != null)
+    {
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == false) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
+      
+      if (possible)
+      {
+        int numeroOrdre = (presentationRepository.countByCategorie(numeroCategorie)) + 1;
+        
+        Production production = productionRepository.findById(Math.abs(numeroProduction));
+        
+        if (production != null)
+        {
+          Presentation presentation = new Presentation();
+              
+          presentation.setCategorie(categorie);
+          presentation.setProduction(production);
+          presentation.setNumeroOrdre(numeroOrdre);
+          presentation.setNombrePoints(0);
+          presentation.setNombrePolePosition(0);
+          
+          presentationRepository.save(presentation);
+              
+          MessagesTransfer mt = new MessagesTransfer();
+          mt.setInformation(messageSource.getMessage("production.linked", null, locale));
+
+          return ResponseEntity.ok(mt);
+        }
+      }
+    }
+     
+    return ResponseEntity.notFound().build(); 
+  }
+
+  @PutMapping(value = "/remove")
+  @PreAuthorize("hasRole('ADMIN')")
+  public ResponseEntity<Object> removeProduction(@RequestParam(required = true) int numeroCategorie, @RequestParam(required = true) int numeroProduction, HttpServletRequest request) 
+  {
+    Locale locale = localeResolver.resolveLocale(request);
+
+    Categorie categorie = categorieRepository.findById(numeroCategorie);
+
+    if (categorie != null)
+    {
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == false) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
+      
+      if (possible)
+      {
+        Presentation presentation = presentationRepository.findByCategorieAndProduction(numeroCategorie, Math.abs(numeroProduction));
+        
+        if (presentation != null)
+        {
+          presentationRepository.delete(presentation);
+          
+          MessagesTransfer mt = new MessagesTransfer();
+          mt.setInformation(messageSource.getMessage("production.unlinked", null, locale));
+
+          return ResponseEntity.ok(mt);
+        }
+      }
+    }
+     
+    return ResponseEntity.notFound().build(); 
+  }
+
+  @PutMapping(value = "/forward")
+  @PreAuthorize("hasRole('ADMIN')")
+  public ResponseEntity<Object> avancerProduction(@RequestParam(required = true) int numeroCategorie, @RequestParam(required = true) int numeroProduction, HttpServletRequest request) 
+  {
+    Locale locale = localeResolver.resolveLocale(request);
+
+    Categorie categorie = categorieRepository.findById(numeroCategorie);
+
+    if (categorie != null)
+    {
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == false) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
+      
+      if (possible)
+      {
+        List<Presentation> presentations = presentationRepository.findByCategorie(numeroCategorie);
+                
+        if (presentations != null)
+        {
+          if (presentations.size() > 1)
+          {
+            int numeroOrdrePrev = 0;
+            int numeroOrdreNext = 0;
+            
+            for (int i = 0; i < presentations.size(); i++)
+            {
+              if (presentations.get(i).getProduction().getNumeroProduction().equals(Integer.valueOf(Math.abs(numeroProduction))))
+              {
+                if (i > 1) 
+                {  
+                  numeroOrdrePrev = presentations.get(i - 1).getNumeroOrdre();
+                  numeroOrdreNext = presentations.get(i).getNumeroOrdre();
+                  
+                  presentations.get(i - 1).setNumeroOrdre(numeroOrdreNext);
+                  presentations.get(i).setNumeroOrdre(numeroOrdrePrev);
+                  
+                  presentationRepository.save(presentations.get(i - 1));
+                  presentationRepository.save(presentations.get(i));
+                  
+                  break;
+                }
+              }
+            }
+          }
+          
+          MessagesTransfer mt = new MessagesTransfer();
+          mt.setInformation(messageSource.getMessage("production.topped", null, locale));
+
+          return ResponseEntity.ok(mt);
+        }
+      }
+    }
+     
+    return ResponseEntity.notFound().build(); 
+  }
+
+  @PutMapping(value = "/backward")
+  @PreAuthorize("hasRole('ADMIN')")
+  public ResponseEntity<Object> reculerProduction(@RequestParam(required = true) int numeroCategorie, @RequestParam(required = true) int numeroProduction, HttpServletRequest request) 
+  {
+    Locale locale = localeResolver.resolveLocale(request);
+
+    Categorie categorie = categorieRepository.findById(numeroCategorie);
+
+    if (categorie != null)
+    {
+      boolean possible = (categorie.isAvailable() == true) && (categorie.isPollable() == false) && (categorie.isComputed() == false) && (categorie.isDisplayable() == false);
+      
+      if (possible)
+      {
+        List<Presentation> presentations = presentationRepository.findByCategorie(numeroCategorie);
+                
+        if (presentations != null)
+        {
+          if (presentations.size() > 1)
+          {
+            int numeroOrdrePrev = 0;
+            int numeroOrdreNext = 0;
+            
+            for (int i = 0; i < (presentations.size() - 1); i++)
+            {
+              if (presentations.get(i).getProduction().getNumeroProduction().equals(Integer.valueOf(Math.abs(numeroProduction))))
+              {
+                numeroOrdrePrev = presentations.get(i).getNumeroOrdre();
+                numeroOrdreNext = presentations.get(i + 1).getNumeroOrdre();
+                
+                presentations.get(i).setNumeroOrdre(numeroOrdreNext);
+                presentations.get(i + 1).setNumeroOrdre(numeroOrdrePrev);
+                
+                presentationRepository.save(presentations.get(i));
+                presentationRepository.save(presentations.get(i + 1));
+                
+                break;
+              }
+            }
+          }
+          
+          MessagesTransfer mt = new MessagesTransfer();
+          mt.setInformation(messageSource.getMessage("production.bottomed", null, locale));
+
+          return ResponseEntity.ok(mt);
+        }
+      }
+    }
+     
+    return ResponseEntity.notFound().build(); 
+  }
+
 }

+ 4 - 0
src/main/resources/langs/messages_en.properties

@@ -20,6 +20,10 @@ production.created=The new production was correctly created.
 production.updated=The production informations were updated.
 production.file.updated=The production archive was updated.
 production.deleted=This production is removed from the list.
+production.linked=This production was added to this compo.
+production.unlinked=This production was removed from this compo.
+production.topped=This production was moved top in this compo list.
+production.bottomed=This production was moved bottom in this compo list.
 
 bulletin.created=The vote was registered.
 bulletin.deleted=The vote was removed.

+ 4 - 0
src/main/resources/langs/messages_fr.properties

@@ -20,6 +20,10 @@ production.created=La nouvelle production a bien 
 production.updated=Les informations de cette production ont bien été mises à jour.
 production.file.updated=L'archive de cette production a bien été mise à jour.
 production.deleted=La production a été retirée des enregistrements.
+production.linked=La production a été ajoutée dans la catégorie.
+production.unlinked=La production a été retirée de la catégorie.
+production.topped=La production a été avancée dans la catégorie.
+production.bottomed=La production a été reculée dans la catégorie.
 
 bulletin.created=Le bulletin a été inséré.
 bulletin.deleted=Le bulletin a été retiré.