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
78feea0e
Commit
78feea0e
authored
Nov 23, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add filters for searching
parent
dd91f897
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
3 deletions
+26
-3
api.py
canteeneo/api.py
+26
-3
No files found.
canteeneo/api.py
View file @
78feea0e
from
canteeneo
import
app
,
db
,
auth
from
flask
import
jsonify
,
request
,
g
from
flask.views
import
MethodView
from
models
import
Dish
,
Stall
,
Location
,
User
,
DishReview
,
StallReview
from
models
import
Dish
,
Stall
,
Location
,
User
,
DishReview
,
StallReview
,
DishType
,
DishCuisine
from
datetime
import
datetime
from
itsdangerous
import
TimedJSONWebSignatureSerializer
as
Serializer
,
BadSignature
,
SignatureExpired
@
app
.
route
(
'/api/locations'
)
def
locations
():
data
=
[{
'id'
:
loc
.
id
,
'name'
:
loc
.
name
}
for
loc
in
Location
.
query
.
all
()]
return
jsonify
(
data
)
@
app
.
route
(
'/api/types'
)
def
types
():
data
=
[{
'id'
:
dish_type
.
id
,
'name'
:
dish_type
.
name
}
for
dish_type
in
DishType
.
query
.
all
()]
return
jsonify
(
data
)
@
app
.
route
(
'/api/cuisines'
)
def
cuisines
():
data
=
[{
'id'
:
cuisine
.
id
,
'name'
:
cuisine
.
name
}
for
cuisine
in
DishCuisine
.
query
.
all
()]
return
jsonify
(
data
)
@
app
.
route
(
'/api/all'
)
def
all
():
data
=
{
'update_time'
:
str
(
datetime
.
now
()),
'dishes'
:
[],
'stalls'
:
[],
'locations'
:
[]}
...
...
@@ -31,8 +46,15 @@ def all():
@
app
.
route
(
'/api/search/dish'
)
def
search
():
query
=
request
.
args
.
get
(
'name'
)
result
=
Dish
.
query
.
filter
(
Dish
.
name
.
like
(
'
%
'
+
query
+
'
%
'
))
.
all
()
name
=
request
.
args
.
get
(
'name'
)
types
=
[
int
(
s
)
for
s
in
request
.
args
.
get
(
'type_filters'
)]
cuisines
=
[
int
(
s
)
for
s
in
request
.
args
.
get
(
'cuisine_filters'
)]
locations
=
[
int
(
s
)
for
s
in
request
.
args
.
get
(
'location_filters'
)]
result
=
Dish
.
query
.
filter
(
Dish
.
name
.
like
(
'
%
'
+
name
+
'
%
'
),
Dish
.
type_id
.
in_
(
types
),
Dish
.
cuisine_id
.
in_
(
cuisines
)
)
.
join
(
Dish
.
stall
)
.
filter
(
Stall
.
location_id
.
in_
(
locations
))
.
all
()
data
=
[]
for
dish
in
result
:
data
.
append
({
...
...
@@ -42,6 +64,7 @@ def search():
'stall_name'
:
dish
.
stall
.
name
,
'image_path'
:
dish
.
image_path
})
return
jsonify
(
data
)
@
app
.
route
(
'/api/users/new'
,
methods
=
[
'POST'
])
...
...
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