git_brcal/src/server/BreCal/api/participant.py

31 lines
1.2 KiB
Python

import logging
from flask import Blueprint, request
from .. import impl
from ..services.auth_guard import auth_guard
from ..services.jwt_handler import decode_jwt
import json
from BreCal.validators.validation_error import create_dynamic_exception_response
bp = Blueprint('participants', __name__)
@bp.route('/participants', methods=['get'])
@auth_guard() # no restriction by role
def GetParticipant():
try:
if 'Authorization' in request.headers:
payload = decode_jwt(request.headers.get("Authorization").split("Bearer ")[-1])
options = {}
options["user_id"] = request.args.get("user_id")
if "participant_id" in payload:
options["participant_id"] = payload["participant_id"]
else:
return create_dynamic_exception_response(ex=None, status_code=403, message="not authorized")
return impl.participant.GetParticipant(options)
else:
return create_dynamic_exception_response(ex=None, status_code=403, message="not authenticated")
except Exception as ex:
return create_dynamic_exception_response(ex=ex, status_code=400)