rajah 1 год назад
Родитель
Сommit
98fcdde283

+ 1 - 0
src/main/java/fr/triplea/demovote/persistence/model/Categorie.java

@@ -91,6 +91,7 @@ public class Categorie
   
   public void setLibelle(String str) { if (str != null) { this.libelle = StringUtils.truncate(str, 128); } }
   public String getLibelle() { return this.libelle; }
+  public boolean hasLibelle() { if (this.libelle == null) { return false; } if (this.libelle.isBlank()) { return false; } return true; }
   
   public void setNumeroOrdre(int o) { this.numeroOrdre = Integer.valueOf(o); }
   public Integer getNumeroOrdre() { return this.numeroOrdre; }

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

@@ -62,9 +62,11 @@ public class Variable
   
   public void setType(String str) { if (str != null) { this.type = StringUtils.truncate(str, 64); } }
   public String getType() { return this.type; }
+  public boolean hasType() { if (this.type == null) { return false; } if (this.type.isBlank()) { return false; } return true; }
   
   public void setCode(String str) { if (str != null) { this.code = StringUtils.truncate(str, 64); } }
   public String getCode() { return this.code; }
+  public boolean hasCode() { if (this.code == null) { return false; } if (this.code.isBlank()) { return false; } return true; }
   
   public void setValeur(String str) { if (str != null) { this.valeur = StringUtils.truncate(str, 4000); } }
   public String getValeur() { return this.valeur; }

+ 3 - 2
src/main/java/fr/triplea/demovote/web/controller/CategorieController.java

@@ -5,7 +5,6 @@ import java.util.List;
 import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 //import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.CrossOrigin;
@@ -56,8 +55,10 @@ public class CategorieController
     Categorie found = categorieRepository.findById(0);
     
     if (found == null) { categorie.setNumeroCategorie(null); }
+    
+    if (categorie.hasLibelle()) { return categorieRepository.save(categorie); }
 
-    return categorieRepository.save(categorie);
+    return null;
   }
 
   @PutMapping(value = "/update/{id}")

+ 3 - 1
src/main/java/fr/triplea/demovote/web/controller/VariableController.java

@@ -60,7 +60,9 @@ public class VariableController
     
     if (found == null) { variable.setNumeroVariable(null); }
     
-    return variableRepository.save(variable);
+    if (variable.hasType() && variable.hasCode()) { return variableRepository.save(variable); }
+    
+    return null;
   }
  
   @PutMapping(value = "/update/{id}")