Private
Public Access
version pre testeo de descuentos
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
a9ec514687
commit
ea009e276f
25 files changed
+1100
-13
No files matched your search
@@ -0,0 +1,40 @@
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user