Compare commits
No commits in common. "f65ed288222da0bd6d524fbc22d0e686c05de6f9" and "e1fcfe670f4fa1b2dd8ccf31fe82401ff5bee2d1" have entirely different histories.
f65ed28822
...
e1fcfe670f
@ -9,6 +9,4 @@ flask_sqlalchemy
|
|||||||
xeger
|
xeger
|
||||||
pika
|
pika
|
||||||
psycopg2-binary
|
psycopg2-binary
|
||||||
marshmallow
|
marshmallow
|
||||||
marshmallow-sqlalchemy
|
|
||||||
flask-marshmallow
|
|
@ -8,7 +8,6 @@ from sentry_sdk.integrations.flask import FlaskIntegration
|
|||||||
import rabbitmqqueue
|
import rabbitmqqueue
|
||||||
from config import *
|
from config import *
|
||||||
from db import db
|
from db import db
|
||||||
from marshm import ma
|
|
||||||
from resources import SampleResource, SampleParameterResource
|
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}"
|
app.config['SQLALCHEMY_DATABASE_URI'] = f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}"
|
||||||
api = Api(app)
|
api = Api(app)
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
ma.init_app(app)
|
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
@ -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()
|
|
@ -8,7 +8,7 @@ import requests
|
|||||||
from db import db
|
from db import db
|
||||||
from models import SampleMetadata
|
from models import SampleMetadata
|
||||||
from rabbitmqqueue import rabbitmq_channel
|
from rabbitmqqueue import rabbitmq_channel
|
||||||
from schemas import SampleSchema, SampleMetadataSchema
|
from schemas import SampleSchema
|
||||||
from config import *
|
from config import *
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -29,9 +29,6 @@ class SampleResource(Resource):
|
|||||||
See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service
|
See: https://swagger.kmlabz.com/?urls.primaryName=Input%20Service
|
||||||
"""
|
"""
|
||||||
|
|
||||||
sampleschema = SampleSchema(many=False)
|
|
||||||
samplemetadataschema = SampleMetadataSchema(many=True)
|
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
"""
|
"""
|
||||||
Post request send to the endpoint
|
Post request send to the endpoint
|
||||||
@ -53,9 +50,15 @@ class SampleResource(Resource):
|
|||||||
return {'err_msg': 'Input file not a wave file.'}, 415
|
return {'err_msg': 'Input file not a wave file.'}, 415
|
||||||
|
|
||||||
try:
|
try:
|
||||||
desc = self.sampleschema.loads(description)
|
desc = json.loads(description)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.exception(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
|
return {'err_msg': 'Input JSON schema invalid'}, 417
|
||||||
|
|
||||||
xeger = Xeger(limit=30)
|
xeger = Xeger(limit=30)
|
||||||
@ -94,7 +97,7 @@ class SampleResource(Resource):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
samples = SampleMetadata.query.all()
|
samples = SampleMetadata.query.all()
|
||||||
return self.samplemetadataschema.dumps(list(samples)), 200
|
return list(samples), 200
|
||||||
|
|
||||||
|
|
||||||
class SampleParameterResource(Resource):
|
class SampleParameterResource(Resource):
|
||||||
@ -102,8 +105,6 @@ class SampleParameterResource(Resource):
|
|||||||
Sample endpoint with parameters
|
Sample endpoint with parameters
|
||||||
"""
|
"""
|
||||||
|
|
||||||
samplemetadataschema = SampleMetadataSchema(many=False)
|
|
||||||
|
|
||||||
def get(self, tag: str):
|
def get(self, tag: str):
|
||||||
"""
|
"""
|
||||||
Get a specific item
|
Get a specific item
|
||||||
@ -111,4 +112,4 @@ class SampleParameterResource(Resource):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
sample = SampleMetadata.query.filter_by(tag=tag).first_or_404()
|
sample = SampleMetadata.query.filter_by(tag=tag).first_or_404()
|
||||||
return self.samplemetadataschema.dumps(sample), 200
|
return sample, 200
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from models import SampleMetadata
|
from marshmallow import Schema, fields
|
||||||
from marshm import ma
|
|
||||||
from marshmallow import fields
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -15,21 +13,12 @@ __module_name__ = "schemas"
|
|||||||
__version__text__ = "1"
|
__version__text__ = "1"
|
||||||
|
|
||||||
|
|
||||||
class SampleSchema(ma.Schema):
|
class SampleSchema(Schema):
|
||||||
"""
|
"""
|
||||||
Parameters:
|
Parameters:
|
||||||
- date (date)
|
- date (date)
|
||||||
- device_id (str)
|
- device_id (str)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
date = fields.DateTime(required=True)
|
date = fields.Date(required=True)
|
||||||
device_id = fields.Str(required=True)
|
device_id = fields.Str(required=True)
|
||||||
|
|
||||||
|
|
||||||
class SampleMetadataSchema(ma.SQLAlchemyAutoSchema):
|
|
||||||
"""
|
|
||||||
Marshmallow schema generated
|
|
||||||
"""
|
|
||||||
class Meta:
|
|
||||||
model = SampleMetadata
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user