CRUD_UserProfile
Some checks failed
K8S Fission Deployment / Deployment fission functions (push) Failing after 21s
Some checks failed
K8S Fission Deployment / Deployment fission functions (push) Failing after 21s
This commit is contained in:
73
apps/ailbl-users_profile-insert-get-update.py
Normal file
73
apps/ailbl-users_profile-insert-get-update.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import crud
|
||||
from flask import jsonify, request
|
||||
from helpers import init_db_connection
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
```fission
|
||||
{
|
||||
"name": "profile-users-get-insert-put",
|
||||
"http_triggers": {
|
||||
"profile-users-get-insert-put-http": {
|
||||
"url": "/ailbl/users/profiles",
|
||||
"methods": ["POST", "PUT", "GET"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
"""
|
||||
try:
|
||||
if request.method == "PUT":
|
||||
return make_update_request()
|
||||
elif request.method == "POST":
|
||||
return make_insert_request()
|
||||
elif request.method == "GET":
|
||||
return make_get_request()
|
||||
else:
|
||||
return {"error": "Method not allow"}, 405
|
||||
except Exception as ex:
|
||||
return jsonify({"error": str(ex)}), 500
|
||||
|
||||
|
||||
def make_insert_request():
|
||||
try:
|
||||
data = request.get_json() # Lay du lieu json tu request body
|
||||
if not data.get("user_id"):
|
||||
return jsonify({"error": "user_id is required"}), 400
|
||||
|
||||
response, status = crud.insert_profile(data)
|
||||
|
||||
return jsonify(response), status
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
def make_update_request():
|
||||
try:
|
||||
data = request.get_json() # Lay du lieu json tu request body
|
||||
user_id = data.get("user_id")
|
||||
|
||||
if not user_id:
|
||||
return jsonify({"error": "user_id is required"}), 400
|
||||
|
||||
# Call CRUD function to update profile
|
||||
response, status = crud.update_profile
|
||||
return jsonify(response), status
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
def make_get_request():
|
||||
try:
|
||||
user_id = request.headers.get("X-User")
|
||||
if not user_id:
|
||||
return jsonify({"error": "user_id is required"}), 400
|
||||
|
||||
response, status = crud.get_profile(user_id)
|
||||
return jsonify(response), status
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
Reference in New Issue
Block a user