def getRelatives():
decoded = jwt.decode(request.cookies.get('token'), SECRET_KEY, algorithms=['HS256'])
current_user_profile_id = decoded['user_profile_id']
#Retrieve all relatives from database, not filtered by user
#To Do: Filter this by user
user_relatives = models.db_session.query(models.user_relatives).all()
user_relatives_ids = []
#Iterate through all relatives
for user_relative in user_relatives:
user = list(user_relative)
#For each relative, grab only those that match on the current_user_profile_id
if current_user_profile_id == str(user[0]):
user_relatives_ids.append(int(user[1]))
#Retrieve all relatives from DB
#To Do: is this the same information in the user_relatives variable above?
relatives = models.db_session.query(models.Relative).all()
finalRelatives = []
#Iterate through all relatives
for relative in relatives:
#Grab only relatives who match the relatives in the user_relatives_ids storage
if relative.serialize()['id'] in user_relatives_ids:
finalRelatives.append(relative.serialize())
return jsonify({'relativeList' : finalRelatives})
评论列表
文章目录