Add created_at and modified_at timestamps to all responses
parent
30666f2fe3
commit
79cbd09f24
|
@ -9,11 +9,11 @@ from app.accounts.tasks import send_email_task
|
|||
from app.api.auth_protection import ProtectedResource
|
||||
from app.api.permission_protection import (requires_permission,
|
||||
valid_permissions)
|
||||
from app.api.schemas import BaseResourceSchema
|
||||
from app.api.schemas import BaseTimestampedResourceSchema
|
||||
from flask import current_app as app
|
||||
|
||||
|
||||
class UserSchema(BaseResourceSchema):
|
||||
class UserSchema(BaseTimestampedResourceSchema):
|
||||
username = fields.Str(required=True)
|
||||
email = fields.Email(required=True)
|
||||
password = fields.Str(required=True, load_only=True)
|
||||
|
@ -27,7 +27,7 @@ def validate_role_permissions(permissions_list):
|
|||
return set(permissions_list).issubset(valid_permissions)
|
||||
|
||||
|
||||
class RoleSchema(BaseResourceSchema):
|
||||
class RoleSchema(BaseTimestampedResourceSchema):
|
||||
id = fields.Integer(required=True, location='json')
|
||||
display_name = fields.String(required=True, location='json')
|
||||
permissions = fields.List(fields.String, required=True,
|
||||
|
|
|
@ -6,10 +6,12 @@ from flasgger import swag_from
|
|||
import app.dashboards.api as dashboard
|
||||
import app.devices.api as device
|
||||
from app.api.auth_protection import ProtectedResource
|
||||
from app.api.schemas import BaseResourceSchema
|
||||
from app.api.schemas import (BaseResourceSchema,
|
||||
BaseTimestampedSchema,
|
||||
BaseTimestampedResourceSchema)
|
||||
|
||||
|
||||
class BasicDashboardWidgetSchema(Schema):
|
||||
class BasicDashboardWidgetSchema(BaseTimestampedSchema):
|
||||
id = fields.Integer(dump_only=True)
|
||||
device_id = fields.Integer(required=True)
|
||||
name = fields.String(required=True)
|
||||
|
@ -25,7 +27,7 @@ class DashboardWidgetSchema(BaseResourceSchema, BasicDashboardWidgetSchema):
|
|||
pass
|
||||
|
||||
|
||||
class DashboardSchema(BaseResourceSchema):
|
||||
class DashboardSchema(BaseTimestampedResourceSchema):
|
||||
id = fields.Integer(dump_only=True)
|
||||
active = fields.Boolean(required=False)
|
||||
dashboard_data = fields.Raw(required=True)
|
||||
|
|
|
@ -6,11 +6,13 @@ from flask import g, request, redirect
|
|||
from app.api.blueprint import api
|
||||
import app.devices.api as devices
|
||||
from app.api.auth_protection import ProtectedResource
|
||||
from app.api.schemas import BaseResourceSchema
|
||||
from app.api.schemas import (BaseResourceSchema,
|
||||
BaseTimestampedSchema,
|
||||
BaseTimestampedResourceSchema)
|
||||
from flask import current_app as app
|
||||
|
||||
|
||||
class BasicDeviceTypeSchema(Schema):
|
||||
class BasicDeviceTypeSchema(BaseTimestampedSchema):
|
||||
id = fields.Integer(dump_only=True)
|
||||
name = fields.Str(required=True)
|
||||
|
||||
|
@ -19,13 +21,11 @@ class DeviceTypeSchema(BaseResourceSchema, BasicDeviceTypeSchema):
|
|||
pass
|
||||
|
||||
|
||||
class DeviceSchema(BaseResourceSchema):
|
||||
class DeviceSchema(BaseTimestampedResourceSchema):
|
||||
id = fields.Integer(dump_only=True)
|
||||
name = fields.Str(required=True)
|
||||
device_type = fields.Nested(BasicDeviceTypeSchema, dump_only=True)
|
||||
device_type_id = fields.Integer(load_only=True, missing=1)
|
||||
created_at = fields.DateTime(dump_only=True)
|
||||
modified_at = fields.DateTime(dump_only=True)
|
||||
|
||||
|
||||
class DeviceWithConfigurationSchema(DeviceSchema):
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
from marshmallow import Schema, post_dump
|
||||
from marshmallow import Schema, post_dump, fields
|
||||
|
||||
|
||||
class BaseResourceSchema(Schema):
|
||||
@post_dump(pass_many=True)
|
||||
def wrap_with_envelope(self, data, many):
|
||||
return {'content': data}
|
||||
|
||||
|
||||
class BaseTimestampedSchema(Schema):
|
||||
created_at = fields.DateTime(dump_only=True)
|
||||
modified_at = fields.DateTime(dump_only=True)
|
||||
|
||||
|
||||
class BaseTimestampedResourceSchema(BaseResourceSchema, BaseTimestampedSchema):
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue