forked from egrfly/instabook-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrating_management.py
77 lines (65 loc) · 2.54 KB
/
rating_management.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from utils import get_db_connection
def get_book_rating_for_user(book_id, user_id):
"""
Get a specific user's rating for a book
Required columns: r.score, r.review
Required tables: book_ratings r
"""
with get_db_connection() as connection:
with connection.cursor() as cursor:
# Temporary code
if book_id == 1:
return [(5, 'Banging')]
else:
return []
def get_recent_book_ratings(book_id):
"""
Get 10 most recent ratings for a book
Required columns: u.id, u.username, u.display_name, r.score, r.review
Required tables: users u, book_ratings r
"""
with get_db_connection() as connection:
with connection.cursor() as cursor:
# Temporary code
return [(1, 'somebody', 'Some Body', 5, 'Banging'),
(2, 'somebodyelse', 'Somebody Else', 4, 'It was good I guess')]
def get_recent_user_ratings(user_id):
"""
Get 10 most recent ratings for a user
Required columns: b.id, b.title, b.author, r.score, r.review
Required tables: books b, book_ratings r
"""
with get_db_connection() as connection:
with connection.cursor() as cursor:
# Temporary code
return [(1, 'Some Book', 'Some Author', 5, 'Banging'),
(2, 'Some Other Book', 'Some Other Author', 4, 'It was good I guess')]
def get_recent_follower_ratings(user_id):
"""
Get 10 most recent ratings from followed users
Required columns: u.id, u.username, u.display_name, b.id, b.title, b.author, r.score, r.review
Required tables: users u, followers f, books b, book_ratings r
"""
with get_db_connection() as connection:
with connection.cursor() as cursor:
# Temporary code
return [(1, 'somebody', 'Some Body', 1, 'Some Book', 'Some Author', 5, 'Banging'),
(2, 'somebodyelse', 'Somebody Else', 2, 'Some Other Book', 'Some Other Author', 4, 'It was good I guess')]
def add_rating(user_id, book_id, score, review):
"""
Add a user rating for a specific book into the database
Required tables: book_ratings r
"""
with get_db_connection() as connection:
with connection.cursor() as cursor:
# Temporary code
pass
def remove_rating(user_id, book_id):
"""
Remove a user rating for a specific book
Required tables: book_ratings r
"""
with get_db_connection() as connection:
with connection.cursor() as cursor:
# Temporary code
pass