diff --git a/app/app.py b/app/app.py index 5182fc3..32fed97 100644 --- a/app/app.py +++ b/app/app.py @@ -16,7 +16,7 @@ VerifyPickupSchema, VerifyPaymentSchema, UpdateStaffProfileSchema, - UpdateResalePriceSchema # <--- ADDED THIS IMPORT + UpdateResalePriceSchema ) from .auth import ( authenticate_student, @@ -210,23 +210,20 @@ async def upload_menu_endpoint( menu_data: MenuSchema, credentials: HTTPAuthorizationCredentials = Security(security) ): - token = credentials.credentials - return await upload_menu(menu_data, token) + return await upload_menu(menu_data, credentials.credentials) @app.get("/staff/menu", tags=["staff", "manager"]) async def get_staff_menu( credentials: HTTPAuthorizationCredentials = Security(security) ): - token = credentials.credentials - return await get_menu(token) + return await get_menu(credentials.credentials) @app.post("/staff/menu/scan-image", tags=["staff", "manager"], response_model=MenuScanResponse) async def scan_menu_endpoint( file: UploadFile = File(...), credentials: HTTPAuthorizationCredentials = Security(security) ): - token = credentials.credentials - return await scan_menu_image(file, token) + return await scan_menu_image(file, credentials.credentials) @app.patch("/staff/menu/{item_id}", tags=["staff", "manager"]) async def update_menu_item_endpoint( @@ -234,21 +231,14 @@ async def update_menu_item_endpoint( update_data: UpdateMenuItemSchema, credentials: HTTPAuthorizationCredentials = Security(security) ): - return await update_menu_item( - item_id, - update_data, - credentials.credentials - ) + return await update_menu_item(item_id, update_data, credentials.credentials) @app.delete("/staff/menu/{item_id}", tags=["staff", "manager"]) async def delete_menu_item_endpoint( item_id: str, credentials: HTTPAuthorizationCredentials = Security(security) ): - return await delete_menu_item( - item_id, - credentials.credentials - ) + return await delete_menu_item(item_id, credentials.credentials) @app.get("/staff/orders", tags=["staff", "manager"]) async def get_staff_orders_endpoint( @@ -271,13 +261,12 @@ async def verify_pickup_endpoint( credentials: HTTPAuthorizationCredentials = Security(security) ): return await verify_order_pickup(verify_data, credentials.credentials) - @app.get("/staff/resale/items", tags=["staff"]) async def get_staff_resale_items_endpoint( - credenitals: HTTPAuthorizationCredentials = Security(security) + credentials: HTTPAuthorizationCredentials = Security(security) ): - return await get_stall_resale_items(credenitals.credentials) + return await get_stall_resale_items(credentials.credentials) @app.patch("/staff/resale/{resale_id}/price", tags=["staff"]) async def update_resale_price_endpoint( @@ -285,4 +274,4 @@ async def update_resale_price_endpoint( body: UpdateResalePriceSchema, credentials: HTTPAuthorizationCredentials = Security(security) ): - return await update_resale_price(resale_id, body.new_price, credentials.credentials) \ No newline at end of file + return await update_resale_price(resale_id, body.new_price, credentials.credentials) diff --git a/app/schema.py b/app/schema.py index 67025be..11a25f0 100644 --- a/app/schema.py +++ b/app/schema.py @@ -118,4 +118,4 @@ class CancelOrderResponse(BaseModel): resale_created: bool = False class UpdateResalePriceSchema(BaseModel): - new_price: float \ No newline at end of file + new_price: float diff --git a/app/staff.py b/app/staff.py index 79f807c..29b8b6f 100644 --- a/app/staff.py +++ b/app/staff.py @@ -701,7 +701,6 @@ async def verify_order_pickup(verify_data: VerifyPickupSchema, id_token: str): except Exception as e: return JSONResponse(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content={"message": str(e)}) - async def get_stall_resale_items(id_token: str): try: staff_data, _ = await get_staff_details(id_token) @@ -710,7 +709,6 @@ async def get_stall_resale_items(id_token: str): stall_id = staff_data.get("stall_id") - # Fetch available or reserved resale items for this stall docs = ( db.collection("resale_items") .where("stall_id", "==", stall_id) @@ -765,4 +763,4 @@ async def update_resale_price(resale_id: str, new_price: float, id_token: str): return JSONResponse(status_code=200, content={"message": "Price updated successfully"}) except Exception as e: - return JSONResponse(status_code=500, content={"message": str(e)}) \ No newline at end of file + return JSONResponse(status_code=500, content={"message": str(e)}) diff --git a/app/user.py b/app/user.py index 044933b..820a19b 100644 --- a/app/user.py +++ b/app/user.py @@ -399,10 +399,6 @@ def calculate_refund(order: dict): return 0, "NO_REFUND" -# app/user.py - -# ... (Keep previous imports and functions like get_user_details, etc.) - async def cancel_order(order_id: str, id_token: str): try: user_data, user_uid = await get_user_details(id_token) @@ -411,7 +407,6 @@ async def cancel_order(order_id: str, id_token: str): now = datetime.now() - # --- Cancellation Limit Logic (kept same) --- week_start = user_data.get("cancellation_week_start") current_count = user_data.get("cancellations_this_week", 0) @@ -429,7 +424,7 @@ async def cancel_order(order_id: str, id_token: str): "cancellations_this_week": 0 }) - if current_count >= 20: # Updated limit as per previous context + if current_count >= 20: return JSONResponse( status_code=status.HTTP_400_BAD_REQUEST, content={"message": "Weekly cancellation limit reached."} @@ -454,16 +449,13 @@ async def cancel_order(order_id: str, id_token: str): content={"message": f"Cannot cancel order with status: {current_status}"} ) - # --- NEW REFUND LOGIC --- total_amount = order_data.get("total_amount", 0) refund_amount = 0 refund_type = "NO_REFUND" - - # If Status is READY -> 70% Refund + if current_status == "READY": refund_amount = int(total_amount * 0.70) refund_type = "PARTIAL_REFUND" - # If Status is PAID/RESERVED (Not cooked yet) -> 100% Refund (Usually) elif current_status in ["PAID", "RESERVED"]: refund_amount = total_amount refund_type = "FULL_REFUND" @@ -478,7 +470,7 @@ async def cancel_order(order_id: str, id_token: str): refund_response = razorpay_client.payment.refund( payment_id, { - "amount": int(refund_amount * 100), # Razorpay expects paise + "amount": int(refund_amount * 100), "speed": "normal", "notes": { "order_id": order_id, @@ -493,14 +485,12 @@ async def cancel_order(order_id: str, id_token: str): print("[Refund Error]", e) refund_status = "FAILED" - # --- RESALE ITEM LOGIC --- resale_created = False if current_status == "READY": college_id = order_data.get("college_id") stall_id = order_data.get("stall_id") - - # Item Price = 70% of original (Since stall kept 30%) + discounted_price = int(total_amount * 0.70) resale_item = { @@ -512,7 +502,7 @@ async def cancel_order(order_id: str, id_token: str): "items": order_data.get("items", []), "original_price": total_amount, "discounted_price": discounted_price, - "max_price": discounted_price, # ✅ Store Max Price constraint + "max_price": discounted_price, "status": "AVAILABLE", "created_at": firestore.SERVER_TIMESTAMP } @@ -522,9 +512,6 @@ async def cancel_order(order_id: str, id_token: str): batch = db.batch() - # Calculate Staff Payout (The amount stall keeps immediately) - # If READY: Stall keeps 30% (Total - Refund) - # If PAID: Stall keeps 0 retained_amount = total_amount - refund_amount batch.update(order_ref, {