Compare commits

..

No commits in common. "f65ed288222da0bd6d524fbc22d0e686c05de6f9" and "e1fcfe670f4fa1b2dd8ccf31fe82401ff5bee2d1" have entirely different histories.

5 changed files with 14 additions and 42 deletions

View File

@ -9,6 +9,4 @@ flask_sqlalchemy
xeger
pika
psycopg2-binary
marshmallow
marshmallow-sqlalchemy
flask-marshmallow
marshmallow

View File

@ -8,7 +8,6 @@ from sentry_sdk.integrations.flask import FlaskIntegration
import rabbitmqqueue
from config import *
from db import db
from marshm import ma
from resources import SampleResource, SampleParameterResource
"""
@ -34,7 +33,6 @@ app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}"
api = Api(app)
db.init_app(app)
ma.init_app(app)
with app.app_context():
db.create_all()

View File

@ -1,14 +0,0 @@
#!/usr/bin/env python3
from flask_marshmallow import Marshmallow
"""
Marshmallow
"""
__author__ = '@tormakris'
__copyright__ = "Copyright 2020, Birbnetes Team"
__module_name__ = "marshm"
__version__text__ = "1"
ma = Marshmallow()

View File

@ -8,7 +8,7 @@ import requests
from db import db
from models import SampleMetadata
from rabbitmqqueue import rabbitmq_channel
from schemas import SampleSchema, SampleMetadataSchema
from schemas import SampleSchema
from config import *
"""
@ -29,9 +29,6 @@ class SampleResource(Resource):
See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service
"""
sampleschema = SampleSchema(many=False)
samplemetadataschema = SampleMetadataSchema(many=True)
def post(self):
"""
Post request send to the endpoint
@ -53,9 +50,15 @@ class SampleResource(Resource):
return {'err_msg': 'Input file not a wave file.'}, 415
try:
desc = self.sampleschema.loads(description)
desc = json.loads(description)
except Exception as e:
LOGGER.exception(e)
return {'err_msg': 'Input JSON could not be parsed'}, 400
validate_errors = SampleSchema().validate(desc)
if validate_errors:
LOGGER.error(
"Input JSON did not conform to schema. It was: {}".format(desc))
return {'err_msg': 'Input JSON schema invalid'}, 417
xeger = Xeger(limit=30)
@ -94,7 +97,7 @@ class SampleResource(Resource):
:return:
"""
samples = SampleMetadata.query.all()
return self.samplemetadataschema.dumps(list(samples)), 200
return list(samples), 200
class SampleParameterResource(Resource):
@ -102,8 +105,6 @@ class SampleParameterResource(Resource):
Sample endpoint with parameters
"""
samplemetadataschema = SampleMetadataSchema(many=False)
def get(self, tag: str):
"""
Get a specific item
@ -111,4 +112,4 @@ class SampleParameterResource(Resource):
:return:
"""
sample = SampleMetadata.query.filter_by(tag=tag).first_or_404()
return self.samplemetadataschema.dumps(sample), 200
return sample, 200

View File

@ -1,7 +1,5 @@
#!/usr/bin/env python3
from models import SampleMetadata
from marshm import ma
from marshmallow import fields
from marshmallow import Schema, fields
"""
@ -15,21 +13,12 @@ __module_name__ = "schemas"
__version__text__ = "1"
class SampleSchema(ma.Schema):
class SampleSchema(Schema):
"""
Parameters:
- date (date)
- device_id (str)
"""
date = fields.DateTime(required=True)
date = fields.Date(required=True)
device_id = fields.Str(required=True)
class SampleMetadataSchema(ma.SQLAlchemyAutoSchema):
"""
Marshmallow schema generated
"""
class Meta:
model = SampleMetadata