This repository has been archived on 2025-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
BreCal/src/server/BreCal/api/times.py

70 lines
1.8 KiB
Python

from flask import Blueprint, request
from ..schemas import model
from .. import impl
from ..services.auth_guard import auth_guard
import json
import logging
bp = Blueprint('times', __name__)
@bp.route('/times', methods=['get'])
@auth_guard() # no restriction by role
def GetTimes():
options = {}
options["shipcall_id"] = request.args.get("shipcall_id")
return impl.times.GetTimes(options)
@bp.route('/times', methods=['post'])
@auth_guard() # no restriction by role
def PostTimes():
try:
# print (request.is_json)
content = request.get_json(force=True) # force gets us json even if the content-type was wrong
# print (content)
# body = parser.parse(schema, request, location='json')
loadedModel = model.TimesSchema().load(data=content, many=False, partial=True)
except Exception as ex:
logging.error(ex)
print(ex)
return json.dumps("bad format"), 400
return impl.times.PostTimes(loadedModel)
@bp.route('/times', methods=['put'])
@auth_guard() # no restriction by role
def PutTimes():
try:
content = request.get_json(force=True)
loadedModel = model.TimesSchema().load(data=content, many=False, partial=True)
except Exception as ex:
logging.error(ex)
print(ex)
return json.dumps("bad format"), 400
return impl.times.PutTimes(loadedModel)
@bp.route('/times', methods=['delete'])
@auth_guard() # no restriction by role
def DeleteTimes():
# TODO check if I am allowd to delete this thing by deriving the participant from the bearer token
if 'id' in request.args:
options = {}
options["id"] = request.args.get("id")
return impl.times.DeleteTimes(options)
else:
logging.warning("Times delete missing id argument")
return json.dumps("missing argument"), 400