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
d86601aa
Commit
d86601aa
authored
Dec 04, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate review endpoints into post and get
parent
5be91500
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
18 deletions
+32
-18
api.py
canteeneo/api.py
+32
-18
No files found.
canteeneo/api.py
View file @
d86601aa
...
...
@@ -111,17 +111,24 @@ def unauthorized():
'message'
:
'Invalid login credentials!'
})
@
app
.
route
(
'/api/dishes/<int:dish_id>/favorites'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/api/dishes/<int:dish_id>/favorites'
,
methods
=
[
'GET'
])
def
dish_favorite_get
(
dish_id
):
dish
=
Dish
.
query
.
get
(
dish_id
)
return
jsonify
({
'count'
:
len
(
dish
.
favorites
),
'favorited'
:
False
if
'user'
not
in
g
else
dish
in
g
.
user
.
dish_favorites
})
@
app
.
route
(
'/api/dishes/<int:dish_id>/favorites'
,
methods
=
[
'POST'
])
@
auth
.
login_required
def
dish_favorite
(
dish_id
):
def
dish_favorite
_post
(
dish_id
):
dish
=
Dish
.
query
.
get
(
dish_id
)
if
request
.
method
==
'POST'
:
favorited
=
request
.
form
[
'favorited'
]
==
'true'
if
dish
not
in
g
.
user
.
dish_favorites
and
favorited
:
g
.
user
.
dish_favorites
.
append
(
dish
)
elif
dish
in
g
.
user
.
dish_favorites
and
not
favorited
:
g
.
user
.
dish_favorites
.
remove
(
dish
)
db
.
session
.
commit
()
favorited
=
request
.
form
[
'favorited'
]
==
'true'
if
dish
not
in
g
.
user
.
dish_favorites
and
favorited
:
g
.
user
.
dish_favorites
.
append
(
dish
)
elif
dish
in
g
.
user
.
dish_favorites
and
not
favorited
:
g
.
user
.
dish_favorites
.
remove
(
dish
)
db
.
session
.
commit
()
return
jsonify
({
'count'
:
len
(
dish
.
favorites
),
'favorited'
:
dish
in
g
.
user
.
dish_favorites
...
...
@@ -192,17 +199,24 @@ def dish_review(dish_id, review_id):
review
=
Dish
.
query
.
get
(
dish_id
)
.
reviews
.
filter_by
(
id
=
review_id
)
.
first
()
return
jsonify
(
dish_review_obj
(
review
))
@
app
.
route
(
'/api/stalls/<int:stall_id>/favorites'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/api/stalls/<int:stall_id>/favorites'
,
methods
=
[
'GET'
])
def
stall_favorite_get
(
stall_id
):
stall
=
Stall
.
query
.
get
(
stall_id
)
return
jsonify
({
'count'
:
len
(
stall
.
favorites
),
'favorited'
:
False
if
'user'
not
in
g
else
stall
in
g
.
user
.
stall_favorites
})
@
app
.
route
(
'/api/stalls/<int:stall_id>/favorites'
,
methods
=
[
'POST'
])
@
auth
.
login_required
def
stall_favorite
(
stall_id
):
def
stall_favorite
_post
(
stall_id
):
stall
=
Stall
.
query
.
get
(
stall_id
)
if
request
.
method
==
'POST'
:
favorited
=
request
.
form
[
'favorited'
]
==
'true'
if
stall
not
in
g
.
user
.
stall_favorites
and
favorited
:
g
.
user
.
stall_favorites
.
append
(
stall
)
elif
stall
in
g
.
user
.
stall_favorites
and
not
favorited
:
g
.
user
.
stall_favorites
.
remove
(
stall
)
db
.
session
.
commit
()
favorited
=
request
.
form
[
'favorited'
]
==
'true'
if
stall
not
in
g
.
user
.
stall_favorites
and
favorited
:
g
.
user
.
stall_favorites
.
append
(
stall
)
elif
stall
in
g
.
user
.
stall_favorites
and
not
favorited
:
g
.
user
.
stall_favorites
.
remove
(
stall
)
db
.
session
.
commit
()
return
jsonify
({
'count'
:
len
(
stall
.
favorites
),
'favorited'
:
stall
in
g
.
user
.
stall_favorites
...
...
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