69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
from flask import Blueprint, request
|
|
from .. import impl
|
|
from ..services.auth_guard import auth_guard
|
|
from marshmallow import EXCLUDE
|
|
from ..schemas import model
|
|
import json
|
|
import logging
|
|
|
|
bp = Blueprint('ships', __name__)
|
|
|
|
@bp.route('/ships', methods=['get'])
|
|
@auth_guard() # no restriction by role
|
|
def GetShips():
|
|
|
|
if 'Authorization' in request.headers:
|
|
token = request.headers.get('Authorization')
|
|
return impl.ships.GetShips(token)
|
|
else:
|
|
return json.dumps("not authenticated"), 403
|
|
|
|
|
|
@bp.route('/ships', methods=['post'])
|
|
@auth_guard() # no restriction by role
|
|
def PostShip():
|
|
|
|
try:
|
|
content = request.get_json(force=True)
|
|
loadedModel = model.ShipSchema().load(data=content, many=False, partial=True)
|
|
except Exception as ex:
|
|
logging.error(ex)
|
|
print(ex)
|
|
return json.dumps("bad format"), 400
|
|
|
|
return impl.ships.PostShip(loadedModel)
|
|
|
|
|
|
@bp.route('/ships', methods=['put'])
|
|
@auth_guard() # no restriction by role
|
|
def PutShip():
|
|
|
|
try:
|
|
content = request.get_json(force=True)
|
|
loadedModel = model.ShipSchema().load(data=content, many=False, partial=True, unknown=EXCLUDE)
|
|
except Exception as ex:
|
|
logging.error(ex)
|
|
print(ex)
|
|
return json.dumps("bad format"), 400
|
|
|
|
return impl.ships.PutShip(loadedModel)
|
|
|
|
|
|
@bp.route('/ships', methods=['delete'])
|
|
@auth_guard() # no restriction by role
|
|
def DeleteShip():
|
|
|
|
# TODO check if I am allowed to delete this thing by deriving the participant from the bearer token
|
|
try:
|
|
if 'id' in request.args:
|
|
options = {}
|
|
options["id"] = request.args.get("id")
|
|
else:
|
|
return json.dumps("no id provided"), 400
|
|
except Exception as ex:
|
|
logging.error(ex)
|
|
print(ex)
|
|
return json.dumps("bad format"), 400
|
|
|
|
return impl.ships.DeleteShip(options)
|