def get_location(group_id): ''' get trip location of the group ''' result = {} if not database.exist_group(group_id): raise ValueError(f"Group '{group_id}' does not exist") result['location'] = database.get_group_location(group_id) return result
def create_group(group_name, leader_token, trip_date, location): ''' create a group ''' group_id = group_name + '_' + trip_date if database.exist_group(group_id): raise ValueError('Group id not unique') leader_email = database.find_email_by_token(leader_token) if not leader_email: raise AuthorizationError('Invalid access token') database.add_group(leader_email, group_id, location)
def get_main_activity_names(group_id): ''' get activity names of all nominated activities ''' if not database.exist_group(group_id): raise ValueError(f"Group '{group_id}' does not exist") main_activities = [] data = database.get_main_activity_names(group_id) for line in data: (activity_name,) = line main_activities.append(activity_name) return main_activities
def get_nominations_from_database(group_id): ''' get basic information of nominated activities of given group from database ''' if not database.exist_group(group_id): raise ValueError(f"Group '{group_id}' does not exist") activities = [] for activity_info in database.get_nominations(group_id): (activity_id, activity_name, rating, photo_reference, category) = activity_info activities.append( { 'activity_id': activity_id, 'activity_name': activity_name, 'rating': rating, 'photo_reference': photo_reference, 'category': category } ) return activities
def nominate(group_id, google_places_id, activity_name, rating, photo_reference, category): ''' nominate an activity ''' if not database.exist_group(group_id): raise ValueError(f"Group '{group_id}' does not exist") activity_id = add_activity_to_database(group_id, google_places_id, activity_name, rating, photo_reference, category, 'main') cache.add_activity(group_id, activity_id, activity_name, rating, photo_reference, category)