Private
Public Access
checkeada parte del back sobre el abm de almacenes
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
3587a8dbc6
commit
12276acbd8
10 files changed
+294
-15
No files matched your search
@@ -0,0 +1,39 @@
|
||||
package almacen
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func AltaAlmacen(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).Almacen
|
||||
almacen, err := repo.ObtenerPorID(uint(id))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Almacén no encontrado"})
|
||||
return
|
||||
}
|
||||
|
||||
if !almacen.DeletedAt.Valid {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "El almacén no está eliminado"})
|
||||
return
|
||||
}
|
||||
|
||||
almacen.DeletedAt = gorm.DeletedAt{}
|
||||
if err := repo.Alta(almacen, *almacen, 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