Bläddra i källkod

fix: promo day fixed

latapp 9 månader sedan
förälder
incheckning
6231c3b00d
2 ändrade filer med 38 tillägg och 10 borttagningar
  1. 2 2
      routes/products.py
  2. 36 8
      services/data_service.py

+ 2 - 2
routes/products.py

@@ -91,8 +91,8 @@ async def get_product(product_id: int, current_user = Depends(get_current_user))
     # Attempt to find product by ID
     product = product_data_service.get_by_id(product_id)
     if product:
-        return JSONResponse({"product": product.model_dump(), "message": SuccessResponse.PRODUCTS_FETCH_SUCCESS})
-    
+        return JSONResponse({"product": product.model_dump(exclude={"promo_id", "promo_price", "promo_day"}), "message": SuccessResponse.PRODUCTS_FETCH_SUCCESS})
+
     # Return 404 if product not found
     return JSONResponse({"message": UserResponse.USER_NOT_FOUND.format(user_id=product_id)}, status_code=404)
 

+ 36 - 8
services/data_service.py

@@ -46,6 +46,9 @@ ESQUEMA DE BASE DE DATOS SQLITE (data.db)
 - price        INTEGER NOT NULL
 - image        TEXT (URL de la imagen)
 - status       INTEGER DEFAULT 1 NOT NULL CHECK (status IN (0, 1)) -- 0: Inactivo, 1: Activo
+- promo_id     INTEGER (ID de la promoción asociada, si existe)
+- promo_price  INTEGER (Precio promocional, si existe)
+- promo_day    INTEGER (Día de la semana para la promoción, 1-7)
 (Guarda los productos disponibles para venta con su estado activo/inactivo)
 
 3. Tabla: sales
@@ -561,7 +564,11 @@ class ProductDataService(BaseDataService):
                 description=product[3],
                 price=product[4],
                 image=product[5],
-                status=product[6]
+                status=product[6],
+                promo_id=product[7],
+                promo_price=product[8],
+                promo_day=product[9]
+
             ) for product in products
         ]
     
@@ -580,7 +587,10 @@ class ProductDataService(BaseDataService):
                 description=product[3],
                 price=product[4],
                 image=product[5],
-                status=product[6]
+                status=product[6],
+                promo_id=product[7],
+                promo_price=product[8],
+                promo_day=product[9]
             )
         return None
     
@@ -599,7 +609,10 @@ class ProductDataService(BaseDataService):
                 description=product[3],
                 price=product[4],
                 image=product[5],
-                status=product[6]
+                status=product[6],
+                promo_id=product[7],
+                promo_price=product[8],
+                promo_day=product[9]
             ) for product in products
         ]
     
@@ -618,7 +631,10 @@ class ProductDataService(BaseDataService):
                 description=product[3],
                 price=product[4],
                 image=product[5],
-                status=product[6]
+                status=product[6],
+                promo_id=product[7],
+                promo_price=product[8],
+                promo_day=product[9]
             ) for product in products
         ]
     
@@ -640,7 +656,10 @@ class ProductDataService(BaseDataService):
                 description=product[3],
                 price=product[4],
                 image=product[5],
-                status=product[6]
+                status=product[6],
+                promo_id=product[7],
+                promo_price=product[8],
+                promo_day=product[9]
             ) for product in products
         ]
     #endregion
@@ -727,7 +746,10 @@ class ProductDataService(BaseDataService):
                 description=product[3],
                 price=product[4],
                 image=product[5],
-                status=product[6]
+                status=product[6],
+                promo_id=product[7],
+                promo_price=product[8],
+                promo_day=product[9]
             ) for product in products
         ]
     
@@ -746,7 +768,10 @@ class ProductDataService(BaseDataService):
                 description=product[3],
                 price=product[4],
                 image=product[5],
-                status=product[6]
+                status=product[6],
+                promo_id=product[7],
+                promo_price=product[8],
+                promo_day=product[9]
             ) for product in products
         ]
     
@@ -1299,7 +1324,10 @@ def initialize_db():
         description TEXT NOT NULL,
         price INTEGER NOT NULL,
         image TEXT,
-        status INTEGER DEFAULT 1 NOT NULL CHECK (status IN (0, 1)) -- 0: Inactivo, 1: Activo
+        status INTEGER DEFAULT 1 NOT NULL CHECK (status IN (0, 1)) -- 0: Inactivo, 1: Activo,
+        promo_id INTEGER,
+        promo_price INTEGER,
+        promo_day INTEGER CHECK (promo_day >= 1 AND promo_day <= 7)
     );
     """)