extract update profile handler handler
This commit is contained in:
parent
3bed7222ec
commit
101bc20923
1
ki/handlers/__init__.py
Normal file
1
ki/handlers/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from ki.handlers.update_profile import update_profile # noqa
|
25
ki/handlers/update_profile.py
Normal file
25
ki/handlers/update_profile.py
Normal file
@ -0,0 +1,25 @@
|
||||
from flask import make_response, request
|
||||
|
||||
from ki.models import User, Profile
|
||||
from app import db
|
||||
|
||||
|
||||
def update_profile(user_id):
|
||||
user = User.query.filter(User.id == int(user_id)).first()
|
||||
|
||||
if user is None:
|
||||
return make_response({}, 404)
|
||||
|
||||
profile = user.profile
|
||||
|
||||
if (profile is None):
|
||||
profile = Profile(user=user, nickname=user.auth_id)
|
||||
db.session.add(profile)
|
||||
|
||||
profile.pronouns = request.json.get("pronouns", "")
|
||||
profile.volunteerwork = request.json.get("volunteerwork", "")
|
||||
profile.freetext = request.json.get("freetext", "")
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return make_response({"profile": profile.to_dict()})
|
24
ki/routes.py
24
ki/routes.py
@ -3,8 +3,9 @@ from flask import g, make_response, request, send_file
|
||||
from functools import wraps
|
||||
|
||||
from ki.auth import auth
|
||||
from ki.models import Language, Skill, Token, User, Profile
|
||||
from app import app, db
|
||||
from ki.handlers import update_profile as update_profile_handler
|
||||
from ki.models import Language, Skill, Token, User
|
||||
from app import app
|
||||
|
||||
|
||||
def token_auth(func):
|
||||
@ -122,24 +123,7 @@ def get_user_profile(user_id):
|
||||
|
||||
@app.route("/users/<user_id>/profile", methods=["POST"])
|
||||
def update_profile(user_id):
|
||||
user = User.query.filter(User.id == int(user_id)).first()
|
||||
|
||||
if user is None:
|
||||
return make_response({}, 404)
|
||||
|
||||
profile = user.profile
|
||||
|
||||
if (profile is None):
|
||||
profile = Profile(user=user, nickname=user.auth_id)
|
||||
db.session.add(profile)
|
||||
|
||||
profile.pronouns = request.json.get("pronouns", "")
|
||||
profile.volunteerwork = request.json.get("volunteerwork", "")
|
||||
profile.freetext = request.json.get("freetext", "")
|
||||
|
||||
db.session.commit()
|
||||
|
||||
return make_response(profile.to_dict(), 200)
|
||||
return update_profile_handler(user_id)
|
||||
|
||||
|
||||
@app.route("/skills")
|
||||
|
Loading…
Reference in New Issue
Block a user