def get(self): # Get book_id and user_id from parser args = review_parser.parse_args() book_id = args.get('book_id') user_id = args.get('user_id') # If user does not exist if (not User.is_user_exists_by_id(user_id)) and (user_id != None): return {'message': 'Resource not found'}, 404 # if book does not exist if (not Book.is_book_exists_by_id(book_id)) and (book_id != None): return {'message': 'Resource not found'}, 404 # show reviews posted by certain user by only input user_id if (book_id == None and user_id != None): result = Review.get_user_reviews(user_id) return {'reviews': result}, 200 # show reviews of certain book by only input book_id elif (book_id != None and user_id == None): result = Review.get_book_review(book_id) return {'reviews': result}, 200 # show reviews posted by certain user of certain book by input both id elif (book_id != None and user_id != None): result = Review.get_book_user_review(user_id, book_id) return {'reviews': result}, 200 # book_id and user_id cannot be both empty elif (book_id == None and user_id == None): return {'message': 'book_id and user_id cannot be both empty'}, 400
def get(self): # Get collection_id from parser args = collection_user_id_parser.parse_args() user_id = args.get('user_id') if not User.is_user_exists_by_id(user_id): return {'message': 'Resource not found'}, 404 books = Collection.get_read_history(user_id) return {'books': books}, 200
def get(self): # Get collection_id from parser args = collection_user_id_parser.parse_args() user_id = args.get('user_id') if not User.is_user_exists_by_id(user_id): return {'message': 'Resource not found'}, 404 result = Collection.get_recent_added_books(user_id) return {'books': result}, 200
def get(self): # Get collection_id from parser args = collection_readHistory_tag_parser.parse_args() user_id = args.get('user_id') year = args.get('year') month = args.get('month') if (month <= 0 or month > 12): return {'message': 'Invalid month'}, 404 if (year > int(datetime.now().year)): return {'message': 'Invalid year'}, 404 if not User.is_user_exists_by_id(user_id): return {'message': 'Resource not found'}, 404 target, finish_book, finish_num, finish_flag = Goal.get_goal_record( user_id, year, month) return { 'target': target, 'finish_num': finish_num, 'finish_flag': finish_flag }, 200
def get_user_collection(user_id): # Is user exist if not User.is_user_exists_by_id(user_id): return None # SQL conn = connect_sys_db() query = "SELECT id, user_id, name, creation_time FROM collections WHERE user_id = \'{user_id}\'".format( user_id=user_id) db_result = read_sql(sql=query, con=conn) json_str = db_result.to_json(orient='index') ds = json.loads(json_str) result = [] for index in ds: if ds[index]['name'] == "Read": continue # Add book's number and number of read book in collection to result ds[index]['book_num'] = Collection.get_num_book_collection( int(ds[index]['id'])) ds[index]['finished_num'] = Collection.get_num_read_collection( user_id, int(ds[index]['id'])) result.append(ds[index]) return result
def get(self): args = goal_get_parser.parse_args() user_id = args.get('user_id') if not User.is_user_exists_by_id(user_id): return {'message': 'Resource not found'}, 404 # Get current year and month year = int(datetime.now().year) month = int(datetime.now().month) target, finish_book, finish_num, finish_flag = Goal.get_goal_record( user_id, year, month) reach_goal_num = Goal.get_goal_finish_num(user_id) if target != 0: finish_ratio = "%.2f%%" % (float(finish_num) / float(target) * 100) else: finish_ratio = 0 return { 'target': target, 'finish_ratio': finish_ratio, 'finish_num': finish_num, 'reach_goal_num': reach_goal_num, 'finish_book': finish_book }, 200
def get(self, user_id): # is user existed if not User.is_user_exists_by_id(user_id): return {'message': 'Resource not found'}, 404 # Get each tag number collection_num = Collection.get_num_collection(user_id) readhistory_num = Collection.get_num_read_collection( user_id, Collection.get_readcollection_id(user_id)) myreviews_num = Review.get_user_num_review(user_id) target, finish_book, finish_num, finish_flag = Goal.get_goal_record( user_id, int(datetime.now().year), int(datetime.now().month)) # Format finish ratio if target != 0: finish_ratio = "%.2f%%" % (float(finish_num) / float(target) * 100) else: finish_ratio = "--" return { 'collections_num': collection_num, 'ReadHistory_num': readhistory_num, 'MonthlyGoal_num': finish_ratio, 'MyReview_num': myreviews_num }, 200
def get(self, user_id): if not User.is_user_exists_by_id(user_id): return {'message': 'Resource not found'}, 404 return {'monthly goal': Goal.get_goal(user_id)}, 200
def get(self, user_id): # Is user existed if not User.is_user_exists_by_id(user_id): return {'message': "Resource not found"}, 404 result = Collection.get_user_collection(user_id) return {'list': result}, 200
def get(self, user_id): # Get review if not User.is_user_exists_by_id(user_id): return {'message': "Resource not found"}, 404 result = Review.get_user_reviews(user_id) return {'list': result}, 200