Private
Public Access
correjida funcionalidad de alta, modificacion y eliminacion de repuestos
This commit is contained in:
1 parent
6c900f0afd
commit
6b9cd844e4
12 files changed
+139
-63
No files matched your search
@@ -10,9 +10,7 @@ import (
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func CrearRepuesto(c *gin.Context){
|
||||
func CrearRepuesto(c *gin.Context) {
|
||||
var data dto.CrearRepuestoDto
|
||||
if err := c.ShouldBindJSON(&data); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func ObtenerRepuestos(c *gin.Context) {
|
||||
repuestos, err := r.ObtenerRepositorios().Repuesto.ObtenerTodos()
|
||||
repuestos, err := r.ObtenerRepositorios().Repuesto.ObtenerTodosConMarca()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package dto
|
||||
|
||||
type ActualizarRepuestoDto struct {
|
||||
ID *uint64 `json:"id,omitempty"`
|
||||
ID *uint64 `json:"ID,omitempty"`
|
||||
Nombre string `json:"nombre"`
|
||||
Descripcion string `json:"descripcion"`
|
||||
Marca uint `json:"marca"`
|
||||
Marca uint `json:"marcaId"`
|
||||
Aliases []string `json:"aliases"`
|
||||
Precio float64 `json:"precio"`
|
||||
StockMinimo int `json:"stockMinimo"`
|
||||
|
||||
@@ -3,7 +3,7 @@ package dto
|
||||
type CrearRepuestoDto struct {
|
||||
Nombre string `json:"nombre"`
|
||||
Descripcion string `json:"descripcion"`
|
||||
Marca uint `json:"marca"`
|
||||
Marca uint `json:"marcaId"`
|
||||
Aliases []string `json:"aliases"`
|
||||
Precio float64 `json:"precio"`
|
||||
StockMinimo int `json:"stockMinimo"`
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
type RepositorioRepuesto interface {
|
||||
IRepositorio[*models.Repuesto]
|
||||
AltaRepuesto(id uint, uid uint) (*models.Repuesto, error)
|
||||
ObtenerTodosConMarca() ([]*models.Repuesto, error)
|
||||
}
|
||||
|
||||
type repositorioRepuesto struct {
|
||||
@@ -25,6 +26,14 @@ func NuevoRepositorioRepuesto(db *gorm.DB) RepositorioRepuesto {
|
||||
}
|
||||
}
|
||||
|
||||
func (r repositorioRepuesto) ObtenerTodosConMarca() ([]*models.Repuesto, error) {
|
||||
var repuestos []*models.Repuesto
|
||||
if err := r.db.Unscoped().Preload("Marca").Find(&repuestos).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return repuestos, nil
|
||||
}
|
||||
|
||||
// Revierte la baja de un producto
|
||||
func (r repositorioRepuesto) AltaRepuesto(id uint, uid uint) (*models.Repuesto, error) {
|
||||
rep := models.Repuesto{
|
||||
|
||||
Reference in new issue
Block a user