-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview.py
169 lines (137 loc) · 4.59 KB
/
review.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import json
from tabnanny import check
import requests
import boto3
from datetime import date
from auth import session_token_to_user
from get_dynamodb import get_dynamodb_item
client = boto3.client('dynamodb',region_name='ap-southeast-2',aws_access_key_id='AKIAQPNE33YVPQHU7F64',aws_secret_access_key='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')
'''
Item={
'Event Title':{'S': event_title},
'Reviews':{'M': {
user:{'M': {
"review_text":{'S':review['review_text']},
"reply_posted":{'BOOL':review['reply_posted']},
"reply_text":{'S':review['reply_text']},
"posted_date":{'S':str(review['posted_date'])},
"edited_date":{'S':str(review['edited_date'])},
"reply_date":{'S':str(review['reply_date'])}
}}
}}
}
get_dynamodb_item("review_details","Free Beer")
'''
def post_review_to_db(event_title, user, review):
check_output = client.update_item(TableName='review_details',
Key={'Event Title':{'S': event_title}},
UpdateExpression="SET Reviews."+user+"=:r",
ExpressionAttributeValues ={
':r':{
'M': {
"review_text":{'S':review['review_text']},
"reply_posted":{'BOOL':review['reply_posted']},
"reply_text":{'S':review['reply_text']},
"posted_date":{'S':str(review['posted_date'])},
"edited_date":{'S':str(review['edited_date'])},
"reply_date":{'S':str(review['reply_date'])}
}
}
}
)
return check_output
"""
"""
def get_reviews(event_title):
reviews = get_dynamodb_item("review_details",event_title)['Reviews']
return reviews
"""
stupid hack to include keys
"""
def get_reviews_alt(event_title):
reviews = get_dynamodb_item("review_details",event_title)['Reviews']
for reviewer in reviews:
reviews[reviewer]['username'] = reviewer
return reviews
"""
"""
def review_exists(event_title, user):
try:
return user in get_reviews(event_title)
except Exception:
return False
"""
"""
def get_review(event_title, user):
reviews = get_dynamodb_item("review_details",event_title)['Reviews']
return reviews[user]
"""
"""
def post_review(session_token, event_title, review_text):
#check if session token is valid
user = session_token_to_user(session_token)
if user is None:
return False
#check if event exists and user has attended the event
#check if a review by that user for that event does not already exist
if review_exists(event_title, user):
return False
review = {
"review_text":review_text,
"reply_posted":False,
"reply_text":"",
"posted_date":date.today(),
"edited_date":None,
"reply_date":None
}
post_review_to_db(event_title, user, review)
return True
"""
"""
def edit_review(session_token, event_title, username, new_review):
#check if session token is valid
user = session_token_to_user(session_token)
if not user == username:
return False
#check if a review does already exist
if not review_exists(event_title, username):
return False
#edit review
review = get_review(event_title, username)
review["review_text"] = new_review
review["edited_date"] = date.today()
post_review_to_db(event_title, user, review)
return True
"""
"""
def reply_review(session_token, event_title, username, reply):
#check if session token is valid
user = session_token_to_user(session_token)
if user is None:
return False
#check if a review does already exist
if not review_exists(event_title, username):
return False
#check if user hosted the event
#reply to review
review = get_review(event_title, username)
review["reply_text"] = reply
review["reply_posted"] = True
review["reply_date"] = date.today()
post_review_to_db(event_title, username, review)
return True
"""
"""
def delete_review(session_token, event_title, username):
#check if session token is valid
user = session_token_to_user(session_token)
if not user == username:
return False
#check if a review does already exist
if not review_exists(event_title, username):
return False
#delete review
review = get_review(event_title, username)
post_review_to_db(event_title, user, review)
#cleanup references to review in event and user
return True