rairo commited on
Commit
544f6ed
·
verified ·
1 Parent(s): 8c0e1ac

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +49 -0
main.py CHANGED
@@ -390,6 +390,55 @@ def get_user_profile():
390
  except Exception as e:
391
  return jsonify({'error': str(e)}), 500
392
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393
 
394
  # delete users
395
 
 
390
  except Exception as e:
391
  return jsonify({'error': str(e)}), 500
392
 
393
+ # Receipt endpoints
394
+ @app.route('/api/admin/receipt/<string:transaction_id>/view', methods=['GET'])
395
+ def view_receipt(transaction_id):
396
+ try:
397
+ verify_admin(request.headers.get('Authorization', ''))
398
+ transaction_ref = db.reference(f'transactions/{transaction_id}')
399
+ transaction_data = transaction_ref.get()
400
+ if not transaction_data:
401
+ return jsonify({'error': 'Transaction not found'}), 404
402
+
403
+ image_url = transaction_data.get('image_url')
404
+ if not image_url:
405
+ return jsonify({'error': 'No receipt image found for this transaction'}), 404
406
+
407
+ # Fetch the image from the public URL
408
+ r = requests.get(image_url)
409
+ if r.status_code != 200:
410
+ return jsonify({'error': 'Unable to fetch image from storage'}), 500
411
+
412
+ return send_file(io.BytesIO(r.content), mimetype='image/jpeg')
413
+ except Exception as e:
414
+ return jsonify({'error': str(e)}), 500
415
+
416
+ @app.route('/api/admin/receipt/<string:transaction_id>/download', methods=['GET'])
417
+ def download_receipt(transaction_id):
418
+ try:
419
+ verify_admin(request.headers.get('Authorization', ''))
420
+ transaction_ref = db.reference(f'transactions/{transaction_id}')
421
+ transaction_data = transaction_ref.get()
422
+ if not transaction_data:
423
+ return jsonify({'error': 'Transaction not found'}), 404
424
+
425
+ image_url = transaction_data.get('image_url')
426
+ if not image_url:
427
+ return jsonify({'error': 'No receipt image found for this transaction'}), 404
428
+
429
+ r = requests.get(image_url)
430
+ if r.status_code != 200:
431
+ return jsonify({'error': 'Unable to fetch image from storage'}), 500
432
+
433
+ return send_file(
434
+ io.BytesIO(r.content),
435
+ mimetype='image/jpeg',
436
+ as_attachment=True,
437
+ download_name='receipt.jpg'
438
+ )
439
+ except Exception as e:
440
+ return jsonify({'error': str(e)}), 500
441
+
442
 
443
  # delete users
444