diff --git a/api/messages/messages_service.py b/api/messages/messages_service.py index 21e5c03..b1cfb9b 100644 --- a/api/messages/messages_service.py +++ b/api/messages/messages_service.py @@ -577,6 +577,53 @@ def unjoin_team(propel_user_id, json): return Message( "Removed from Team") +@limits(calls=100, period=ONE_MINUTE) +def update_npo_application( application_id, json, propel_id): + send_slack_audit(action="update_npo_application", message="Updating", payload=json) + db = get_db() + logger.info("NPO Application Update") + doc = db.collection('project_applications').document(application_id) + if doc: + doc_dict = doc.get().to_dict() + send_slack_audit(action="update_npo_application", + message="Updating", payload=doc_dict) + doc.update(json) + + # Clear cache for get_npo_applications + logger.info(f"Clearing cache for application_id={application_id}") + + clear_cache() + + return Message( + "Updated NPO Application" + ) + + +@limits(calls=100, period=ONE_MINUTE) +def get_npo_applications(): + logger.info("get_npo_applications Start") + db = get_db() + + # Use a transaction to ensure consistency + @firestore.transactional + def get_latest_docs(transaction): + docs = db.collection('project_applications').get(transaction=transaction) + return [doc_to_json(docid=doc.id, doc=doc) for doc in docs] + + + # Use a transaction to get the latest data + transaction = db.transaction() + results = get_latest_docs(transaction) + + if not results: + return {"applications": []} + + logger.info(results) + logger.info("get_npo_applications End") + + return {"applications": results} + + @limits(calls=100, period=ONE_MINUTE) def save_npo_application(json): send_slack_audit(action="save_npo_application", message="Saving", payload=json) diff --git a/api/messages/messages_views.py b/api/messages/messages_views.py index 6c1f47f..9185599 100644 --- a/api/messages/messages_views.py +++ b/api/messages/messages_views.py @@ -39,7 +39,9 @@ save_lead_async, get_news, get_all_profiles, - save_npo_application + save_npo_application, + get_npo_applications, + update_npo_application ) @@ -108,6 +110,18 @@ def get_npo(npo_id): def submit_npo_application(): return vars(save_npo_application(request.get_json())) +@bp.route("/npo/applications", methods=["GET"]) +@auth.require_user +@auth.require_org_member_with_permission("volunteer.admin", req_to_org_id=getOrgId) +def get_npo_applications_api(): + return get_npo_applications() + +@bp.route("/npo/applications/", methods=["PATCH"]) +@auth.require_user +@auth.require_org_member_with_permission("volunteer.admin", req_to_org_id=getOrgId) +def update_npo_application_api(application_id): + if auth_user and auth_user.user_id: + return vars(update_npo_application(application_id, request.get_json(), auth_user.user_id)) # # Hackathon Related Endpoints