Private
Public Access
1 parent
bc0db6dbee
commit
fcf16df5d3
21 files changed
+728
-3
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package formapago
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repuestera_back/models"
|
||||
r "repuestera_back/repositorios"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func CrearFormaDePago(c *gin.Context) {
|
||||
var fp models.FormaDePago
|
||||
if err := c.ShouldBindJSON(&fp); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if fp.Descripcion == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "La descripción es obligatoria"})
|
||||
return
|
||||
}
|
||||
|
||||
repo := r.ObtenerRepositorios(c).FormaDePago
|
||||
if _, err := repo.ObtenerPorDescripcion(fp.Descripcion); err == nil {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "ya existe una forma de pago con esa descripción"})
|
||||
return
|
||||
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo.Crear(fp, c.GetUint("userID")); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusCreated)
|
||||
}
|
||||
Reference in new issue
Block a user