Commit 8b8ab285 authored by Zach Perkins's avatar Zach Perkins

added some basic argument validation to spice things up

parent 8f3ce9f1
from flask import Flask, redirect, jsonify, abort, request, url_for, make_response
from webargs.flaskparser import use_args
from webargs import fields
from where.model import with_session, Point, Category, Field
from where.model.field_types import FieldType
......@@ -7,7 +9,6 @@ from where.validation import PointSchema, CategorySchema, FieldSchema
app = Flask(__name__)
# Endpoints:
......@@ -112,24 +113,25 @@ def get_category(session, id):
@app.route('/category/<id>/children')
@with_session
def get_category_children(session, id):
def get_category_children(data, session, id):
data = dict(request.args)
data['parent_id'] = id
return search_resource(session, Point, data)
@app.route('/point', methods=['GET'])
@use_args({'parent_id': fields.Int(), 'category_id': fields.Int(required=True)})
@with_session
def search_point(session):
return search_resource(session, Point, dict(request.args))
def search_point(session, args):
return search_resource(session, Point, args)
@app.route('/point', methods=['POST'])
def create_point(session):
data = request.get_json()
data['category'] = session.query(Category).get(data.pop('category_id'))
return create_resource(session, Point, data, 'get_point')
@use_args(PointSchema)
@with_session
def create_point(session, args):
args['category'] = session.query(Category).get(args.pop('category_id'))
return create_resource(session, Point, args, 'get_point')
@app.route('/point/<id>', methods=['GET'])
......
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema, auto_field
from .model import Point, Category, Field
class PointSchema(SQLAlchemyAutoSchema):
class Meta:
model = Point
include_relationships = True
load_instance = True
include_fk = True
include_relationships = False
load_instance = False
class CategorySchema(SQLAlchemyAutoSchema):
class Meta:
model = Category
include_relationships = True
load_instance = True
include_relationships = False
load_instance = False
class FieldSchema(SQLAlchemyAutoSchema):
class Meta:
model = Field
include_relationships = True
load_instance = True
\ No newline at end of file
include_relationships = False
load_instance = False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment