def schema(event, context): create_todos = query.create_class({ 'name': 'todos' }) create_all_todos = query.create_index({ 'name': 'all_todos', 'source': TODOS }) client.query(query.if_expr( query.exists(TODOS), query.get(TODOS), create_todos )) client.query(query.if_expr( query.exists(ALL_TODOS), query.get(ALL_TODOS), create_all_todos )) # create a response response = { "statusCode": 200 } return response
def delete(event, context): # delete the todo from the database client.query(query.delete(Ref(TODOS, event['pathParameters']['id']))) # create a response response = { "statusCode": 200 } return response
def get(event, context): # fetch todo from the database ref = Ref(TODOS, event['pathParameters']['id']) fetched = client.query(query.get(ref)) # create a response response = {"statusCode": 200, "body": json.dumps(make_result(fetched))} return response
def schema(event, context): create_todos = query.create_class({'name': 'todos'}) create_all_todos = query.create_index({ 'name': 'all_todos', 'source': TODOS }) client.query( query.if_expr(query.exists(TODOS), query.get(TODOS), create_todos)) client.query( query.if_expr(query.exists(ALL_TODOS), query.get(ALL_TODOS), create_all_todos)) # create a response response = {"statusCode": 200} return response
def get(event, context): # fetch todo from the database ref = Ref(TODOS, event['pathParameters']['id']) fetched = client.query(query.get(ref)) # create a response response = { "statusCode": 200, "body": json.dumps(make_result(fetched)) } return response
def list(event, context): # fetch all todos from the database results = client.query( query.map_expr(lambda ref: query.get(ref), query.paginate(query.match(ALL_TODOS)))) # create a response response = { "statusCode": 200, "body": json.dumps(map(make_result, results['data'])) } return response
def create(event, context): data = json.loads(event['body']) if 'text' not in data: logging.error("Validation Failed") raise Exception("Couldn't create the todo item.") data = { 'text': data['text'], 'checked': False, 'createdAt': query.time('now'), 'updatedAt': query.time('now') } # write the todo to the database created = client.query(query.create(TODOS, {'data': data})) # create a response response = {"statusCode": 200, "body": json.dumps(make_result(created))} return response
def update(event, context): data = json.loads(event['body']) if 'text' not in data or 'checked' not in data: logging.error("Validation Failed") raise Exception("Couldn't update the todo item.") data = { 'text': data['text'], 'checked': data['checked'], 'updatedAt': query.time('now') } # update the todo in the database ref = Ref(TODOS, event['pathParameters']['id']) updated = client.query(query.update(ref, {'data': data})) # create a response response = {"statusCode": 200, "body": json.dumps(make_result(updated))} return response
def update(event, context): data = json.loads(event['body']) if 'text' not in data or 'checked' not in data: logging.error("Validation Failed") raise Exception("Couldn't update the todo item.") data = { 'text': data['text'], 'checked': data['checked'], 'updatedAt': query.time('now') } # update the todo in the database ref = Ref(TODOS, event['pathParameters']['id']) updated = client.query(query.update(ref, {'data': data})) # create a response response = { "statusCode": 200, "body": json.dumps(make_result(updated)) } return response
def create(event, context): data = json.loads(event['body']) if 'text' not in data: logging.error("Validation Failed") raise Exception("Couldn't create the todo item.") data = { 'text': data['text'], 'checked': False, 'createdAt': query.time('now'), 'updatedAt': query.time('now') } # write the todo to the database created = client.query(query.create(TODOS, {'data': data})) # create a response response = { "statusCode": 200, "body": json.dumps(make_result(created)) } return response