Celeskry commited on
Commit
c3b1a33
·
verified ·
1 Parent(s): 24eba9a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +13 -8
main.py CHANGED
@@ -227,7 +227,7 @@ class GmailRequest(BaseModel):
227
  to_email: str
228
  subject: str
229
  customer_name: str
230
- order_id: str
231
  status: str
232
  total_price: str
233
  products: List[ProductItem]
@@ -239,12 +239,15 @@ class CompleteRequest(BaseModel):
239
  mk: str
240
 
241
  @app.post("/api/v1/gmail/create")
242
- async def create_gmail_notif(data: GmailRequest, x_api_key: str = Header(None)):
 
 
 
243
  if x_api_key != API_KEY:
244
- raise HTTPException(status_code=403, detail="Invalid Key")
 
 
245
 
246
- final_order_id = gm_app.generate_order_id()
247
-
248
  order_cache[final_order_id] = {
249
  "email": data.to_email,
250
  "name": data.customer_name,
@@ -262,9 +265,11 @@ async def create_gmail_notif(data: GmailRequest, x_api_key: str = Header(None)):
262
  total_price=data.total_price,
263
  from_name=data.from_name
264
  )
265
-
266
- if res["ok"]:
267
- res["order_id"] = final_order_id
 
 
268
  return res
269
 
270
  @app.post("/api/v1/gmail/done")
 
227
  to_email: str
228
  subject: str
229
  customer_name: str
230
+ order_id: Optional[str] = None
231
  status: str
232
  total_price: str
233
  products: List[ProductItem]
 
239
  mk: str
240
 
241
  @app.post("/api/v1/gmail/create")
242
+ async def create_gmail_notif(
243
+ data: GmailRequest,
244
+ x_api_key: str = Header(None)
245
+ ):
246
  if x_api_key != API_KEY:
247
+ raise HTTPException(status_code=403, detail="API key invalid.")
248
+
249
+ final_order_id = data.order_id if data.order_id else gm_app.generate_random_order_id()
250
 
 
 
251
  order_cache[final_order_id] = {
252
  "email": data.to_email,
253
  "name": data.customer_name,
 
265
  total_price=data.total_price,
266
  from_name=data.from_name
267
  )
268
+
269
+ if not res["ok"]:
270
+ raise HTTPException(status_code=500, detail=res["error"])
271
+
272
+ res["order_id"] = final_order_id
273
  return res
274
 
275
  @app.post("/api/v1/gmail/done")