die meisten GET calls sind drin, 2 funktionieren noch nicht

This commit is contained in:
Daniel Schick 2023-06-19 16:04:02 +02:00
parent a40df31f9d
commit d0a77b3f0f
8 changed files with 95 additions and 29 deletions

View File

@ -11,6 +11,7 @@ from .api import participant
from .api import times from .api import times
from .api import notifications from .api import notifications
from .api import berths from .api import berths
from .api import ships
sessions = dict() sessions = dict()
@ -38,6 +39,7 @@ def create_app(test_config=None):
app.register_blueprint(times.bp) app.register_blueprint(times.bp)
app.register_blueprint(notifications.bp) app.register_blueprint(notifications.bp)
app.register_blueprint(berths.bp) app.register_blueprint(berths.bp)
app.register_blueprint(ships.bp)
logging.basicConfig(filename='brecal.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s') logging.basicConfig(filename='brecal.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s')
local_db.initPool() local_db.initPool()

View File

@ -0,0 +1,13 @@
from flask import Blueprint, request
from webargs.flaskparser import parser
from marshmallow import Schema, fields
from ..schemas import model
from .. import impl
bp = Blueprint('ships', __name__)
@bp.route('/ships', methods=['get'])
def GetShips():
token = request.headers.get('Authentication')
return impl.ships.GetShips(token)

View File

@ -4,3 +4,4 @@ from . import participant
from . import shipcalls from . import shipcalls
from . import times from . import times
from . import verify from . import verify
from . import ships

View File

@ -1,5 +1,9 @@
import json import json
import logging import logging
import pydapper
from ..schemas import model
from .. import local_db
def GetNotifications(options): def GetNotifications(options):
""" """

View File

@ -1,21 +1,32 @@
import json import json
import logging import logging
import pydapper
from ..schemas import model
from .. import local_db
def GetShipcalls(options): def GetShipcalls(options):
""" """
:param options: A dictionary containing all the paramters for the Operations No parameters, gets all entries
options["participant_id"]: **Id of participant**. *Example: 2*. Id of participant entity requesting ship calls
""" """
# Implement your business logic here # TODO: validate token
# All the parameters are present in the options argument
return json.dumps([{ try:
"description": "<string>",
"id": "<ShipcallId>", commands = pydapper.using(local_db.connection_pool)
"type": "<string>", data = commands.query("SELECT id, ship_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, " +
}]), 200 "flags, pier_side, bunkering, replenishing, draft, tidal_window_from, tidal_window_to, rain_sensitive_cargo, recommended_tugs, " +
"created, modified FROM shipcall WHERE eta IS NULL OR eta >= DATE(NOW() - INTERVAL 2 DAY) " +
"ORDER BY eta", model=model.Shipcall)
except Exception as ex:
logging.error(ex)
print(ex)
return json.dumps("call failed"), 500
return json.dumps(data, default=model.obj_dict), 200
def PostShipcalls(body): def PostShipcalls(body):

View File

@ -0,0 +1,29 @@
import json
import logging
import pydapper
from ..schemas import model
from .. import local_db
def GetShips(token):
"""
No parameters, gets all entries
"""
# TODO: validate token
try:
commands = pydapper.using(local_db.connection_pool)
data = commands.query("SELECT id, name, imo, callsign, participant_id, length, width, created, modified FROM ship ORDER BY name", model=model.Ship)
except Exception as ex:
logging.error(ex)
print(ex)
return json.dumps("call failed"), 500
return json.dumps(data, default=model.obj_dict), 200

View File

@ -1,5 +1,9 @@
import json import json
import logging import logging
import pydapper
from ..schemas import model
from .. import local_db
def GetTimes(options): def GetTimes(options):
""" """
@ -8,20 +12,20 @@ def GetTimes(options):
""" """
# Implement your business logic here # TODO: validate token
# All the parameters are present in the options argument
try:
commands = pydapper.using(local_db.connection_pool)
data = commands.query("SELECT id, start_planned, end_planned, duration_planned, start_actual, end_actual, duration_actual, shipcall_id, participant_id, created, modified FROM times " +
"WHERE times.shipcall_id = ?scid?", model=model.Times, param={"scid" : options["shipcall_id"]})
except Exception as ex:
logging.error(ex)
print(ex)
return json.dumps("call failed"), 500
return json.dumps(data, default=model.obj_dict), 200
return json.dumps([{
"duration_planned": "<integer>",
"end_actual": "<date-time>",
"end_planned": "<date-time>",
"id": "<integer>",
"participant_id": "<integer>",
"shipcall_id": "<integer>",
"start_actual": "<date-time>",
"start_planned": "<date-time>",
"remark":"<string>"
}]), 200
def PostTimes(body): def PostTimes(body):
@ -30,8 +34,7 @@ def PostTimes(body):
:param body: The parsed body of the request :param body: The parsed body of the request
""" """
# Implement your business logic here # This creates a *new* entry
# All the parameters are present in the options argument
return 400 return 400
@ -42,8 +45,9 @@ def PutTimes(body):
:param body: The parsed body of the request :param body: The parsed body of the request
""" """
# Implement your business logic here # This updates an *existing* entry
# All the parameters are present in the options argument
return 400 return 400

View File

@ -31,7 +31,7 @@ class Error(Schema):
class GetVerifyInlineResp(Schema): class GetVerifyInlineResp(Schema):
pass pass
@dataclass
class Notification(Schema): class Notification(Schema):
id: int id: int
@ -75,6 +75,7 @@ class Participant(Schema):
class ParticipantList(Participant): class ParticipantList(Participant):
pass pass
@dataclass
class Shipcall(Schema): class Shipcall(Schema):
id: int id: int
ship_id: int ship_id: int
@ -124,7 +125,7 @@ class Shipcall(Schema):
class ShipcallId(Schema): class ShipcallId(Schema):
pass pass
@dataclass
class Times(Schema): class Times(Schema):
id: int id: int
start_planned: datetime start_planned: datetime
@ -148,6 +149,7 @@ class Times(Schema):
created = fields.DateTime() created = fields.DateTime()
modified = fields.DateTime() modified = fields.DateTime()
@dataclass
class Ship(Schema): class Ship(Schema):
id: int id: int
name: str name: str