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