virtual_command_model changes -> model parser needs modification -> also the model relations between recorden model and virtual command may be removed \(not done yet\)

This commit is contained in:
2020-08-14 15:59:24 +02:00
parent b18f9ba616
commit 3ae6db1184
2 changed files with 37 additions and 12 deletions

View File

@@ -13,7 +13,7 @@ from flask_jwt_extended import jwt_required
from flask_restx import fields, Resource
from backend import db, app
from backend.api import api_virtual_command
from backend.api import api_virtual_command, recorder_command_model
from backend.models import VirtualCommand
from backend.models.recorder_model import Recorder, RecorderModel, RecorderCommand
from backend.models.room_model import Room
@@ -37,6 +37,10 @@ virtual_command_model = api_virtual_command.model('VirtualCommand', {
allow_null=True,
skip_none=False,
description='Parent virtual command.')),
'recorder_commands': fields.List(fields.Nested(recorder_command_model)),
'command_default_params': fields.List(fields.Raw()),
'room': fields.Nested(api_virtual_command.model('recorder_room',
{'id': fields.Integer(), 'name': fields.String(),
'number': fields.String(), 'alternate_name': fields.String()}),
@@ -58,9 +62,9 @@ class VirtualCommandResource(Resource):
@api_virtual_command.marshal_with(virtual_command_model, skip_none=False)
def get(self, id):
"""Fetch a recorder given its identifier"""
recorder = Recorder.query.get(id)
if recorder is not None:
return recorder
command = VirtualCommand.query.get(id)
if command is not None:
return command
api_virtual_command.abort(404)
@jwt_required
@@ -91,7 +95,7 @@ class VirtualCommandResource(Resource):
@api_virtual_command.route('')
class RecorderList(Resource):
class VirtualCommandList(Resource):
@jwt_required
@api_virtual_command.doc('recorders')
@api_virtual_command.marshal_list_with(virtual_command_model, skip_none=False)
@@ -100,7 +104,7 @@ class RecorderList(Resource):
List all recorders
:return: recorders
"""
return Recorder.get_all()
return VirtualCommand.get_all()
virtual_command_model_parser = api_virtual_command.parser()
virtual_command_model_parser.add_argument('notes', type=str, required=True)
@@ -119,7 +123,7 @@ class RecorderList(Resource):
if room is not None:
api_virtual_command.payload["room"] = room
else:
return "specified room (id: {}) does not exist!".format(api_virtual_command.payload["room_id"]), 404
return "specified v-command (id: {}) does not exist!".format(api_virtual_command.payload["room_id"]), 404
recorder_model_id = api_virtual_command.payload.pop('recorder_model_id', None)
if recorder_model_id is None:
api_virtual_command.payload["recorder_model"] = None
@@ -138,7 +142,7 @@ class RecorderList(Resource):
if recorder is not None:
api_virtual_command.payload["recorder"] = recorder
else:
return "specified recorder (id: {}) does not exist!".format(
return "specified v-command (id: {}) does not exist!".format(
api_virtual_command.payload["recorder_id"]), 404
virtual_command = VirtualCommand(**api_virtual_command.payload)
db.session.add(virtual_command)