API: user - minor refactor

This commit is contained in:
Sam 2018-05-09 15:52:27 +02:00
parent 2f0c952ecc
commit 436476c55d
2 changed files with 16 additions and 13 deletions

View File

@ -152,19 +152,7 @@ def get_user_status(user_id):
user = User.query.filter_by(id=user_id).first()
response_object = {
'status': 'success',
'data': {
'id': user.id,
'username': user.username,
'email': user.email,
'created_at': user.created_at,
'admin': user.admin,
'first_name': user.first_name,
'last_name': user.last_name,
'bio': user.bio,
'location': user.location,
'birth_date': user.birth_date,
'picture': True if user.picture else False,
}
'data': user.serialize()
}
return jsonify(response_object), 200

View File

@ -76,3 +76,18 @@ class User(db.Model):
return 'Signature expired. Please log in again.'
except jwt.InvalidTokenError:
return 'Invalid token. Please log in again.'
def serialize(self):
return {
'id': self.id,
'username': self.username,
'email': self.email,
'created_at': self.created_at,
'admin': self.admin,
'first_name': self.first_name,
'last_name': self.last_name,
'bio': self.bio,
'location': self.location,
'birth_date': self.birth_date,
'picture': self.picture is not None
}