This commit is contained in:
parent
7d7227aa47
commit
4d1de2a1f6
@ -5,4 +5,6 @@ Flask
|
||||
Flask-RESTful
|
||||
requests
|
||||
werkzeug
|
||||
filetype
|
||||
filetype
|
||||
sqlalchemy
|
||||
flask_sqlalchemy
|
@ -6,6 +6,7 @@ from flask_restful import Api
|
||||
from sentry_sdk.integrations.flask import FlaskIntegration
|
||||
|
||||
from config import SENTRY_DSN, RELEASE_ID, RELEASEMODE, PORT, DEBUG
|
||||
import db
|
||||
from resources import *
|
||||
|
||||
"""
|
||||
@ -28,6 +29,10 @@ if SENTRY_DSN:
|
||||
|
||||
app = Flask(__name__)
|
||||
api = Api(app)
|
||||
db.init_app(app)
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
formatter = logging.Formatter(
|
||||
fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s"
|
||||
|
13
src/db.py
Normal file
13
src/db.py
Normal file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
"""
|
||||
Flask Restful endpoints
|
||||
"""
|
||||
|
||||
__author__ = '@tormakris'
|
||||
__copyright__ = "Copyright 2020, Birbnetes Team"
|
||||
__module_name__ = "db"
|
||||
__version__text__ = "1"
|
||||
|
||||
db = SQLAlchemy()
|
25
src/models.py
Normal file
25
src/models.py
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
import db
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
"""
|
||||
Flask Restful endpoints
|
||||
"""
|
||||
|
||||
__author__ = '@tormakris'
|
||||
__copyright__ = "Copyright 2020, Birbnetes Team"
|
||||
__module_name__ = "models"
|
||||
__version__text__ = "1"
|
||||
|
||||
|
||||
class SampleMetadata(db.Model):
|
||||
"""
|
||||
SQLAlchemy model of metadata entries
|
||||
"""
|
||||
id = db.Column(db.Integer, primary_key=True, auto_increment=True)
|
||||
timestamp = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now())
|
||||
|
||||
device_id = db.Column(db.String, nullable=False)
|
||||
device_date = db.Column(db.DateTime, nullable=False)
|
||||
|
||||
tag = db.Column(db.String, nullable=False)
|
@ -5,6 +5,8 @@ from flask import request
|
||||
from flask_restful import Resource, reqparse
|
||||
from werkzeug.datastructures import FileStorage
|
||||
import filetype
|
||||
import db
|
||||
from models import SampleMetadata
|
||||
from schemas import *
|
||||
|
||||
"""
|
||||
@ -54,3 +56,6 @@ class SampleResource(Resource):
|
||||
"Input JSON did not conform to schema. It was: {}", desc)
|
||||
return {'status': 'error',
|
||||
'message': 'Input JSON schema invalid'}, 417
|
||||
# TODO: Preserve input data in relational DB
|
||||
# TODO: Pass data and tag to ObjectStorage
|
||||
# TODO: Pass tag to MQ
|
||||
|
Loading…
Reference in New Issue
Block a user