validators are now decorators instead
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
from api import db, tasks
|
||||
from api.models import Designer
|
||||
from api.validators import validate_keys_exists
|
||||
from api.helpers import pagination_to_dict
|
||||
from api.validators import validate_jsonschema
|
||||
|
||||
|
||||
mod = Blueprint('designers', __name__, url_prefix='/designers')
|
||||
|
||||
create_designer_schema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"username": {"type": "string"},
|
||||
"name": {"type": "string"},
|
||||
"territory": {"type": "string"},
|
||||
"currency": {"type": "string"},
|
||||
},
|
||||
"required": ["username", "name", "territory", "currency"]
|
||||
}
|
||||
|
||||
|
||||
@mod.route("/", methods=["GET"])
|
||||
def list():
|
||||
@@ -22,9 +33,9 @@ def list():
|
||||
|
||||
|
||||
@mod.route("/", methods=["POST"])
|
||||
@validate_jsonschema(create_designer_schema)
|
||||
def create():
|
||||
data = request.json
|
||||
validate_keys_exists(data, 'username', 'name', 'territory', 'currency')
|
||||
designer = Designer(**data)
|
||||
db.session.add(designer)
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user