def delete(self): username = get_username_from_header(request) if is_user_exists(username): if not delete_user_calendars(username): return '', 400 return '', 200 return '', 401
def get(self): username = get_username_from_header(request) if is_user_exists(username): serialized_data = SearchDataRequestSchema().load(request.args) if not serialized_data.errors: calendars = get_calendars_by_username(username, request.args) return paginate_data(CalendarResultSchema(many=True).dump(calendars).data, serialized_data.data), 200 return serialized_data.errors, 400 return '', 401
def post(self): serialized_data = LoginUserRequestSchema().load(request.json) if not serialized_data.errors: username = serialized_data.data['username'] if not is_user_exists(username): create_new_user(username) return {'message': f'created user: {username}'}, 201 return {'message': f'{username} exists in db'}, 200 return serialized_data.errors, 400
def put(self): username = get_username_from_header(request) if is_user_exists(username): serialized_data = CalendarEditDataSchema().load(request.json) if not serialized_data.errors: if not edit_db_object_from_request(request.json, username): return '', 404 return '', 200 return serialized_data.errors, 400 return '', 401
def get(self): username = get_username_from_header(request) if is_user_exists(username): serialized_data = DownloadDataRequestSchema().load(request.args) if not serialized_data.errors: dates = {'start': request.args['start'], 'end': request.args['end']} from app import collect_data # to solve circular ImportError with Celery collect_data.delay(dates, username) return {'message': f'Download triggered for dates: {dates}'}, 200 return serialized_data.errors, 400 return '', 401
def get(self): username = get_username_from_header(request) if is_user_exists(username): calendars = get_calendars_by_username(username, request.args) return random.choice(CalendarResultSchema(many=True).dump(calendars).data), 200 return '', 401