Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

Adiciona endpoint para publicar datasets #45

Merged
merged 19 commits into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6f4c643
Adiciona modelo do metadata com validação
lucasaarcoverde Sep 6, 2019
cb19fdf
Adiciona dependencias no Pipfile
lucasaarcoverde Sep 6, 2019
5603c53
Adiciona tratamento de erro de validação
lucasaarcoverde Sep 6, 2019
8d4ff10
Adiciona rota de publish
lucasaarcoverde Sep 6, 2019
12b08b1
Adiciona espaços depois de virgulas
JoseRenan Sep 6, 2019
e4d28a8
Adiciona http status 201 no retorno ao criar o DatasetMetadata
lucasaarcoverde Sep 7, 2019
6c2e6a3
Padroniza a rota com o REST
lucasaarcoverde Sep 7, 2019
6cbdc98
Ajusta nome da função para pegar datasets
lucasaarcoverde Sep 7, 2019
cf4e010
Ajusta nome da classe MetadataSchema para DatasetMetadataSchema
lucasaarcoverde Sep 7, 2019
f20fa14
Ajusta identação para padronizar com o PEP8
lucasaarcoverde Sep 7, 2019
f60a82e
Agora DatasetMetadataSchema é um singleton, para não precisar instanc…
lucasaarcoverde Sep 7, 2019
4d61e2b
Move função de retorno de mensagen de erro para outro arquivo, para q…
lucasaarcoverde Sep 7, 2019
e252f11
Remove espaços em branco do metadata.py (pylint)
lucasmedeiros Sep 7, 2019
04998a1
Remove import não utilizado (pprint)
lucasmedeiros Sep 7, 2019
b8f50e4
Padroniza uma forma de parse pra JSON usando schema
lucasaarcoverde Sep 7, 2019
2f6b0a4
Move função de retorno de mensagen de erro para outro arquivo, pa…
lucasaarcoverde Sep 7, 2019
7494dc1
Remove import não utilizado (pprint)
lucasaarcoverde Sep 7, 2019
968a54d
Remove identação extra
JoseRenan Sep 8, 2019
aa2d98d
Adiciona trailing line
JoseRenan Sep 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pylint = "*"

[packages]
flask = "*"
marshmallow = "*"

[requires]
python_version = "3"
Expand Down
7 changes: 6 additions & 1 deletion laguinho/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from flask import Flask
from .errors.handlers import errors
from .routes.datasets import datasets

def create_app(config_filename=None):
app = Flask(__name__)


app.register_blueprint(errors)
app.register_blueprint(datasets)

@app.route('/')
def hello_world():
return 'Laguinho API is up and running.'
Expand Down
Empty file added laguinho/errors/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions laguinho/errors/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Blueprint, jsonify
from marshmallow import ValidationError

errors = Blueprint('errors', __name__)

@errors.app_errorhandler(ValidationError)
def handle_validation_error(e):
return jsonify(e.messages), 422
9 changes: 9 additions & 0 deletions laguinho/models/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from marshmallow import Schema, fields, pprint, validate

class MetadataSchema(Schema):
JoseRenan marked this conversation as resolved.
Show resolved Hide resolved
name = fields.Str(required=True, error_messages={"required": {"message": "Name is required."}})
JoseRenan marked this conversation as resolved.
Show resolved Hide resolved
url = fields.Str(required=True, error_messages={"required": {"message": "URL is required."}})
path = fields.Str(required=True, error_messages={"required": {"message": "Path is required."}})
maintainers = fields.List(fields.Str())
format = fields.Str(validate=validate.OneOf(["json", "csv"]), required=True, error_messages={"required": {"message": "Format is required."}})
JoseRenan marked this conversation as resolved.
Show resolved Hide resolved
contributable = fields.Bool()
Empty file added laguinho/routes/__inity__.py
Empty file.
17 changes: 17 additions & 0 deletions laguinho/routes/datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from flask import Blueprint, request, jsonify
from laguinho.models.metadata import MetadataSchema
from marshmallow import ValidationError, EXCLUDE

datasets = Blueprint('datasets', __name__, url_prefix="/datasets")
metadata = []

@datasets.route("/publish", methods=['POST'])
JoseRenan marked this conversation as resolved.
Show resolved Hide resolved
def publish():
schema = MetadataSchema()
result = schema.load(request.json, unknown=EXCLUDE)
metadata.append(result)
return result
JoseRenan marked this conversation as resolved.
Show resolved Hide resolved

@datasets.route("/metadata", methods=['GET'])
def get_metadata():
JoseRenan marked this conversation as resolved.
Show resolved Hide resolved
return jsonify(metadata)
JoseRenan marked this conversation as resolved.
Show resolved Hide resolved