diff --git a/model_service/schemas/default_schema.py b/model_service/schemas/default_schema.py index 827fef6..09277d1 100644 --- a/model_service/schemas/default_schema.py +++ b/model_service/schemas/default_schema.py @@ -1,9 +1,7 @@ #!/usr/bin/env python3 from marshmallow import fields from marshmallow_sqlalchemy import ModelSchema -from model import Default class DefaultSchema(ModelSchema): - class Meta: - model = Default + id = fields.UUID() diff --git a/model_service/views/model_view.py b/model_service/views/model_view.py index a8ba4c7..1e63a7f 100644 --- a/model_service/views/model_view.py +++ b/model_service/views/model_view.py @@ -5,6 +5,7 @@ from flask_classful import FlaskView, route from model import db, Default, AIModel from minio.error import BucketAlreadyExists, BucketAlreadyOwnedByYou, ResponseError, NoSuchKey from schemas import AIModelSchema, DefaultSchema +from marshmallow.exceptions import ValidationError from utils import json_required, storage @@ -56,4 +57,17 @@ class ModelView(FlaskView): @json_required @route('$default', methods=['PUT']) def put_default(self): - return jsonify({}) + + try: + req = self.default_schema.load(request.json()) + except ValidationError as e: + abort(404, str(e)) + + m = AIModel.query.fiter_by(id=req['id']).first_or_404() + + Default.query.delete() + new_default = Default(m) + db.session.add(new_default) + db.session.commit() + + return jsonify(self.aimodel_schema.dump(m))