Skip to content

Commit

Permalink
Refactor API-related data access operations (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison authored May 27, 2020
1 parent 44ef8b4 commit e0b8530
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
1 change: 0 additions & 1 deletion reciperadar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@
import reciperadar.api.recipes
import reciperadar.api.redirect
import reciperadar.api.search
import reciperadar.api.view
22 changes: 14 additions & 8 deletions reciperadar/api/recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from reciperadar.models.events.search import SearchEvent
from reciperadar.models.recipes import Recipe
from reciperadar.search.recipes import RecipeSearch
from reciperadar.services.database import Database
from reciperadar.utils.decorators import internal
from reciperadar.workers.events import store_event
from reciperadar.workers.recipes import crawl_url, index_recipe
Expand All @@ -15,20 +14,27 @@
@app.route('/api/recipes/<recipe_id>')
@internal
def recipe_get(recipe_id):
session = Database().get_session()
recipe = session.query(Recipe).get(recipe_id)
recipe = Recipe().get_by_id(recipe_id)
if not recipe:
session.close()
return abort(404)
return jsonify(recipe.to_doc())

response = recipe.to_doc()
session.close()

return jsonify(response)
@app.route('/api/recipes/<recipe_id>/view')
def recipe_view(recipe_id):
recipe = Recipe().get_by_id(recipe_id)
if not recipe:
return abort(404)

results = {
'total': 1,
'results': [recipe.to_dict()],
}
return jsonify(results)


@app.route('/api/recipes/search')
def recipes():
def recipe_search():
include = request.args.getlist('include[]')
exclude = request.args.getlist('exclude[]')
equipment = request.args.getlist('equipment[]')
Expand Down
17 changes: 0 additions & 17 deletions reciperadar/api/view.py

This file was deleted.

0 comments on commit e0b8530

Please sign in to comment.