add get endpoints
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-03-31 15:10:58 +02:00
parent 355ea26621
commit fefbb63f67
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
3 changed files with 29 additions and 4 deletions

View File

@ -9,4 +9,4 @@ filetype
sqlalchemy
flask_sqlalchemy
rstr
pike
pika

View File

@ -7,7 +7,7 @@ from sentry_sdk.integrations.flask import FlaskIntegration
import pika
from config import *
import db
from db import db
from resources import *
"""
@ -53,6 +53,7 @@ logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
api.add_resource(SampleResource, "/v1/input/sample")
api.add_resource(SampleParameterResource, '/v1/input/sample<str:tag>')
if __name__ == "__main__":
app.run(

View File

@ -7,7 +7,7 @@ from flask_restful import Resource, reqparse
from werkzeug.datastructures import FileStorage
import requests
import filetype
import db
from db import db
from models import SampleMetadata
from schemas import *
from config import *
@ -23,6 +23,7 @@ __version__text__ = "1"
LOGGER = logging.getLogger(__name__)
class SampleResource(Resource):
"""
Sample endpoint
@ -67,7 +68,7 @@ class SampleResource(Resource):
try:
db.session.add(record)
requests.post(
f"http://{STORAGE_HOSTNAME}/object",
f"http://{STORAGE_HOSTNAME}/v1/storage/object",
files={
'tag': (None, generated_tag),
'file': (
@ -86,3 +87,26 @@ class SampleResource(Resource):
db.session.commit()
return {"status": "ok", "message": generated_tag}, 200
def get(self):
"""
Get all stored items
:return:
"""
samples = SampleMetadata.query.get.all()
return {"status": "ok", "message": samples}, 200
class SampleParameterResource(Resource):
"""
Sample endpoint with parameters
"""
def get(self, tag: str):
"""
Get a specific item
:param tag:
:return:
"""
sample = SampleMetadata.query.filter_by(tag=tag).first_or_404()
return {"status": "ok", "message": sample}, 200