Private
Public Access
bueno es parte del plan de implementacion para el caso de uso de gestion
de stock
This commit is contained in:
1 parent
24e746b1b7
commit
6ed8805e21
40 files changed
+2748
-31
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package almacen
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
|
||||
dto "repuestera_back/dto/Almacenes"
|
||||
"repuestera_back/models"
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func CrearAlmacen(c *gin.Context) {
|
||||
var data dto.CrearAlmacenDto
|
||||
if err := c.ShouldBindJSON(&data); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
repo := r.ObtenerRepositorios(c).Almacen
|
||||
if _, err := repo.BuscarPorCodigo(data.Codigo); err == nil {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "ya existe un almacén con ese código"})
|
||||
return
|
||||
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
almacen := models.Almacen{Codigo: data.Codigo, Ubicacion: data.Ubicacion}
|
||||
if err := repo.Crear(almacen, c.GetUint("userID")); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
creado, err := repo.BuscarPorCodigo(data.Codigo)
|
||||
if err != nil {
|
||||
c.Status(http.StatusCreated)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, creado)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package almacen
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func ObtenerAlmacenes(c *gin.Context) {
|
||||
almacenes, err := r.ObtenerRepositorios(c).Almacen.Listar()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, almacenes)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cliente
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func ObtenerClientes(c *gin.Context) {
|
||||
clientes, err := r.ObtenerRepositorios(c).Cliente.Listar(c.Query("q"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, clientes)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package factura
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func ObtenerFactura(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "id inválido"})
|
||||
return
|
||||
}
|
||||
|
||||
factura, err := r.ObtenerRepositorios(c).Factura.ObtenerConRelaciones(uint(id))
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "factura no encontrada"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, factura)
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package factura
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func ObtenerFacturas(c *gin.Context) {
|
||||
filtros := r.FiltrosFactura{
|
||||
Numero: c.Query("numero"),
|
||||
Cliente: c.Query("cliente"),
|
||||
}
|
||||
|
||||
if raw := c.Query("clienteId"); raw != "" {
|
||||
id, err := strconv.ParseUint(raw, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "clienteId inválido"})
|
||||
return
|
||||
}
|
||||
filtros.ClienteID = uint(id)
|
||||
}
|
||||
|
||||
desde, err := fechaQuery(c.Query("desde"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "desde inválido, se espera YYYY-MM-DD"})
|
||||
return
|
||||
}
|
||||
hasta, err := fechaQuery(c.Query("hasta"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "hasta inválido, se espera YYYY-MM-DD"})
|
||||
return
|
||||
}
|
||||
filtros.Desde = desde
|
||||
filtros.Hasta = hasta
|
||||
|
||||
facturas, err := r.ObtenerRepositorios(c).Factura.Listar(filtros)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, facturas)
|
||||
}
|
||||
|
||||
func fechaQuery(valor string) (*time.Time, error) {
|
||||
if valor == "" {
|
||||
return nil, nil
|
||||
}
|
||||
fecha, err := time.Parse("2006-01-02", valor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fecha, nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package proveedor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
|
||||
dto "repuestera_back/dto/Proveedores"
|
||||
"repuestera_back/models"
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func CrearProveedor(c *gin.Context) {
|
||||
var data dto.CrearProveedorDto
|
||||
if err := c.ShouldBindJSON(&data); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
repo := r.ObtenerRepositorios(c).Proveedor
|
||||
if _, err := repo.BuscarPorNombre(data.Nombre); err == nil {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "ya existe un proveedor con ese nombre"})
|
||||
return
|
||||
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
proveedor := models.Proveedor{
|
||||
Nombre: data.Nombre,
|
||||
Cuit: data.Cuit,
|
||||
Email: data.Email,
|
||||
Telefono: data.Telefono,
|
||||
}
|
||||
if err := repo.Crear(proveedor, c.GetUint("userID")); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
creado, err := repo.BuscarPorNombre(data.Nombre)
|
||||
if err != nil {
|
||||
c.Status(http.StatusCreated)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, creado)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package proveedor
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func ObtenerProveedores(c *gin.Context) {
|
||||
proveedores, err := r.ObtenerRepositorios(c).Proveedor.Listar(c.Query("q"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, proveedores)
|
||||
}
|
||||
Reference in new issue
Block a user