die meisten GET calls sind drin, 2 funktionieren noch nicht
This commit is contained in:
parent
a40df31f9d
commit
d0a77b3f0f
@ -11,6 +11,7 @@ from .api import participant
|
||||
from .api import times
|
||||
from .api import notifications
|
||||
from .api import berths
|
||||
from .api import ships
|
||||
|
||||
sessions = dict()
|
||||
|
||||
@ -38,6 +39,7 @@ def create_app(test_config=None):
|
||||
app.register_blueprint(times.bp)
|
||||
app.register_blueprint(notifications.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')
|
||||
local_db.initPool()
|
||||
|
||||
13
src/server/BreCal/api/ships.py
Normal file
13
src/server/BreCal/api/ships.py
Normal 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)
|
||||
@ -4,3 +4,4 @@ from . import participant
|
||||
from . import shipcalls
|
||||
from . import times
|
||||
from . import verify
|
||||
from . import ships
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import json
|
||||
import logging
|
||||
import pydapper
|
||||
|
||||
from ..schemas import model
|
||||
from .. import local_db
|
||||
|
||||
def GetNotifications(options):
|
||||
"""
|
||||
|
||||
@ -1,21 +1,32 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
import pydapper
|
||||
|
||||
from ..schemas import model
|
||||
from .. import local_db
|
||||
|
||||
def GetShipcalls(options):
|
||||
"""
|
||||
:param options: A dictionary containing all the paramters for the Operations
|
||||
options["participant_id"]: **Id of participant**. *Example: 2*. Id of participant entity requesting ship calls
|
||||
|
||||
No parameters, gets all entries
|
||||
"""
|
||||
|
||||
# Implement your business logic here
|
||||
# All the parameters are present in the options argument
|
||||
# TODO: validate token
|
||||
|
||||
return json.dumps([{
|
||||
"description": "<string>",
|
||||
"id": "<ShipcallId>",
|
||||
"type": "<string>",
|
||||
}]), 200
|
||||
try:
|
||||
|
||||
commands = pydapper.using(local_db.connection_pool)
|
||||
data = commands.query("SELECT id, ship_id, type, eta, voyage, etd, arrival_berth_id, departure_berth_id, tug_required, pilot_required, " +
|
||||
"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):
|
||||
|
||||
29
src/server/BreCal/impl/ships.py
Normal file
29
src/server/BreCal/impl/ships.py
Normal 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
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
import json
|
||||
import logging
|
||||
import pydapper
|
||||
|
||||
from ..schemas import model
|
||||
from .. import local_db
|
||||
|
||||
def GetTimes(options):
|
||||
"""
|
||||
@ -8,20 +12,20 @@ def GetTimes(options):
|
||||
|
||||
"""
|
||||
|
||||
# Implement your business logic here
|
||||
# All the parameters are present in the options argument
|
||||
# TODO: validate token
|
||||
|
||||
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):
|
||||
@ -30,8 +34,7 @@ def PostTimes(body):
|
||||
:param body: The parsed body of the request
|
||||
"""
|
||||
|
||||
# Implement your business logic here
|
||||
# All the parameters are present in the options argument
|
||||
# This creates a *new* entry
|
||||
|
||||
return 400
|
||||
|
||||
@ -42,8 +45,9 @@ def PutTimes(body):
|
||||
:param body: The parsed body of the request
|
||||
"""
|
||||
|
||||
# Implement your business logic here
|
||||
# All the parameters are present in the options argument
|
||||
# This updates an *existing* entry
|
||||
|
||||
|
||||
|
||||
return 400
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ class Error(Schema):
|
||||
class GetVerifyInlineResp(Schema):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Notification(Schema):
|
||||
|
||||
id: int
|
||||
@ -75,6 +75,7 @@ class Participant(Schema):
|
||||
class ParticipantList(Participant):
|
||||
pass
|
||||
|
||||
@dataclass
|
||||
class Shipcall(Schema):
|
||||
id: int
|
||||
ship_id: int
|
||||
@ -124,7 +125,7 @@ class Shipcall(Schema):
|
||||
class ShipcallId(Schema):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Times(Schema):
|
||||
id: int
|
||||
start_planned: datetime
|
||||
@ -148,6 +149,7 @@ class Times(Schema):
|
||||
created = fields.DateTime()
|
||||
modified = fields.DateTime()
|
||||
|
||||
@dataclass
|
||||
class Ship(Schema):
|
||||
id: int
|
||||
name: str
|
||||
|
||||
Reference in New Issue
Block a user