diff --git a/model_service/model/__init__.py b/model_service/model/__init__.py index a1ba3ea..ada7b03 100644 --- a/model_service/model/__init__.py +++ b/model_service/model/__init__.py @@ -1,2 +1,4 @@ #!/usr/bin/env python3 from .db import db +from .default import Default +from .details import Details \ No newline at end of file diff --git a/model_service/model/default.py b/model_service/model/default.py new file mode 100644 index 0000000..61faea1 --- /dev/null +++ b/model_service/model/default.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +from .db import db + + +class Default(db.Model): + default_id = db.Column(db.Integer, db.ForeignKey("details.id"), nullable=False) + default = db.relationship("Details") \ No newline at end of file diff --git a/model_service/model/details.py b/model_service/model/details.py new file mode 100644 index 0000000..00a0b63 --- /dev/null +++ b/model_service/model/details.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +from .db import db +from sqlalchemy.sql import func + + +class Details(db.Model): + id = db.Column(db.Integer, primary_key=True, auto_increment=True) + name = db.Column(db.String(30), key=True) + timestamp = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now()) + + mid_window = db.Column(db.Float) + mid_step = db.Column(db.Float) + short_window = db.Column(db.Float) + short_step = db.Column(db.Float) + compute_beat = db.Column(db.Float) + type = db.Column(db.String(15)) \ No newline at end of file diff --git a/model_service/schemas/__init__.py b/model_service/schemas/__init__.py index 63f77b6..6cf4bf9 100644 --- a/model_service/schemas/__init__.py +++ b/model_service/schemas/__init__.py @@ -1,2 +1,3 @@ #!/usr/bin/env python3 - +from .default_schema import DefaultSchema +from .details_schema import DetailsSchema diff --git a/model_service/schemas/default_schema.py b/model_service/schemas/default_schema.py new file mode 100644 index 0000000..827fef6 --- /dev/null +++ b/model_service/schemas/default_schema.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +from marshmallow import fields +from marshmallow_sqlalchemy import ModelSchema +from model import Default + + +class DefaultSchema(ModelSchema): + class Meta: + model = Default diff --git a/model_service/schemas/details_schema.py b/model_service/schemas/details_schema.py new file mode 100644 index 0000000..cfc9f68 --- /dev/null +++ b/model_service/schemas/details_schema.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +from marshmallow import fields +from marshmallow_sqlalchemy import ModelSchema +from model import Details + + +class DetailsSchema(ModelSchema): + class Meta: + model = Details diff --git a/model_service/views/model_view.py b/model_service/views/model_view.py index 7628171..827f19b 100644 --- a/model_service/views/model_view.py +++ b/model_service/views/model_view.py @@ -1,14 +1,17 @@ #!/usr/bin/env python3 from flask import request, jsonify from flask_classful import FlaskView, route -from model import db +from model import db, Default, Details +from schema import DetailsSchema, DefaultSchema from utils import json_required -import requests.exceptions - class ModelView(FlaskView): + details_schema = DetailsSchema(many=False) + default_schema = DefaultSchema(many=False) + + @json_required def post(self): return jsonify({}) @@ -22,6 +25,15 @@ class ModelView(FlaskView): def delete(self, _id: str): return jsonify({"id": _id}) + @json_required @route('$default', methods=['PUT']) def put_default(self): - return jsonify({}) + + Default.query.delete() + #new_default = Default() + + + db.session.add(new_default) + db.session.commit() + + return jsonify(self.default_schema.dump(new_default))