Spaces:
Sleeping
Sleeping
JairoDanielMT
commited on
Commit
•
02eec01
1
Parent(s):
d63d035
quitando el metodo post de almacen
Browse files- routers/almacen.py +63 -63
routers/almacen.py
CHANGED
@@ -1,63 +1,63 @@
|
|
1 |
-
from library.librerias import *
|
2 |
-
from models.almacen import Almacen
|
3 |
-
|
4 |
-
router = APIRouter(
|
5 |
-
prefix="/almacen",
|
6 |
-
tags=["Almacen"],
|
7 |
-
responses={404: {"description": "No encontrado"}},
|
8 |
-
)
|
9 |
-
|
10 |
-
"""CREATE TABLE almacen (
|
11 |
-
ID_Almacen INTEGER PRIMARY KEY AUTOINCREMENT,
|
12 |
-
ID_Insumo INTEGER,
|
13 |
-
Cantidad_Actual INTEGER,
|
14 |
-
Cantidad_Minima INTEGER,
|
15 |
-
FOREIGN KEY (ID_Insumo) REFERENCES insumos (ID_Insumo)
|
16 |
-
);"""
|
17 |
-
|
18 |
-
|
19 |
-
@router.get("/")
|
20 |
-
def get_almacen():
|
21 |
-
try:
|
22 |
-
with DatabaseConnection().get_connection() as conn:
|
23 |
-
cursor = conn.cursor()
|
24 |
-
cursor.execute("SELECT * FROM almacen")
|
25 |
-
almacen = cursor.fetchall()
|
26 |
-
return almacen
|
27 |
-
except Exception as e:
|
28 |
-
print(e)
|
29 |
-
return []
|
30 |
-
|
31 |
-
|
32 |
-
@router.post("/")
|
33 |
-
def post_almacen(almacen: Almacen):
|
34 |
-
try:
|
35 |
-
with DatabaseConnection().get_connection() as conn:
|
36 |
-
cursor = conn.cursor()
|
37 |
-
cursor.execute(
|
38 |
-
"INSERT INTO almacen (ID_Insumo, Cantidad_Actual, Cantidad_Minima) VALUES (?, ?, ?)",
|
39 |
-
(
|
40 |
-
almacen.ID_Insumo,
|
41 |
-
almacen.Cantidad_Actual,
|
42 |
-
almacen.Cantidad_Minima,
|
43 |
-
),
|
44 |
-
)
|
45 |
-
conn.commit()
|
46 |
-
return {"message": "Almacen creado"}
|
47 |
-
except Exception as e:
|
48 |
-
print(e)
|
49 |
-
return []
|
50 |
-
|
51 |
-
|
52 |
-
# search by id_insumo in almacen table
|
53 |
-
@router.get("/{ID_Insumo}")
|
54 |
-
def get_almacen_by_id(ID_Insumo: int):
|
55 |
-
try:
|
56 |
-
with DatabaseConnection().get_connection() as conn:
|
57 |
-
cursor = conn.cursor()
|
58 |
-
cursor.execute("SELECT * FROM almacen WHERE ID_Insumo = ?", (ID_Insumo,))
|
59 |
-
almacen = cursor.fetchall()
|
60 |
-
return almacen
|
61 |
-
except Exception as e:
|
62 |
-
print(e)
|
63 |
-
return []
|
|
|
1 |
+
from library.librerias import *
|
2 |
+
from models.almacen import Almacen
|
3 |
+
|
4 |
+
router = APIRouter(
|
5 |
+
prefix="/almacen",
|
6 |
+
tags=["Almacen"],
|
7 |
+
responses={404: {"description": "No encontrado"}},
|
8 |
+
)
|
9 |
+
|
10 |
+
"""CREATE TABLE almacen (
|
11 |
+
ID_Almacen INTEGER PRIMARY KEY AUTOINCREMENT,
|
12 |
+
ID_Insumo INTEGER,
|
13 |
+
Cantidad_Actual INTEGER,
|
14 |
+
Cantidad_Minima INTEGER,
|
15 |
+
FOREIGN KEY (ID_Insumo) REFERENCES insumos (ID_Insumo)
|
16 |
+
);"""
|
17 |
+
|
18 |
+
|
19 |
+
@router.get("/")
|
20 |
+
def get_almacen():
|
21 |
+
try:
|
22 |
+
with DatabaseConnection().get_connection() as conn:
|
23 |
+
cursor = conn.cursor()
|
24 |
+
cursor.execute("SELECT * FROM almacen")
|
25 |
+
almacen = cursor.fetchall()
|
26 |
+
return almacen
|
27 |
+
except Exception as e:
|
28 |
+
print(e)
|
29 |
+
return []
|
30 |
+
|
31 |
+
|
32 |
+
# @router.post("/")
|
33 |
+
def post_almacen(almacen: Almacen):
|
34 |
+
try:
|
35 |
+
with DatabaseConnection().get_connection() as conn:
|
36 |
+
cursor = conn.cursor()
|
37 |
+
cursor.execute(
|
38 |
+
"INSERT INTO almacen (ID_Insumo, Cantidad_Actual, Cantidad_Minima) VALUES (?, ?, ?)",
|
39 |
+
(
|
40 |
+
almacen.ID_Insumo,
|
41 |
+
almacen.Cantidad_Actual,
|
42 |
+
almacen.Cantidad_Minima,
|
43 |
+
),
|
44 |
+
)
|
45 |
+
conn.commit()
|
46 |
+
return {"message": "Almacen creado"}
|
47 |
+
except Exception as e:
|
48 |
+
print(e)
|
49 |
+
return []
|
50 |
+
|
51 |
+
|
52 |
+
# search by id_insumo in almacen table
|
53 |
+
@router.get("/{ID_Insumo}")
|
54 |
+
def get_almacen_by_id(ID_Insumo: int):
|
55 |
+
try:
|
56 |
+
with DatabaseConnection().get_connection() as conn:
|
57 |
+
cursor = conn.cursor()
|
58 |
+
cursor.execute("SELECT * FROM almacen WHERE ID_Insumo = ?", (ID_Insumo,))
|
59 |
+
almacen = cursor.fetchall()
|
60 |
+
return almacen
|
61 |
+
except Exception as e:
|
62 |
+
print(e)
|
63 |
+
return []
|