Add device configuration route
parent
c14b3a8bed
commit
3077e46dc5
|
@ -44,7 +44,8 @@ def add_resources():
|
|||
DeviceRecordingResource,
|
||||
DeviceListResource,
|
||||
DeviceTypeResource,
|
||||
DeviceTypeListResource)
|
||||
DeviceTypeListResource,
|
||||
DeviceConfigurationResource)
|
||||
|
||||
api.add_resource(AccountResource, '/v1/accounts/<int:account_id>')
|
||||
api.add_resource(AccountListResource, '/v1/accounts')
|
||||
|
@ -57,6 +58,8 @@ def add_resources():
|
|||
api.add_resource(DeviceTypeResource,
|
||||
'/v1/devices/types/<int:device_type_id>')
|
||||
api.add_resource(DeviceTypeListResource, '/v1/devices/types')
|
||||
api.add_resource(DeviceConfigurationResource,
|
||||
'/v1/devices/<int:device_id>/configuration')
|
||||
|
||||
|
||||
add_resources()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from marshmallow import Schema, fields
|
||||
from webargs.flaskparser import use_args
|
||||
from flasgger import swag_from
|
||||
from flask import g
|
||||
from flask import g, request
|
||||
import app.devices as devices
|
||||
from app.api import ProtectedResource
|
||||
|
||||
|
@ -106,3 +106,15 @@ class DeviceListResource(ProtectedResource):
|
|||
def get(self):
|
||||
return DevicesWrapperSchema().dump(
|
||||
{'devices': devices.get_devices(g.current_account.id)}), 200
|
||||
|
||||
|
||||
class DeviceConfigurationResource(ProtectedResource):
|
||||
@swag_from('swagger/update_device_configuration_spec.yaml')
|
||||
def put(self, device_id):
|
||||
success = devices.set_device_configuration(device_id, request.json)
|
||||
if success:
|
||||
return '', 204
|
||||
|
||||
@swag_from('swagger/get_device_configuration_spec.yaml')
|
||||
def get(self, device_id):
|
||||
return devices.get_device_configuration(device_id), 200
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
Gets a device configuration
|
||||
---
|
||||
tags:
|
||||
- Device
|
||||
- Configuration
|
||||
parameters:
|
||||
- in: path
|
||||
name: device_id
|
||||
required: true
|
||||
type: integer
|
||||
description: Id of the device
|
||||
responses:
|
||||
200:
|
||||
description: Success
|
||||
schema:
|
||||
type: object
|
|
@ -0,0 +1,19 @@
|
|||
Updates a device configuration
|
||||
---
|
||||
tags:
|
||||
- Device
|
||||
- Configuration
|
||||
parameters:
|
||||
- in: path
|
||||
name: device_id
|
||||
required: true
|
||||
type: integer
|
||||
description: Id of the device
|
||||
- in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
type: object
|
||||
responses:
|
||||
204:
|
||||
description: Success
|
|
@ -38,6 +38,33 @@ def create_device_type(name):
|
|||
device_type.save()
|
||||
|
||||
|
||||
def set_device_configuration(device_id, configuration_json):
|
||||
"""
|
||||
Tries to update configuration of device with given id
|
||||
|
||||
:param device_id: Id of device to change configuration
|
||||
:param configuration_json: New configuration
|
||||
:type device_id: int
|
||||
:type configuration_json: JSON
|
||||
:rtype: Boolean
|
||||
"""
|
||||
device = Device.get(id=device_id)
|
||||
device.configuration = configuration_json
|
||||
device.save()
|
||||
|
||||
|
||||
def get_device_configuration(device_id):
|
||||
"""
|
||||
Tries to get configuration for device with given parameters.
|
||||
|
||||
:param device_id: Id of device
|
||||
:type device_id: int
|
||||
:returns: Configuration of given device
|
||||
:rtype: JSON Configuration
|
||||
"""
|
||||
return Device.get(id=device_id).configuration
|
||||
|
||||
|
||||
def get_device_recordings(device_id):
|
||||
"""
|
||||
Tries to get device recording for device with given parameters. Raises
|
||||
|
|
Loading…
Reference in New Issue