Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
VerifyPickupSchema,
VerifyPaymentSchema,
UpdateStaffProfileSchema,
UpdateResalePriceSchema # <--- ADDED THIS IMPORT
UpdateResalePriceSchema

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
)
from .auth import (
authenticate_student,
Expand Down Expand Up @@ -95,7 +95,7 @@

@app.post('/auth/verify-student', tags=["auth"])
async def verify_student_endpoint(credentials: HTTPAuthorizationCredentials = Security(security)):
return await authenticate_student(credentials.credentials)

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation before block (add 4 spaces). Warning

Wrong hanging indentation before block (add 4 spaces).

@app.patch("/user/profile", tags=["user"])
async def update_profile_endpoint(
Expand Down Expand Up @@ -210,45 +210,35 @@
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(
item_id: str,
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(
Expand All @@ -271,18 +261,17 @@
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(
resale_id: str,
body: UpdateResalePriceSchema,
credentials: HTTPAuthorizationCredentials = Security(security)
):
return await update_resale_price(resale_id, body.new_price, credentials.credentials)
return await update_resale_price(resale_id, body.new_price, credentials.credentials)
2 changes: 1 addition & 1 deletion app/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ class CancelOrderResponse(BaseModel):
resale_created: bool = False

class UpdateResalePriceSchema(BaseModel):
new_price: float
new_price: float
4 changes: 1 addition & 3 deletions app/staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@
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)
Expand All @@ -710,7 +709,6 @@

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)
Expand Down Expand Up @@ -765,4 +763,4 @@
return JSONResponse(status_code=200, content={"message": "Price updated successfully"})

except Exception as e:
return JSONResponse(status_code=500, content={"message": str(e)})
return JSONResponse(status_code=500, content={"message": str(e)})

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
23 changes: 5 additions & 18 deletions app/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,6 @@

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)
Expand All @@ -411,7 +407,6 @@

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)

Expand All @@ -429,7 +424,7 @@
"cancellations_this_week": 0
})

if current_count >= 20: # Updated limit as per previous context
if current_count >= 20:

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 (bad-indentation) Warning

Bad indentation. Found 4 spaces, expected 8 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content={"message": "Weekly cancellation limit reached."}
Expand All @@ -454,16 +449,13 @@
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"
Expand All @@ -478,11 +470,11 @@
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,
"type": refund_type,

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
"reason": "User Cancelled"
}
}
Expand All @@ -493,14 +485,12 @@
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 = {
Expand All @@ -512,7 +502,7 @@
"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,

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
"status": "AVAILABLE",
"created_at": firestore.SERVER_TIMESTAMP
}
Expand All @@ -522,9 +512,6 @@

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, {
Expand Down
Loading