def AddTodo(self, request, context): if request.todo == '': response = todo_pb2.OperationResponse(todo=request) response.status = 2 response.message = 'Required fields missing' else: todo = add_todo(request) response = todo_pb2.OperationResponse(todo=todo_pb2.Todo( id=todo.id, todo=todo.todo, note=todo.note, status=todo.status)) response.status = 1 response.message = 'New Todo "%s" created!' % response.todo.todo return response
def UpdateTodo(self, request, context): response = todo_pb2.OperationResponse(todo=request, status=2) message, todo = update_todo(request) if todo: response = todo_pb2.OperationResponse( todo=todo_pb2.Todo(id=todo.id, todo=todo.todo, note=todo.note, status=todo.status), status=1, message=message) else: response.message = message return response
def DeleteTodo(self, request, context): response = todo_pb2.OperationResponse() if (len(self.todoList) >= request.id): response.todo.id = self.todoList[request.id]['id'] response.todo.task = self.todoList[request.id]['task'] self.todoList.remove(self.todoList[request.id]) response.status = todo_pb2.OperationResponse.DELETED else: response.error = "Task with id doesn't exist" return response
def UpdateTodo(self, request, context): response = todo_pb2.OperationResponse() for todo in self.todoList: if todo["id"] == request.id: todo["task"] = request.task response.todo.id = request.id response.todo.task = request.task response.status = todo_pb2.OperationResponse.UPDATED break else: response.error = "Task with id doesn't exist" return response
def AddTodo(self, request, context): response = todo_pb2.OperationResponse() if len(self.todoList) > 0: self.todoList.append({ "id": self.todoList[len(self.todoList) - 1]["id"] + 1, "task": request.task }) else: self.todoList.append({ "id": len(self.todoList) + 1, "task": request.task }) response.status = todo_pb2.OperationResponse.CREATED response.todo.id = len(self.todoList) response.todo.task = request.task return response
def DeleteTodo(self, request, context): status, message = delete_todo(request.id) return todo_pb2.OperationResponse(status=status, message=message)