added state api

This commit is contained in:
2020-02-24 16:00:41 +01:00
parent 6ba38cd42d
commit 1d011af64b
10 changed files with 74 additions and 80 deletions

View File

@@ -30,6 +30,7 @@ api_group = Namespace('group', description="Group management namespace", authori
api_permissions = Namespace('permissions', description="Permissions management namespace", authorizations=api_authorizations)
api_room = Namespace('room', description="Room management namespace", authorizations=api_authorizations)
api_recorder = Namespace('recorder', description="Recorder management namespace", authorizations=api_authorizations)
api_state = Namespace('state', description="Object state management namespace", authorizations=api_authorizations)
api_virtual_command = Namespace('virtual_command', description="Virtual command namespace",
authorizations=api_authorizations)
api_cron_job = Namespace('cron_job', description="Cron job namespace",
@@ -42,6 +43,7 @@ api_v1.add_namespace(api_group)
api_v1.add_namespace(api_permissions)
api_v1.add_namespace(api_room)
api_v1.add_namespace(api_recorder)
api_v1.add_namespace(api_state)
api_v1.add_namespace(api_virtual_command)
api_v1.add_namespace(api_cron_job)
api_v1.add_namespace(api_control)
@@ -64,6 +66,7 @@ from .permission_api import *
from .group_api import *
from .room_api import *
from .recorder_api import *
from .state_api import *
from .control_api import *
from .virtual_command_api import *

View File

@@ -1,5 +1,5 @@
from flask_restx import fields
from backend.api import api_user, api_recorder, api_v1
from backend.api import api_user, api_recorder, api_v1, api_state
generic_id_parser = api_v1.parser()
generic_id_parser.add_argument('id', type=str, required=True, store_missing=False)
@@ -102,3 +102,6 @@ recorder_model_model = api_recorder.model('Recorder Model', {
description='Model of the recorder.'),
'commands': fields.List(fields.Nested(recorder_command_model), attribute="recorder_commands")
})
state_model = api_state.model('Recorder', {
})

View File

@@ -1,9 +1,6 @@
# Copyright (c) 2019. Tobias Kurze
"""
This module provides functions related to authentication through the API.
For example: listing of available auth providers or registration of users.
Login through API does not start a new session, but instead returns JWT.
This module provides functions related to recorders through the API.
"""
from datetime import datetime
from pprint import pprint

48
backend/api/state_api.py Normal file
View File

@@ -0,0 +1,48 @@
# Copyright (c) 2019. Tobias Kurze
"""
This module provides functions related to object states through the API.
"""
from datetime import datetime
from pprint import pprint
from flask_jwt_extended import jwt_required
from flask_restx import fields, Resource, inputs
from backend import db, app
from backend.api import api_state
from backend.api.models import recorder_model, recorder_model_model, recorder_command_model, state_model
from backend.models.recorder_model import Recorder, RecorderModel, RecorderCommand
from backend.models.room_model import Room
import backend.recorder_adapters as r_a
# ==
@api_state.route('/<int:id>')
@api_state.response(404, 'Recorder not found')
@api_state.param('id', 'The recorder identifier')
class RecorderStateResource(Resource):
@jwt_required
@api_state.doc('get_recorder_state')
@api_state.marshal_with(state_model, skip_none=False)
def get(self, id):
"""Fetch a recorder given its identifier"""
recorder = Recorder.query.get(id)
if recorder is None:
api_state.abort(404)
return recorder
@api_state.route('')
class RecorderStateList(Resource):
@jwt_required
@api_state.doc('recorders')
@api_state.marshal_list_with(recorder_model, skip_none=False)
def get(self):
"""
List all recorders
:return: recorders
"""
return Recorder.get_all()