JairoDanielMT commited on
Commit
eddae92
1 Parent(s): 21bbf15

Update routers/detalle_ventas.py

Browse files
Files changed (1) hide show
  1. routers/detalle_ventas.py +54 -54
routers/detalle_ventas.py CHANGED
@@ -1,54 +1,54 @@
1
- from library.librerias import *
2
- from models.detalle_ventas import DetalleVentas
3
-
4
- router = APIRouter(
5
- prefix="/detalle_ventas",
6
- tags=["Detalle_ventas"],
7
- responses={404: {"description": "No encontrado"}},
8
- )
9
-
10
- """CREATE TABLE detalle_ventas (
11
- ID_Venta INTEGER,
12
- ID_Producto INTEGER,
13
- Cantidad INTEGER,
14
- Precio_Unitario REAL,
15
- PRIMARY KEY (ID_Venta, ID_Producto),
16
- FOREIGN KEY (ID_Venta) REFERENCES ventas (ID_Venta),
17
- FOREIGN KEY (ID_Producto) REFERENCES productos (ID_Producto)
18
- );"""
19
-
20
-
21
- # get/detalle_ventas -> obtener todos los detalle_ventas con with connection as conn, manejo de errores
22
- @router.get("/")
23
- def get_detalle_ventas():
24
- try:
25
- with DatabaseConnection().get_connection() as conn:
26
- cursor = conn.cursor()
27
- cursor.execute("SELECT * FROM detalle_ventas")
28
- detalle_ventas = cursor.fetchall()
29
- return detalle_ventas
30
- except Exception as e:
31
- print(e)
32
- return []
33
-
34
-
35
- # post/detalle_ventas -> crear un detalle_venta con with connection as conn, manejo de errores
36
- @router.post("/")
37
- def post_detalle_venta(detalle_venta: DetalleVentas):
38
- try:
39
- with DatabaseConnection().get_connection() as conn:
40
- cursor = conn.cursor()
41
- cursor.execute(
42
- "INSERT INTO detalle_ventas (ID_Venta, ID_Producto, Cantidad, Precio_Unitario) VALUES (?, ?, ?, ?)",
43
- (
44
- detalle_venta.ID_Venta,
45
- detalle_venta.ID_Producto,
46
- detalle_venta.Cantidad,
47
- detalle_venta.Precio_Unitario,
48
- ),
49
- )
50
- conn.commit()
51
- return {"message": "Detalle_venta creado"}
52
- except Exception as e:
53
- print(e)
54
- return []
 
1
+ from library.librerias import *
2
+ from models.detalle_ventas import DetalleVentas
3
+
4
+ router = APIRouter(
5
+ prefix="/detalle_ventas",
6
+ tags=["Detalle_ventas"],
7
+ responses={404: {"description": "No encontrado"}},
8
+ )
9
+
10
+ """CREATE TABLE detalle_ventas (
11
+ ID_Venta INTEGER,
12
+ ID_Producto INTEGER,
13
+ Cantidad INTEGER,
14
+ Precio_Unitario REAL,
15
+ PRIMARY KEY (ID_Venta, ID_Producto),
16
+ FOREIGN KEY (ID_Venta) REFERENCES ventas (ID_Venta),
17
+ FOREIGN KEY (ID_Producto) REFERENCES productos (ID_Producto)
18
+ );"""
19
+
20
+
21
+ # get/detalle_ventas -> obtener todos los detalle_ventas con with connection as conn, manejo de errores
22
+ @router.get("/")
23
+ def get_detalle_ventas():
24
+ try:
25
+ with DatabaseConnection().get_connection() as conn:
26
+ cursor = conn.cursor()
27
+ cursor.execute("SELECT * FROM detalle_ventas")
28
+ detalle_ventas = cursor.fetchall()
29
+ return detalle_ventas
30
+ except Exception as e:
31
+ print(e)
32
+ return []
33
+
34
+
35
+ # post/detalle_ventas -> crear un detalle_venta con with connection as conn, manejo de errores
36
+ # @router.post("/")
37
+ def post_detalle_venta(detalle_venta: DetalleVentas):
38
+ try:
39
+ with DatabaseConnection().get_connection() as conn:
40
+ cursor = conn.cursor()
41
+ cursor.execute(
42
+ "INSERT INTO detalle_ventas (ID_Venta, ID_Producto, Cantidad, Precio_Unitario) VALUES (?, ?, ?, ?)",
43
+ (
44
+ detalle_venta.ID_Venta,
45
+ detalle_venta.ID_Producto,
46
+ detalle_venta.Cantidad,
47
+ detalle_venta.Precio_Unitario,
48
+ ),
49
+ )
50
+ conn.commit()
51
+ return {"message": "Detalle_venta creado"}
52
+ except Exception as e:
53
+ print(e)
54
+ return []