Skip to content

Commit

Permalink
Add role name to members endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bsatoriu committed Aug 26, 2024
1 parent 563a9dd commit 48d2dff
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions api/endpoints/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from flask import request, jsonify, Response
from flask_api import status
from sqlalchemy.exc import SQLAlchemyError

from api.models.role import Role
from api.restplus import api
import api.settings as settings
from api.auth.security import get_authorized_user, login_required, valid_dps_request, edl_federated_request, \
Expand Down Expand Up @@ -42,19 +44,26 @@ class Member(Resource):
@api.doc(security='ApiKeyAuth')
@login_required()
def get(self):
members = db.session.query(
Member_db.id,
Member_db.username,
Member_db.first_name,
Member_db.last_name,
Member_db.email,
Member_db.status,
Member_db.creation_date

member_query = db.session.query(
Member_db, Role,
).filter(
Member_db.role_id == Role.id
).order_by(Member_db.username).all()

member_schema = MemberSchema()
result = [json.loads(member_schema.dumps(m)) for m in members]
return result
result = [{
'id': m.Member.id,
'username': m.Member.username,
'first_name': m.Member.first_name,
'last_name': m.Member.last_name,
'email': m.Member.email,
'role_id': m.Member.role_id,
'role_name': m.Role.role_name,
'status': m.Member.status,
'creation_date': m.Member.creation_date,
} for m in member_query]

return json.dumps(result, indent=4, sort_keys=True, default=str)


@ns.route('/<string:key>')
Expand Down

0 comments on commit 48d2dff

Please sign in to comment.