Private
Public Access
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
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)
|
|
}
|