diff --git a/mpwo_api/mpwo_api/users/auth.py b/mpwo_api/mpwo_api/users/auth.py index 0fbb6fc6..1eb93bc1 100644 --- a/mpwo_api/mpwo_api/users/auth.py +++ b/mpwo_api/mpwo_api/users/auth.py @@ -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 diff --git a/mpwo_api/mpwo_api/users/models.py b/mpwo_api/mpwo_api/users/models.py index 8878b76a..fb991f42 100644 --- a/mpwo_api/mpwo_api/users/models.py +++ b/mpwo_api/mpwo_api/users/models.py @@ -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 + }