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
15337921
Commit
15337921
authored
Nov 26, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept dish review as JSON instead of form
parent
44616206
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
6 deletions
+31
-6
api.py
canteeneo/api.py
+31
-6
No files found.
canteeneo/api.py
View file @
15337921
...
...
@@ -108,9 +108,9 @@ def dish_favorite(dish_id):
@
auth
.
login_required
def
create_dish_review
(
dish_id
):
user_id
=
g
.
user
.
id
title
=
request
.
form
[
'title'
]
body
=
request
.
form
[
'body'
]
rating
=
int
(
request
.
form
[
'rating'
])
title
=
request
.
json
[
'title'
]
body
=
request
.
json
[
'body'
]
rating
=
int
(
request
.
json
[
'rating'
])
review
=
DishReview
(
title
,
body
,
rating
,
user_id
,
dish_id
)
db
.
session
.
add
(
review
)
db
.
session
.
commit
()
...
...
@@ -118,12 +118,28 @@ def create_dish_review(dish_id):
@
app
.
route
(
'/api/dishes/<int:dish_id>/reviews'
,
methods
=
[
'GET'
])
def
dish_reviews
(
dish_id
):
reviews
=
Dish
.
query
.
get
(
dish_id
)
.
reviews
.
all
()
dish
=
Dish
.
query
.
get
(
dish_id
)
if
dish
is
None
:
return
'Invalid dish'
reviews
=
dish
.
reviews
.
all
()
data
=
[]
for
review
in
reviews
:
data
.
append
(
review_obj
(
review
))
return
jsonify
(
data
)
@
app
.
route
(
'/api/stalls'
,
methods
=
[
'GET'
])
def
get_stall_by_name
():
name
=
request
.
args
.
get
(
'name'
)
return
jsonify
(
stall_obj
(
Stall
.
query
.
filter_by
(
name
=
name
)
.
first
()))
@
app
.
route
(
'/api/stalls/<int:stall_id>/dishes'
,
methods
=
[
'GET'
])
def
get_dishes_by_stall
(
stall_id
):
dishes
=
[]
stall
=
Stall
.
query
.
get
(
stall_id
)
for
dish
in
stall
.
dishes
:
dishes
.
append
(
dish_obj
(
dish
))
return
jsonify
(
dishes
)
@
app
.
route
(
'/api/dishes/<int:dish_id>/reviews/<int:review_id>'
,
methods
=
[
'GET'
])
def
dish_review
(
dish_id
,
review_id
):
review
=
Dish
.
query
.
get
(
dish_id
)
.
reviews
.
filter_by
(
id
=
review_id
)
.
first
()
...
...
@@ -178,12 +194,21 @@ def dish_obj(dish):
'image_path'
:
dish
.
image_path
}
def
stall_obj
(
stall
):
if
stall
is
None
:
return
None
return
{
'id'
:
stall
.
id
,
'name'
:
stall
.
name
,
'description'
:
stall
.
description
,
'location'
:
Location
.
query
.
get
(
stall
.
location_id
)
.
name
}
def
review_obj
(
review
):
if
review
is
None
:
return
None
return
{
'title'
:
review
.
title
,
'body'
:
review
.
body
,
'rating'
:
review
.
rating
,
'user_id'
:
review
.
user_id
,
'dish_id'
:
review
.
dish_id
...
...
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