mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-02 17:48:36 -04:00
Template history endpoint added. All tests passing.
Code quality fix.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from datetime import date
|
||||
from flask_marshmallow.fields import fields
|
||||
from sqlalchemy.orm import load_only
|
||||
|
||||
from marshmallow import (
|
||||
post_load,
|
||||
@@ -93,6 +94,11 @@ class BaseTemplateSchema(BaseSchema):
|
||||
class TemplateSchema(BaseTemplateSchema):
|
||||
|
||||
created_by = field_for(models.Template, 'created_by', required=True)
|
||||
versions = fields.Method("template_versions", dump_only=True)
|
||||
|
||||
def template_versions(self, template):
|
||||
return [x.version for x in models.Template.get_history_model().query.filter_by(
|
||||
id=template.id).options(load_only("version"))]
|
||||
|
||||
@validates_schema
|
||||
def validate_type(self, data):
|
||||
@@ -103,6 +109,11 @@ class TemplateSchema(BaseTemplateSchema):
|
||||
raise ValidationError('Invalid template subject', 'subject')
|
||||
|
||||
|
||||
class TemplateHistorySchema(BaseTemplateSchema):
|
||||
|
||||
created_by = field_for(models.Template, 'created_by', required=True)
|
||||
|
||||
|
||||
class NotificationsStatisticsSchema(BaseSchema):
|
||||
class Meta:
|
||||
model = models.NotificationStatistics
|
||||
@@ -302,18 +313,6 @@ class ApiKeyHistorySchema(ma.Schema):
|
||||
created_by_id = fields.UUID()
|
||||
|
||||
|
||||
class TemplateHistorySchema(ma.Schema):
|
||||
id = fields.UUID()
|
||||
name = fields.String()
|
||||
template_type = fields.String()
|
||||
created_at = fields.DateTime()
|
||||
updated_at = fields.DateTime()
|
||||
content = fields.String()
|
||||
service_id = fields.UUID()
|
||||
subject = fields.String()
|
||||
created_by_id = fields.UUID()
|
||||
|
||||
|
||||
class EventSchema(BaseSchema):
|
||||
class Meta:
|
||||
model = models.Event
|
||||
|
||||
Reference in New Issue
Block a user