Add pagination and update swagger

master
esensar 2018-09-19 23:04:49 +02:00
parent fefa8dbf77
commit c14b3a8bed
5 changed files with 47 additions and 5 deletions

View File

@ -13,7 +13,7 @@ parameters:
- device - device
properties: properties:
device: device:
$ref: '#/definitions/Device' $ref: '#/definitions/DeviceCreation'
responses: responses:
201: 201:
description: Successful creation description: Successful creation

View File

@ -2,6 +2,21 @@ Gets all device types
--- ---
tags: tags:
- DeviceType - DeviceType
parameters:
- in: path
name: page
required: false
schema:
type: integer
minimum: 1
description: requested page
- in: path
name: per_page
required: false
schema:
type: integer
minimum: 1
description: requested items per page
responses: responses:
200: 200:
description: Success description: Success

View File

@ -2,6 +2,21 @@ Gets all associated devices
--- ---
tags: tags:
- Device - Device
parameters:
- in: path
name: page
required: false
schema:
type: integer
minimum: 1
description: requested page
- in: path
name: per_page
required: false
schema:
type: integer
minimum: 1
description: requested items per page
responses: responses:
200: 200:
description: Success description: Success
@ -14,4 +29,3 @@ responses:
type: array type: array
items: items:
$ref: '#/definitions/Device' $ref: '#/definitions/Device'

View File

@ -138,7 +138,8 @@ class Device(db.Model):
* configuration (useless) * configuration (useless)
""" """
return Device.query.filter_by(**kwargs).all() return Device.query.filter_by(**kwargs).paginate(
None, None, False).items
@staticmethod @staticmethod
def get_many_for_user(account_id): def get_many_for_user(account_id):
@ -147,7 +148,7 @@ class Device(db.Model):
""" """
return Device.query.filter( return Device.query.filter(
Device.users.any(account_id=account_id) Device.users.any(account_id=account_id)
).all() ).paginate(None, None, False).items
@staticmethod @staticmethod
def get(**kwargs): def get(**kwargs):
@ -260,7 +261,8 @@ class DeviceType(db.Model):
* id * id
* name * name
""" """
return DeviceType.query.filter_by(**kwargs).all() return DeviceType.query.filter_by(**kwargs).paginate(
None, None, False).items
@staticmethod @staticmethod
def get(**kwargs): def get(**kwargs):

View File

@ -122,6 +122,17 @@ definitions:
device_type: device_type:
$ref: '#/definitions/DeviceType' $ref: '#/definitions/DeviceType'
DeviceCreation:
type: object
required:
- name
- device_type_id
properties:
name:
$ref: '#/definitions/devicename'
device_type_id:
$ref: '#/definitions/id'
UnauthorizedError: UnauthorizedError:
type: object type: object
required: required: