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
properties:
device:
$ref: '#/definitions/Device'
$ref: '#/definitions/DeviceCreation'
responses:
201:
description: Successful creation

View File

@ -2,6 +2,21 @@ Gets all device types
---
tags:
- 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:
200:
description: Success

View File

@ -2,6 +2,21 @@ Gets all associated devices
---
tags:
- 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:
200:
description: Success
@ -14,4 +29,3 @@ responses:
type: array
items:
$ref: '#/definitions/Device'

View File

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

View File

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