LogicGoInfotechSpaces commited on
Commit
90b7591
·
verified ·
1 Parent(s): 986b0e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -21
app.py CHANGED
@@ -307,17 +307,20 @@ async def face_swap_api(
307
  # ---------- media_clicks update only if user_id exists ----------
308
  if user_id:
309
  try:
310
- print("\n======= MEDIA_CLICKS DEBUG LOG =======")
311
- print("user_id received:", user_id)
312
- print("category_id resolved from subcategory:", category_id)
313
- print("ADMIN_MONGO_URL:", ADMIN_MONGO_URL)
314
-
315
- user_oid = ObjectId(user_id)
316
- cat_oid = ObjectId(category_id)
317
-
 
 
 
 
318
  now = datetime.utcnow()
319
-
320
- # Try to update existing category entry
321
  update_result = await media_clicks_col.update_one(
322
  {
323
  "userId": user_oid,
@@ -333,14 +336,13 @@ async def face_swap_api(
333
  }
334
  }
335
  )
336
-
337
- print("Existing category update matched_count:", update_result.matched_count)
338
- print("Existing category update modified_count:", update_result.modified_count)
339
-
340
- # If category did not exist, push new category object
341
  if update_result.matched_count == 0:
342
- print("Category not found under this user → pushing new category entry")
343
-
344
  insert_result = await media_clicks_col.update_one(
345
  {"userId": user_oid},
346
  {
@@ -356,10 +358,11 @@ async def face_swap_api(
356
  },
357
  upsert=True
358
  )
359
-
360
- print("Insert/upsert raw_result:", insert_result.raw_result)
361
-
362
- print("======= END MEDIA_CLICKS LOG =======\n")
 
363
 
364
  except Exception as media_err:
365
  print("❌ ERROR while saving media_clicks:", str(media_err))
 
307
  # ---------- media_clicks update only if user_id exists ----------
308
  if user_id:
309
  try:
310
+ logger.info("======= MEDIA_CLICKS DEBUG LOG =======")
311
+ logger.info(f"user_id received: {user_id}")
312
+ logger.info(f"category_id resolved from subcategory: {category_id}")
313
+ logger.info(f"ADMIN_MONGO_URL: {ADMIN_MONGO_URL}")
314
+
315
+ try:
316
+ user_oid = ObjectId(user_id)
317
+ cat_oid = ObjectId(category_id)
318
+ except Exception as conv_err:
319
+ logger.error(f"❌ ObjectId conversion failed: {conv_err}")
320
+ raise HTTPException(status_code=400, detail=f"Invalid user_id or category_id: {conv_err}")
321
+
322
  now = datetime.utcnow()
323
+
 
324
  update_result = await media_clicks_col.update_one(
325
  {
326
  "userId": user_oid,
 
336
  }
337
  }
338
  )
339
+
340
+ logger.info(f"Existing category update matched_count: {update_result.matched_count}")
341
+ logger.info(f"Existing category update modified_count: {update_result.modified_count}")
342
+
 
343
  if update_result.matched_count == 0:
344
+ logger.info("Category not found → pushing new category entry")
345
+
346
  insert_result = await media_clicks_col.update_one(
347
  {"userId": user_oid},
348
  {
 
358
  },
359
  upsert=True
360
  )
361
+
362
+ logger.info(f"Insert/upsert raw_result: {insert_result.raw_result}")
363
+
364
+ logger.info("======= END MEDIA_CLICKS LOG =======")
365
+
366
 
367
  except Exception as media_err:
368
  print("❌ ERROR while saving media_clicks:", str(media_err))