mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-11 09:27:56 -04:00
fix schema and primary key
* version is an additional primary key so we need to indicate that * schema no longer relies on Template model, and uses nested user
This commit is contained in:
@@ -249,7 +249,7 @@ class TemplateHistory(db.Model):
|
||||
subject = db.Column(db.Text)
|
||||
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
|
||||
created_by = db.relationship('User')
|
||||
version = db.Column(db.Integer)
|
||||
version = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
|
||||
MMG_PROVIDER = "mmg"
|
||||
|
||||
@@ -172,17 +172,11 @@ class TemplateSchema(BaseTemplateSchema):
|
||||
|
||||
class TemplateHistorySchema(BaseSchema):
|
||||
|
||||
class Meta:
|
||||
# Use the base model class that the history class is created from
|
||||
model = models.Template
|
||||
# We have to use a method here because the relationship field on the
|
||||
# history object is not created.
|
||||
created_by = fields.Method("populate_created_by", dump_only=True)
|
||||
created_by = fields.Nested(UserSchema, only=['id', 'name', 'email_address'], dump_only=True)
|
||||
created_at = field_for(models.Template, 'created_at', format='%Y-%m-%d %H:%M:%S.%f')
|
||||
|
||||
def populate_created_by(self, data):
|
||||
usr = models.User.query.filter_by(id=data.created_by_id).one()
|
||||
return {'id': str(usr.id), 'name': usr.name, 'email_address': usr.email_address}
|
||||
class Meta:
|
||||
model = models.TemplateHistory
|
||||
|
||||
|
||||
class NotificationsStatisticsSchema(BaseSchema):
|
||||
|
||||
@@ -176,7 +176,7 @@ def get_service_provider_aggregate_statistics(service_id):
|
||||
# tables. This is so product owner can pass stories as done
|
||||
@service.route('/<uuid:service_id>/history', methods=['GET'])
|
||||
def get_service_history(service_id):
|
||||
from app.models import (Service, ApiKey, Template, Event)
|
||||
from app.models import (Service, ApiKey, Template, TemplateHistory, Event)
|
||||
from app.schemas import (
|
||||
service_history_schema,
|
||||
api_key_history_schema,
|
||||
|
||||
Reference in New Issue
Block a user