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
11 changes: 9 additions & 2 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# app/app.py
# app/app.py

Check warning

Code scanning / Pylint (reported by Codacy)

Missing module docstring Warning

Missing module docstring

Check warning

Code scanning / Prospector (reported by Codacy)

indentation is not a multiple of four (comment) (E114) Warning

indentation is not a multiple of four (comment) (E114)

Check warning

Code scanning / Prospector (reported by Codacy)

unexpected indentation (comment) (E116) Warning

unexpected indentation (comment) (E116)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing module docstring Warning

Missing module docstring

import os
from fastapi import FastAPI, Security, File, UploadFile
from fastapi.middleware.cors import CORSMiddleware
Expand Down Expand Up @@ -31,7 +32,7 @@
remove_staff_member,
update_staff_email,
)
from .user import get_user_menu, create_payment_order
from .user import get_user_menu, create_payment_order, get_user_orders
from .webhook import router as webhook_router

app = FastAPI()
Expand Down Expand Up @@ -82,10 +83,16 @@
):
return await create_payment_order(order_data, credentials.credentials)

@app.get("/user/orders", tags=["user"])
async def get_student_orders_endpoint(

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning

Missing function docstring

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning

Missing function or method docstring
credentials: HTTPAuthorizationCredentials = Security(security)
):
return await get_user_orders(credentials.credentials)

@app.post('/staff/add-member', tags=["manager"])
async def add_staff_endpoint(
staff_data: AddStaffSchema,
credentials: HTTPAuthorizationCredentials = Security(security)

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).
):
return await add_staff_member(staff_data, credentials.credentials)

Expand Down
44 changes: 44 additions & 0 deletions app/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .firebase_init import db, firestore
from datetime import datetime
from .schema import CreateOrderSchema

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 2 spaces, expected 4 Note

Bad indentation. Found 2 spaces, expected 4
razorpay_client = razorpay.Client(auth=(
os.environ.get("RAZORPAY_KEY_ID"),
os.environ.get("RAZORPAY_KEY_SECRET")
Expand Down Expand Up @@ -63,7 +63,7 @@
stall_data = stall_doc.to_dict()
stall_id = stall_doc.id

menu_items_ref = (

Check warning

Code scanning / Pylint (reported by Codacy)

Variable name "e" doesn't conform to snake_case naming style Warning

Variable name "e" doesn't conform to snake_case naming style
stall_doc.reference
.collection("menu_items")
.where("is_available", "==", True)
Expand Down Expand Up @@ -105,12 +105,12 @@


async def create_payment_order(order_data: CreateOrderSchema, id_token: str):
try:

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 2 spaces, expected 4 Note

Bad indentation. Found 2 spaces, expected 4
user_data, user_uid = await get_user_details(id_token)

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
if not user_data:

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 / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
return JSONResponse(

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
status_code=status.HTTP_401_UNAUTHORIZED,

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
content={"message": "Invalid or expired token."}

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
)

college_id = user_data.get("college_id")
Expand All @@ -133,13 +133,13 @@
if item_doc.exists:
item_data = item_doc.to_dict()

if item_data.get('is_available') is False:

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": f"Sorry, {item_data.get('name')} is currently out of stock."}
)

price = item_data.get('price', 0)

Check notice

Code scanning / Pylint (reported by Codacy)

Catching too general exception Exception Note

Catching too general exception Exception
quantity = cart_item.quantity
total_amount += price * quantity

Expand All @@ -147,7 +147,7 @@
"item_id": cart_item.item_id,
"name": item_data.get('name'),
"price": price,
"quantity": quantity

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
})

else:
Expand All @@ -165,9 +165,9 @@
new_order_ref = db.collection('orders').document()
internal_order_id = new_order_ref.id

firestore_order_data = {

Check warning

Code scanning / Prospector (reported by Codacy)

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

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

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12
"user_id": user_uid,

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
"stall_id": stall_id,

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
"college_id": college_id,
"items": order_items,
"amount": total_amount,
Expand All @@ -176,9 +176,9 @@
"updated_at": firestore.SERVER_TIMESTAMP
}

new_order_ref.set(firestore_order_data)

Check warning

Code scanning / Prospector (reported by Codacy)

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

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

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "e" doesn't conform to snake_case naming style Warning

Variable name "e" doesn't conform to snake_case naming style

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Catching too general exception Exception Note

Catching too general exception Exception

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 10 spaces, expected 20 (bad-indentation) Warning

Bad indentation. Found 10 spaces, expected 20 (bad-indentation)
data = {

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
"amount": int(total_amount * 100),
"currency": "INR",
"receipt": f"rcpt_{internal_order_id[:8]}",
Expand Down Expand Up @@ -211,3 +211,47 @@
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={"message": f"Payment Error: {str(e)}"}
)


async def get_user_orders(id_token: str):

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning

Missing function docstring

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning

Missing function or method docstring
try:

Check warning

Code scanning / Prospector (reported by Codacy)

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

Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
user_data, user_uid = await get_user_details(id_token)

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)
if not user_data:

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8
return JSONResponse(

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)
status_code=status.HTTP_401_UNAUTHORIZED,

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 2 spaces, expected 4 Note

Bad indentation. Found 2 spaces, expected 4

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 2 spaces, expected 4 Note

Bad indentation. Found 2 spaces, expected 4
content={"message": "Invalid or expired token."}
)

orders_ref = (

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

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
db.collection("orders")

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 1 space). Warning

Wrong hanging indentation (add 1 space).
.where("user_id", "==", user_uid)

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 1 space). Warning

Wrong hanging indentation (add 1 space).
.order_by("created_at", direction=firestore.Query.DESCENDING)

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 1 space). Warning

Wrong hanging indentation (add 1 space).
)

docs = orders_ref.stream()

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

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

my_orders = []

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

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
for doc in docs:

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 4 spaces, expected 8 Note

Bad indentation. Found 4 spaces, expected 8

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
data = doc.to_dict()

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12
data['order_id'] = doc.id

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

data = serialize_firestore_data(data)

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

data.pop("razorpay_payment_data", None)

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12
data.pop("internal_order_id", None)

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

my_orders.append(data)

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 Note

Bad indentation. Found 6 spaces, expected 12

Check warning

Code scanning / Prospector (reported by Codacy)

Bad indentation. Found 6 spaces, expected 12 (bad-indentation) Warning

Bad indentation. Found 6 spaces, expected 12 (bad-indentation)

return JSONResponse(

Check notice

Code scanning / Pylint (reported by Codacy)

Bad indentation. Found 8 spaces, expected 16 Note

Bad indentation. Found 8 spaces, expected 16
status_code=status.HTTP_200_OK,
content={
"count": len(my_orders),

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
"orders": my_orders

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
}
)

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

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong hanging indentation (add 2 spaces). Warning

Wrong hanging indentation (add 2 spaces).
)
Loading