Private
Public Access
hecha funcionalidad para reactivar el proveedor
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
0cc3db865d
commit
6467147af5
5 files changed
+131
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package proveedor
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// AltaProveedor reactiva un proveedor dado de baja lógicamente.
|
||||
func AltaProveedor(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
|
||||
}
|
||||
|
||||
proveedor, err := r.ObtenerRepositorios(c).Proveedor.ObtenerPorID(uint(id))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Proveedor no encontrado"})
|
||||
return
|
||||
}
|
||||
|
||||
if !proveedor.DeletedAt.Valid {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "El proveedor no está eliminado"})
|
||||
return
|
||||
}
|
||||
|
||||
proveedor.DeletedAt = gorm.DeletedAt{}
|
||||
uid := c.GetUint("userID")
|
||||
if err := r.ObtenerRepositorios(c).Proveedor.Alta(proveedor, *proveedor, uid); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
Reference in new issue
Block a user