Private
Public Access
41 lines
946 B
Go
41 lines
946 B
Go
package descuento
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
r "repuestera_back/repositorios"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// AltaDescuento reactiva un descuento dado de baja lógicamente.
|
|
func AltaDescuento(c *gin.Context) {
|
|
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if err != nil || id < 1 {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "ID inválido"})
|
|
return
|
|
}
|
|
|
|
repo := r.ObtenerRepositorios(c).Descuento
|
|
descuento, err := repo.ObtenerPorID(uint(id))
|
|
if err != nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"error": "Descuento no encontrado"})
|
|
return
|
|
}
|
|
|
|
if !descuento.DeletedAt.Valid {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "El descuento no está eliminado"})
|
|
return
|
|
}
|
|
|
|
descuento.DeletedAt = gorm.DeletedAt{}
|
|
if err := repo.Alta(descuento, *descuento, c.GetUint("userID")); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.Status(http.StatusOK)
|
|
}
|