Commit 8f3ce9f1 authored by Zach Perkins's avatar Zach Perkins
Browse files

split endpoint view functions based on request method

parent 86f6d008
......@@ -3,6 +3,8 @@ from flask import Flask, redirect, jsonify, abort, request, url_for, make_respon
from where.model import with_session, Point, Category, Field
from where.model.field_types import FieldType
from where.validation import PointSchema, CategorySchema, FieldSchema
app = Flask(__name__)
......@@ -116,26 +118,35 @@ def get_category_children(session, id):
return search_resource(session, Point, data)
@app.route('/point', methods=['GET', 'POST'])
@app.route('/point', methods=['GET'])
def handle_point(session):
if request.method == 'GET':
def search_point(session):
return search_resource(session, Point, dict(request.args))
elif request.method == 'POST':
@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')
@app.route('/point/<id>', methods=['GET', 'PUT', 'DELETE'])
@app.route('/point/<id>', methods=['GET'])
def get_point(session, id):
if request.method == 'GET':
return get_resource(session, Point, id)
elif request.method == 'DELETE':
@app.route('/point/<id>', methods=['DELETE'])
def del_point(session, id):
return delete_resource(session, Point, id)
elif request.method == 'PUT':
@app.route('/point/<id>', methods=['PUT'])
def edit_point(session, id):
return edit_resource(session, Point, id, request.get_json())
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