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

29 lines
981 B
Python

import logging
from flask import Blueprint, request
from webargs.flaskparser import parser
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('berths', __name__)
@bp.route('/berths', methods=['get'])
@auth_guard() # no restriction by role
def GetBerths():
try:
if 'Authorization' in request.headers:
token = request.headers.get('Authorization')
payload = decode_jwt(token.split("Bearer ")[-1])
options = {}
options["participant_id"] = payload["participant_id"]
return impl.berths.GetBerths(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)