Private
Public Access
feat: hecha parte del back para crear clientes y correjida alta de
miembros Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
37f1741a77
commit
405eaca25c
20 files changed
+417
-112
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package cliente
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// AltaCliente reactiva un cliente dado de baja lógicamente.
|
||||
func AltaCliente(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID invalido"})
|
||||
return
|
||||
}
|
||||
if id < 1 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID no puede ser menor que 1"})
|
||||
return
|
||||
}
|
||||
|
||||
repo := r.ObtenerRepositorios(c).Cliente
|
||||
cliente, err := repo.ObtenerPorID(uint(id))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Cliente no encontrado"})
|
||||
return
|
||||
}
|
||||
|
||||
if !cliente.DeletedAt.Valid {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "El cliente no está eliminado"})
|
||||
return
|
||||
}
|
||||
|
||||
cliente.DeletedAt = gorm.DeletedAt{}
|
||||
uid := c.GetUint("userID")
|
||||
if err := repo.Alta(cliente, *cliente, uid); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
Reference in new issue
Block a user