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

57 lines
1.6 KiB
Python

from flask import Blueprint, request
from webargs.flaskparser import parser
from marshmallow import Schema, fields
from ..schemas import model
from .. import impl
from ..services.auth_guard import auth_guard
import logging
import json
bp = Blueprint('shipcalls', __name__)
@bp.route('/shipcalls', methods=['get'])
@auth_guard() # no restriction by role
def GetShipcalls():
if 'Authorization' in request.headers:
token = request.headers.get('Authorization')
options = {}
options["participant_id"] = request.args.get("participant_id")
options["past_days"] = request.args.get("past_days", default=1, type=int)
return impl.shipcalls.GetShipcalls(options)
else:
return json.dumps("not authenticated"), 403
@bp.route('/shipcalls', methods=['post'])
@auth_guard() # no restriction by role
def PostShipcalls():
try:
content = request.get_json(force=True)
logging.info(content)
loadedModel = model.ShipcallSchema().load(data=content, many=False, partial=True)
except Exception as ex:
logging.error(ex)
print(ex)
return json.dumps("bad format"), 400
return impl.shipcalls.PostShipcalls(loadedModel)
@bp.route('/shipcalls', methods=['put'])
@auth_guard() # no restriction by role
def PutShipcalls():
try:
content = request.get_json(force=True)
logging.info(content)
loadedModel = model.ShipcallSchema().load(data=content, many=False, partial=True)
except Exception as ex:
logging.error(ex)
print(ex)
return json.dumps("bad format"), 400
return impl.shipcalls.PutShipcalls(loadedModel)