Commit 7a586ed5 authored by Zach Perkins's avatar Zach Perkins
Browse files

Changed these names back again

parent c4e6d25e
......@@ -15,6 +15,11 @@ def create_resource(session, model_cls, data, get_function):
return response
def get_resource(session, model_cls, id):
resource = session.query(model_cls).get(id)
return make_response(jsonify(resource.as_json()), 200)
def search_resource(session, model_cls, data):
query = session.query(model_cls).filter_by(**data)
results = list(map(lambda m: m.as_json(), query.limit(100).all()))
......@@ -118,11 +123,7 @@ def test_data(session):
def get_category(session, id):
result = session.query(Category).filter_by(id=id).first()
if result:
return jsonify(result.as_json())
return get_resource(session, Category, id)
......@@ -140,8 +141,7 @@ def handle_point(session):
return search_resource(session, Point, dict(request.args))
elif request.method == 'POST':
data = request.get_json()
data['category'] = session.query(Category).get(data['category'])
data['parent_id'] = data.pop('parent', None)
data['category'] = session.query(Category).get(data.pop('category_id'))
return create_resource(session, Point, data, 'get_point')
......@@ -149,11 +149,7 @@ def handle_point(session):
@app.route('/point/<id>', methods=['GET', 'PUT', 'DELETE'])
def get_point(session, id):
result = session.query(Point).get(id)
if result:
return jsonify(result.as_json())
return get_resource(session, Point, id)
@app.route('/point/<id>/children', methods=['GET'])
......@@ -163,5 +159,6 @@ def get_point_children(session, id):
data['parent_id'] = id
return search_resource(session, Point, data)
if __name__ == '__main__':
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