Spaces:
Sleeping
Sleeping
Proyecto terminado
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- .gitignore +2 -0
- Dockerfile +15 -0
- app.py +52 -0
- database/__pycache__/conexion.cpython-311.pyc +0 -0
- database/anhelados.db +3 -0
- database/conexion.py +49 -0
- library/__pycache__/librerias.cpython-311.pyc +0 -0
- library/librerias.py +21 -0
- models/__pycache__/almacen.cpython-311.pyc +0 -0
- models/__pycache__/clientes.cpython-311.pyc +0 -0
- models/__pycache__/detalle_pedidos.cpython-311.pyc +0 -0
- models/__pycache__/detalle_ventas.cpython-311.pyc +0 -0
- models/__pycache__/empleados.cpython-311.pyc +0 -0
- models/__pycache__/gastos.cpython-311.pyc +0 -0
- models/__pycache__/gastos_imprevistos.cpython-311.pyc +0 -0
- models/__pycache__/insumos.cpython-311.pyc +0 -0
- models/__pycache__/maquinas.cpython-311.pyc +0 -0
- models/__pycache__/pedidos_proveedor.cpython-311.pyc +0 -0
- models/__pycache__/produccion.cpython-311.pyc +0 -0
- models/__pycache__/productos.cpython-311.pyc +0 -0
- models/__pycache__/registro_energetico.cpython-311.pyc +0 -0
- models/__pycache__/ventas.cpython-311.pyc +0 -0
- models/almacen.py +9 -0
- models/clientes.py +21 -0
- models/detalle_pedidos.py +8 -0
- models/detalle_ventas.py +8 -0
- models/empleados.py +10 -0
- models/gastos.py +9 -0
- models/gastos_imprevistos.py +9 -0
- models/insumos.py +9 -0
- models/maquinas.py +8 -0
- models/pedidos_proveedor.py +9 -0
- models/produccion.py +9 -0
- models/productos.py +7 -0
- models/registro_energetico.py +9 -0
- models/ventas.py +9 -0
- requirements.txt +2 -0
- routers/__pycache__/almacen.cpython-311.pyc +0 -0
- routers/__pycache__/clientes.cpython-311.pyc +0 -0
- routers/__pycache__/detalle_pedidos.cpython-311.pyc +0 -0
- routers/__pycache__/detalle_ventas.cpython-311.pyc +0 -0
- routers/__pycache__/empleados.cpython-311.pyc +0 -0
- routers/__pycache__/gastos.cpython-311.pyc +0 -0
- routers/__pycache__/gastos_imprevistos.cpython-311.pyc +0 -0
- routers/__pycache__/insumos.cpython-311.pyc +0 -0
- routers/__pycache__/maquinas.cpython-311.pyc +0 -0
- routers/__pycache__/pedidos_proveedor.cpython-311.pyc +0 -0
- routers/__pycache__/produccion.cpython-311.pyc +0 -0
- routers/__pycache__/productos.cpython-311.pyc +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
database/anhelados.db filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
__init__.py
|
Dockerfile
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Usa una imagen base de Python
|
2 |
+
FROM python:3.9
|
3 |
+
# Establece el directorio de trabajo
|
4 |
+
WORKDIR /code
|
5 |
+
|
6 |
+
# Copia los archivos necesarios al contenedor
|
7 |
+
COPY ./requirements.txt /code/requirements.txt
|
8 |
+
RUN pip install --no-cache-dir -r /code/requirements.txt
|
9 |
+
|
10 |
+
COPY . .
|
11 |
+
|
12 |
+
RUN chmod -R 777 /code
|
13 |
+
|
14 |
+
# Comando para ejecutar la aplicación
|
15 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# uvicorn app:app --host localhost --port 7860 --reload
|
2 |
+
from library.librerias import *
|
3 |
+
from routers.routers import *
|
4 |
+
|
5 |
+
|
6 |
+
app = FastAPI(
|
7 |
+
title="API de la heladería Anhelados",
|
8 |
+
description="Esta es la API de la microempresa Anhelados, la cual se dedica a la venta de helados y postres. Aquí se pueden realizar operaciones CRUD para los recursos de la empresa.",
|
9 |
+
version="2.8.7",
|
10 |
+
openapi_url="/anhelados-openapi.json",
|
11 |
+
docs_url="/anhelados-docs",
|
12 |
+
redoc_url="/anhelados-redoc",
|
13 |
+
contact={
|
14 |
+
"name": "Anhelados",
|
15 |
+
"url": "https://www.anhelados.com",
|
16 |
+
"email": "[email protected]",
|
17 |
+
},
|
18 |
+
license_info={"name": "MIT", "url": "https://opensource.org/licenses/MIT"},
|
19 |
+
)
|
20 |
+
|
21 |
+
# CORS
|
22 |
+
app.add_middleware(
|
23 |
+
CORSMiddleware,
|
24 |
+
allow_origins=["*"],
|
25 |
+
allow_credentials=True,
|
26 |
+
allow_methods=["*"],
|
27 |
+
allow_headers=["*"],
|
28 |
+
)
|
29 |
+
|
30 |
+
|
31 |
+
# saludo
|
32 |
+
@app.get("/", summary="Saludo", description="Saludo de la API")
|
33 |
+
def read_root():
|
34 |
+
return {"message": "Bienvenido a la API de la heladeria"}
|
35 |
+
|
36 |
+
|
37 |
+
# Routers
|
38 |
+
|
39 |
+
app.router.include_router(almacen.router)
|
40 |
+
app.router.include_router(clientes.router)
|
41 |
+
app.router.include_router(detalle_pedidos.router)
|
42 |
+
app.router.include_router(detalle_ventas.router)
|
43 |
+
app.router.include_router(empleados.router)
|
44 |
+
app.router.include_router(gastos_imprevistos.router)
|
45 |
+
app.router.include_router(gastos.router)
|
46 |
+
app.router.include_router(insumos.router)
|
47 |
+
app.router.include_router(maquinas.router)
|
48 |
+
app.router.include_router(pedidos_proveedor.router)
|
49 |
+
app.router.include_router(produccion.router)
|
50 |
+
app.router.include_router(productos.router)
|
51 |
+
app.router.include_router(registro_energetico.router)
|
52 |
+
app.router.include_router(ventas.router)
|
database/__pycache__/conexion.cpython-311.pyc
ADDED
Binary file (2.81 kB). View file
|
|
database/anhelados.db
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:201772d7fc1f716aeb890fdb6e926c21ed8dba8f10fd90f95e0ab297c0f0ca46
|
3 |
+
size 3162112
|
database/conexion.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from library.librerias import sqlite3, Queue, threading
|
2 |
+
|
3 |
+
|
4 |
+
DB_PATH = "database/anhelados.db"
|
5 |
+
|
6 |
+
|
7 |
+
class DatabaseConnection:
|
8 |
+
"""
|
9 |
+
Clase para gestionar las conexiones a la base de datos con un pool.
|
10 |
+
"""
|
11 |
+
|
12 |
+
_instance = None
|
13 |
+
_lock = threading.Lock()
|
14 |
+
_connection_pool = Queue(maxsize=5)
|
15 |
+
|
16 |
+
def __new__(cls):
|
17 |
+
"""
|
18 |
+
Crea una nueva instancia de la clase si no existe.
|
19 |
+
"""
|
20 |
+
with cls._lock:
|
21 |
+
if cls._instance is None:
|
22 |
+
cls._instance = super().__new__(cls)
|
23 |
+
cls._instance.conn = cls._instance._create_connection()
|
24 |
+
return cls._instance
|
25 |
+
|
26 |
+
def _create_connection(self):
|
27 |
+
"""
|
28 |
+
Crea una conexión a la base de datos.
|
29 |
+
"""
|
30 |
+
if not self._connection_pool.empty():
|
31 |
+
return self._connection_pool.get()
|
32 |
+
else:
|
33 |
+
connection = sqlite3.connect(DB_PATH)
|
34 |
+
connection.row_factory = sqlite3.Row
|
35 |
+
return connection
|
36 |
+
|
37 |
+
def get_connection(self):
|
38 |
+
"""
|
39 |
+
Obtener el objeto de conexión de la base de datos.
|
40 |
+
"""
|
41 |
+
return self._instance._create_connection()
|
42 |
+
|
43 |
+
def release_connection(self):
|
44 |
+
"""
|
45 |
+
Liberar la conexión de nuevo al pool.
|
46 |
+
"""
|
47 |
+
if self._instance is not None:
|
48 |
+
self._connection_pool.put(self._instance.conn)
|
49 |
+
self._instance.conn = None # Marcar la instancia como sin conexión
|
library/__pycache__/librerias.cpython-311.pyc
ADDED
Binary file (877 Bytes). View file
|
|
library/librerias.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# librerias propias del lenguaje
|
2 |
+
from datetime import datetime
|
3 |
+
from datetime import date
|
4 |
+
import os
|
5 |
+
|
6 |
+
# librerias para la API
|
7 |
+
from pydantic import BaseModel
|
8 |
+
from fastapi import FastAPI, HTTPException
|
9 |
+
from fastapi.middleware.cors import CORSMiddleware
|
10 |
+
from fastapi.responses import FileResponse
|
11 |
+
from fastapi import APIRouter, Depends, status
|
12 |
+
import uvicorn
|
13 |
+
|
14 |
+
# importar librerias para la conexion a la base de datos
|
15 |
+
from queue import Queue
|
16 |
+
import sqlite3
|
17 |
+
import threading
|
18 |
+
|
19 |
+
|
20 |
+
# clase para la conexion a la base de datos
|
21 |
+
from database.conexion import DatabaseConnection
|
models/__pycache__/almacen.cpython-311.pyc
ADDED
Binary file (724 Bytes). View file
|
|
models/__pycache__/clientes.cpython-311.pyc
ADDED
Binary file (878 Bytes). View file
|
|
models/__pycache__/detalle_pedidos.cpython-311.pyc
ADDED
Binary file (623 Bytes). View file
|
|
models/__pycache__/detalle_ventas.cpython-311.pyc
ADDED
Binary file (626 Bytes). View file
|
|
models/__pycache__/empleados.cpython-311.pyc
ADDED
Binary file (720 Bytes). View file
|
|
models/__pycache__/gastos.cpython-311.pyc
ADDED
Binary file (669 Bytes). View file
|
|
models/__pycache__/gastos_imprevistos.cpython-311.pyc
ADDED
Binary file (716 Bytes). View file
|
|
models/__pycache__/insumos.cpython-311.pyc
ADDED
Binary file (629 Bytes). View file
|
|
models/__pycache__/maquinas.cpython-311.pyc
ADDED
Binary file (616 Bytes). View file
|
|
models/__pycache__/pedidos_proveedor.cpython-311.pyc
ADDED
Binary file (700 Bytes). View file
|
|
models/__pycache__/produccion.cpython-311.pyc
ADDED
Binary file (700 Bytes). View file
|
|
models/__pycache__/productos.cpython-311.pyc
ADDED
Binary file (577 Bytes). View file
|
|
models/__pycache__/registro_energetico.cpython-311.pyc
ADDED
Binary file (706 Bytes). View file
|
|
models/__pycache__/ventas.cpython-311.pyc
ADDED
Binary file (677 Bytes). View file
|
|
models/almacen.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
|
5 |
+
class Almacen(BaseModel):
|
6 |
+
ID_Almacen: int
|
7 |
+
ID_Insumo: Optional[int]
|
8 |
+
Cantidad_Actual: Optional[int]
|
9 |
+
Cantidad_Minima: Optional[int]
|
models/clientes.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
|
3 |
+
"""
|
4 |
+
CREATE TABLE clientes (
|
5 |
+
ID_Proveedor INTEGER PRIMARY KEY AUTOINCREMENT,
|
6 |
+
Nombre TEXT,
|
7 |
+
Contacto TEXT,
|
8 |
+
Direccion TEXT
|
9 |
+
);
|
10 |
+
"""
|
11 |
+
|
12 |
+
|
13 |
+
class Clientes(BaseModel):
|
14 |
+
ID_Proveedor: int
|
15 |
+
Nombre: str
|
16 |
+
Contacto: str
|
17 |
+
Direccion: str
|
18 |
+
|
19 |
+
|
20 |
+
class SearchClientes(BaseModel):
|
21 |
+
nombre: str = ""
|
models/detalle_pedidos.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
|
3 |
+
|
4 |
+
class DetallePedidos(BaseModel):
|
5 |
+
ID_Pedido: int
|
6 |
+
ID_Insumo: int
|
7 |
+
Cantidad: int
|
8 |
+
Costo_Unitario: float
|
models/detalle_ventas.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
|
3 |
+
|
4 |
+
class DetalleVentas(BaseModel):
|
5 |
+
ID_Venta: int
|
6 |
+
ID_Producto: int
|
7 |
+
Cantidad: int
|
8 |
+
Precio_Unitario: float
|
models/empleados.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
|
5 |
+
class Empleados(BaseModel):
|
6 |
+
ID_Empleado: int
|
7 |
+
Nombre: str
|
8 |
+
Apellido: str
|
9 |
+
Sueldo: float
|
10 |
+
Fecha_Inicio: Optional[str]
|
models/gastos.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
|
5 |
+
class Gastos(BaseModel):
|
6 |
+
ID_Gasto: int
|
7 |
+
Tipo: str
|
8 |
+
Monto: float
|
9 |
+
Fecha: Optional[str]
|
models/gastos_imprevistos.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
|
5 |
+
class GastosImprevistos(BaseModel):
|
6 |
+
ID_Gasto_Imprevisto: int
|
7 |
+
Descripcion: str
|
8 |
+
Monto: float
|
9 |
+
Fecha: Optional[str]
|
models/insumos.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
|
3 |
+
|
4 |
+
class Insumos(BaseModel):
|
5 |
+
ID_Insumo: int
|
6 |
+
Descripcion: str
|
7 |
+
Tipo: str
|
8 |
+
Costo: float
|
9 |
+
Cantidad: int
|
models/maquinas.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
|
3 |
+
|
4 |
+
class Maquinas(BaseModel):
|
5 |
+
ID_Maquina: int
|
6 |
+
Tipo: str
|
7 |
+
Capacidad: int
|
8 |
+
Consumo_Energetico: float
|
models/pedidos_proveedor.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
|
5 |
+
class PedidosProveedor(BaseModel):
|
6 |
+
ID_Pedido: int
|
7 |
+
ID_Proveedor: int
|
8 |
+
Fecha: Optional[str]
|
9 |
+
Total: float
|
models/produccion.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
|
5 |
+
class Produccion(BaseModel):
|
6 |
+
ID_Produccion: int
|
7 |
+
ID_Maquina: int
|
8 |
+
Fecha: Optional[str]
|
9 |
+
Cantidad_Producida: int
|
models/productos.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
|
3 |
+
|
4 |
+
class Productos(BaseModel):
|
5 |
+
ID_Producto: int
|
6 |
+
Nombre: str
|
7 |
+
Precio: float
|
models/registro_energetico.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
|
5 |
+
class RegistroEnergetico(BaseModel):
|
6 |
+
ID_Registro: int
|
7 |
+
ID_Maquina: int
|
8 |
+
Fecha: Optional[str]
|
9 |
+
Consumo: float
|
models/ventas.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
from typing import Optional
|
3 |
+
|
4 |
+
|
5 |
+
class Ventas(BaseModel):
|
6 |
+
ID_Venta: int
|
7 |
+
Fecha: Optional[str]
|
8 |
+
ID_Empleado: int
|
9 |
+
Total: float
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
routers/__pycache__/almacen.cpython-311.pyc
ADDED
Binary file (3.47 kB). View file
|
|
routers/__pycache__/clientes.cpython-311.pyc
ADDED
Binary file (5.67 kB). View file
|
|
routers/__pycache__/detalle_pedidos.cpython-311.pyc
ADDED
Binary file (2.66 kB). View file
|
|
routers/__pycache__/detalle_ventas.cpython-311.pyc
ADDED
Binary file (2.65 kB). View file
|
|
routers/__pycache__/empleados.cpython-311.pyc
ADDED
Binary file (5.54 kB). View file
|
|
routers/__pycache__/gastos.cpython-311.pyc
ADDED
Binary file (5.67 kB). View file
|
|
routers/__pycache__/gastos_imprevistos.cpython-311.pyc
ADDED
Binary file (4.78 kB). View file
|
|
routers/__pycache__/insumos.cpython-311.pyc
ADDED
Binary file (4.64 kB). View file
|
|
routers/__pycache__/maquinas.cpython-311.pyc
ADDED
Binary file (4.56 kB). View file
|
|
routers/__pycache__/pedidos_proveedor.cpython-311.pyc
ADDED
Binary file (5.72 kB). View file
|
|
routers/__pycache__/produccion.cpython-311.pyc
ADDED
Binary file (6.78 kB). View file
|
|
routers/__pycache__/productos.cpython-311.pyc
ADDED
Binary file (3.42 kB). View file
|
|