Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Group17ReviewsandRatingsMicroservice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Asif, Adiv (UG - Comp Sci & Elec Eng)
Group17ReviewsandRatingsMicroservice
Commits
58fc5adf
Commit
58fc5adf
authored
2 years ago
by
Adiv Asif
Browse files
Options
Downloads
Plain Diff
Merged PR 13: Added 2 files
Added 2 files
parents
f57786ae
5e84b10e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rating.py
+39
-0
39 additions, 0 deletions
rating.py
review.py
+39
-0
39 additions, 0 deletions
review.py
with
78 additions
and
0 deletions
rating.py
0 → 100644
+
39
−
0
View file @
58fc5adf
from
flask
import
Blueprint
,
request
,
jsonify
from
flask_login
import
current_user
,
login_required
from
app.models
import
db
,
Movie
,
Rating
rating_bp
=
Blueprint
(
'
rating
'
,
__name__
,
url_prefix
=
'
/api/rating
'
)
@rating_bp.route
(
'
/create
'
,
methods
=
[
'
POST
'
])
@login_required
def
create_rating
():
data
=
request
.
get_json
()
movie_id
=
data
[
'
movie_id
'
]
value
=
data
[
'
value
'
]
movie
=
Movie
.
query
.
get
(
movie_id
)
if
not
movie
:
return
jsonify
({
'
error
'
:
'
Invalid movie ID
'
})
rating
=
Rating
(
movie
=
movie
,
user
=
current_user
,
value
=
value
)
db
.
session
.
add
(
rating
)
db
.
session
.
commit
()
return
jsonify
({
'
success
'
:
'
Rating created successfully
'
})
@rating_bp.route
(
'
/list
'
,
methods
=
[
'
GET
'
])
def
list_ratings
():
movie_id
=
request
.
args
.
get
(
'
movie_id
'
)
if
not
movie_id
:
return
jsonify
({
'
error
'
:
'
Missing movie ID
'
})
movie
=
Movie
.
query
.
get
(
movie_id
)
if
not
movie
:
return
jsonify
({
'
error
'
:
'
Invalid movie ID
'
})
ratings
=
[
r
.
to_dict
()
for
r
in
movie
.
ratings
]
return
jsonify
({
'
ratings
'
:
ratings
})
This diff is collapsed.
Click to expand it.
review.py
0 → 100644
+
39
−
0
View file @
58fc5adf
from
flask
import
Blueprint
,
request
,
jsonify
from
flask_login
import
current_user
,
login_required
from
app.models
import
db
,
Movie
,
Review
review_bp
=
Blueprint
(
'
review
'
,
__name__
,
url_prefix
=
'
/api/review
'
)
@review_bp.route
(
'
/create
'
,
methods
=
[
'
POST
'
])
@login_required
def
create_review
():
data
=
request
.
get_json
()
movie_id
=
data
[
'
movie_id
'
]
text
=
data
[
'
text
'
]
movie
=
Movie
.
query
.
get
(
movie_id
)
if
not
movie
:
return
jsonify
({
'
error
'
:
'
Invalid movie ID
'
})
review
=
Review
(
movie
=
movie
,
user
=
current_user
,
text
=
text
)
db
.
session
.
add
(
review
)
db
.
session
.
commit
()
return
jsonify
({
'
success
'
:
'
Review created successfully
'
})
@review_bp.route
(
'
/list
'
,
methods
=
[
'
GET
'
])
def
list_reviews
():
movie_id
=
request
.
args
.
get
(
'
movie_id
'
)
if
not
movie_id
:
return
jsonify
({
'
error
'
:
'
Missing movie ID
'
})
movie
=
Movie
.
query
.
get
(
movie_id
)
if
not
movie
:
return
jsonify
({
'
error
'
:
'
Invalid movie ID
'
})
reviews
=
[
r
.
to_dict
()
for
r
in
movie
.
reviews
]
return
jsonify
({
'
reviews
'
:
reviews
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment