Private
Public Access
- Update Dockerfile.dev to use golang:1.27‑alpine and set go.mod go version to 1.27. - Convert Marca fields in DTOs, builders, and controller to uint and use ObtenerPorID. - Adjust RepositorioMarcas to use generic models.Marca and remove the obsolete ObtenerPorId method. - Add SeAviso bool flag to the Factura model. - Fix AltaRepuesto ID conversion from uint64 to uint. - Add gorm.io/datatypes as a direct dependency in go.mod.
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package repuestos
|
|
|
|
import (
|
|
"net/http"
|
|
dto_builders "repuestera_back/dto/Builders"
|
|
dto "repuestera_back/dto/Repuestos"
|
|
r "repuestera_back/repositorios"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func ActualizarRepuesto(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
|
|
}
|
|
|
|
var data dto.ActualizarRepuestoDto
|
|
if err := c.ShouldBindJSON(&data); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
data.ID = &id
|
|
|
|
marca, err := r.ObtenerRepositorios().Marca.ObtenerPorID(data.Marca)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
repuesto := dto_builders.NewActualizarRepuestoBuilder().
|
|
ConDto(data).
|
|
ConMarca(marca.ID).
|
|
Build()
|
|
|
|
entity, err := r.ObtenerRepositorios().Repuesto.ObtenerPorID(uint(id))
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
uid, _ := c.Get("userID")
|
|
if err := r.ObtenerRepositorios().Repuesto.Actualizar(entity, &repuesto, uid.(uint)); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusCreated, repuesto)
|
|
}
|