implement address update

This commit is contained in:
2021-06-27 12:20:36 +02:00
parent 101bc20923
commit 54a6686474
3 changed files with 32 additions and 1 deletions

View File

@ -1,9 +1,25 @@
from flask import make_response, request
from ki.models import User, Profile
from ki.models import Address, User, Profile
from app import db
def update_address(profile, address_data):
address = profile.address
if (address is None):
address = Address(profile=profile)
db.session.add(address)
address.name = address_data.get("name", "")
address.street = address_data.get("street", "")
address.house_number = address_data.get("house_number", "")
address.additional = address_data.get("additional", "")
address.postcode = address_data.get("postcode", "")
address.city = address_data.get("city", "")
address.country = address_data.get("country", "")
def update_profile(user_id):
user = User.query.filter(User.id == int(user_id)).first()
@ -20,6 +36,8 @@ def update_profile(user_id):
profile.volunteerwork = request.json.get("volunteerwork", "")
profile.freetext = request.json.get("freetext", "")
update_address(profile, request.json.get("address", {}))
db.session.commit()
return make_response({"profile": profile.to_dict()})