Skip to content

Commit 32bbcf7

Browse files
finished up v1 work on project, moving onto frontend
1 parent 5d7e556 commit 32bbcf7

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

lib/app/IngredientsDelegate.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from app.recipe import Recipe
2+
class IngredientsDelegate:
3+
4+
def getIngredients(self):
5+
recipes=Recipe.query.all()
6+
ingredient_lists=map(lambda r: r.ingredients,recipes)
7+
return set([tag for ingredients in ingredient_lists for tag in ingredients])
8+
9+
def ingredientsInclude(self,ingredients):
10+
recipes = Recipe.query.ingredientsInclude(ingredients=ingredients)
11+
if recipes is None:
12+
return []
13+
return list(map((lambda r: r.toJson()), recipes))
14+
15+
def ingredientsIncludeAll(self,ingredients):
16+
recipes = Recipe.query.ingredientsContainAll(ingredients=ingredients)
17+
if recipes is None:
18+
return []
19+
return list(map((lambda r: r.toJson()), recipes))

lib/app/RecipeQuery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
class Queries(BaseQuery):
44

55
def ingredientsInclude(self,ingredients=[]):
6-
return self.filter(any(i in self.type.ingredients for i in ingredients))
6+
return self.filter({'ingredients':{'$in':ingredients}}).all()
77

88
def ingredientsContainAll(self,ingredients=[]):
9-
return self.filter(all(i in self.type.ingredients for i in ingredients))
9+
return self.filter({'ingredients':{'$all':ingredients}}).all()
1010

1111
def tagsInclude(self,tags=[]):
1212
return self.filter({'tags':{'$in':tags}}).all()
1313

1414
def tagsIncludeAll(self,tags=[]):
15-
return self.filter({'tags':{'$in':tags}}).all()
15+
return self.filter({'tags':{'$all':tags}}).all()
1616

1717
def titleIsLike(self,match):
1818
return self.filter(match in self.type.title)

lib/app/TagsDelegate.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ def getTags(self):
88

99
def tagsInclude(self,tags):
1010
recipes = Recipe.query.tagsInclude(tags=tags)
11+
if recipes is None:
12+
return []
13+
return list(map((lambda r: r.toJson()), recipes))
14+
15+
def tagsIncludeAll(self,tags):
16+
recipes = Recipe.query.tagsIncludeAll(tags=tags)
1117
if recipes is None:
1218
return []
1319
return list(map((lambda r: r.toJson()), recipes))

lib/app/routes.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from app import app
22
import datetime
3+
import os
34

45
from flask.json import jsonify
56
from flask import request
7+
from flask import send_file
68
from app.FileDelegate import FileDelegate
79
from app.TagsDelegate import TagsDelegate
10+
from app.IngredientsDelegate import IngredientsDelegate
811
from app.recipe import Recipe
912

1013

@@ -28,7 +31,9 @@ def searchByTags():
2831

2932
@app.route('/search/byTags/all', methods=['GET'])
3033
def searchByTagsAll():
31-
return jsonify("{}")
34+
tags = request.args['tags'].split(',')
35+
recipes = TagsDelegate().tagsIncludeAll(tags)
36+
return jsonify(recipes)
3237

3338

3439
@app.route("/search/all", methods=['GET'])
@@ -40,12 +45,15 @@ def getAll():
4045

4146
@app.route("/search/ByIngredients", methods=['GET'])
4247
def searchByIngredients():
43-
return jsonify("{}")
44-
48+
ingredients = request.args['ingredients'].split(',')
49+
recipes=IngredientsDelegate().ingredientsInclude(ingredients)
50+
return jsonify(recipes)
4551

4652
@app.route("/search/ByIngredients/all", methods=['GET'])
4753
def searchByIngredientsAll():
48-
return jsonify("{}")
54+
ingredients = request.args['ingredients'].split(',')
55+
recipes=IngredientsDelegate().ingredientsIncludeAll(ingredients)
56+
return jsonify(recipes)
4957

5058

5159
@app.route("/recipes/put", methods=['POST'])
@@ -82,4 +90,12 @@ def getTags():
8290

8391
@app.route('/recipes/ingredients', methods=['GET'])
8492
def getIngredients():
85-
return jsonify("{}")
93+
ingredients = IngredientsDelegate().getIngredients()
94+
return jsonify(list(ingredients))
95+
96+
@app.route('/download',methods=['GET'])
97+
def downloadFile():
98+
filename=request.args['filename']
99+
full_path=os.path.join(os.getcwd(),"pdfs",filename)
100+
return send_file(full_path)
101+

0 commit comments

Comments
 (0)