Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS123-Canteeneo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Willard Torres
CS123-Canteeneo
Commits
44616206
Commit
44616206
authored
Nov 25, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor api tweaks, default value to search filters
parent
3aacfcdf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
14 deletions
+22
-14
api.py
canteeneo/api.py
+22
-14
No files found.
canteeneo/api.py
View file @
44616206
...
@@ -23,9 +23,13 @@ def cuisines():
...
@@ -23,9 +23,13 @@ def cuisines():
@
app
.
route
(
'/api/search/dish'
)
@
app
.
route
(
'/api/search/dish'
)
def
search
():
def
search
():
name
=
request
.
args
.
get
(
'name'
)
name
=
request
.
args
.
get
(
'name'
)
types
=
[
int
(
s
)
for
s
in
request
.
args
.
get
(
'type_filters'
)]
type_filters
=
request
.
args
.
get
(
'type_filters'
)
or
[
i
for
i
in
range
(
1
,
len
(
DishType
.
query
.
all
())
+
1
)]
cuisines
=
[
int
(
s
)
for
s
in
request
.
args
.
get
(
'cuisine_filters'
)]
cuisine_filters
=
request
.
args
.
get
(
'cuisine_filters'
)
or
[
i
for
i
in
range
(
1
,
len
(
DishCuisine
.
query
.
all
())
+
1
)]
locations
=
[
int
(
s
)
for
s
in
request
.
args
.
get
(
'location_filters'
)]
location_filters
=
request
.
args
.
get
(
'location_filters'
)
or
[
i
for
i
in
range
(
1
,
len
(
Location
.
query
.
all
())
+
1
)]
types
=
[
int
(
s
)
for
s
in
type_filters
]
cuisines
=
[
int
(
s
)
for
s
in
cuisine_filters
]
locations
=
[
int
(
s
)
for
s
in
location_filters
]
result
=
Dish
.
query
.
filter
(
result
=
Dish
.
query
.
filter
(
Dish
.
name
.
like
(
'
%
'
+
name
+
'
%
'
),
Dish
.
name
.
like
(
'
%
'
+
name
+
'
%
'
),
...
@@ -33,13 +37,7 @@ def search():
...
@@ -33,13 +37,7 @@ def search():
)
.
join
(
Dish
.
stall
)
.
filter
(
Stall
.
location_id
.
in_
(
locations
))
.
all
()
)
.
join
(
Dish
.
stall
)
.
filter
(
Stall
.
location_id
.
in_
(
locations
))
.
all
()
data
=
[]
data
=
[]
for
dish
in
result
:
for
dish
in
result
:
data
.
append
({
data
.
append
(
dish_obj
(
dish
))
'id'
:
dish
.
id
,
'name'
:
dish
.
name
,
'price'
:
dish
.
price
,
'stall_name'
:
dish
.
stall
.
name
,
'image_path'
:
dish
.
image_path
})
return
jsonify
(
data
)
return
jsonify
(
data
)
...
@@ -169,14 +167,24 @@ def stall_review(stall_id, review_id):
...
@@ -169,14 +167,24 @@ def stall_review(stall_id, review_id):
review
=
Stall
.
query
.
get
(
stall_id
)
.
reviews
.
filter_by
(
id
=
review_id
)
.
first
()
review
=
Stall
.
query
.
get
(
stall_id
)
.
reviews
.
filter_by
(
id
=
review_id
)
.
first
()
return
jsonify
(
review_obj
(
review
))
return
jsonify
(
review_obj
(
review
))
def
dish_obj
(
dish
):
if
dish
is
None
:
return
None
return
{
'id'
:
dish
.
id
,
'name'
:
dish
.
name
,
'price'
:
dish
.
price
,
'stall_name'
:
dish
.
stall
.
name
,
'image_path'
:
dish
.
image_path
}
def
review_obj
(
review
):
def
review_obj
(
review
):
if
review
is
None
:
if
review
is
None
:
return
''
return
None
re
view
=
{
re
turn
{
'title'
:
review
.
title
,
'title'
:
review
.
title
,
'body'
:
review
.
body
,
'body'
:
review
.
body
,
'rating'
:
review
.
rating
,
'rating'
:
review
.
rating
,
'user_id'
:
review
.
user_id
,
'user_id'
:
review
.
user_id
,
'dish_id'
:
review
.
dish_id
'dish_id'
:
review
.
dish_id
}
}
return
review
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment