예제 #1
0
 def post(self, id):
     user = current_identity
     data = Todo.parser.parse_args()
     todo = {'username': user.username, 'text': data['text'], 'done': False}
     todo = TodoModel(None, user.username, data['text'], False)
     todo.save_to_db()
     return {'message': 'todo has been created'}, 201
예제 #2
0
    def post(self):
        data = self.parser.parse_args()
        todo = TodoModel(**data)

        try:
            todo.save_to_db()
        except Exception as exception:
            print(exception)
            return {'message': 'An error occured inserting the item.'}, 500

        return todo.json(), 201
예제 #3
0
    def get(self, id):
        id = TodoModel.is_valid_id(id)

        if id == False:
            return {'message': 'invalid id'}, 400

        todo = TodoModel.find_by_id(id)

        if not todo:
            return {'message': 'todo was not found'}, 404

        current_user = current_identity

        if not todo.check_autherized(current_user.username):
            return {'message': 'not authorized to modify this todo'}, 401

        return todo.json()
예제 #4
0
    def get(self, title):

        todo = TodoModel.find_by_title(title)

        if todo:
            return todo.json()

        return {'message': 'Note was never created'}
예제 #5
0
    def delete(self, title):

        todo = TodoModel.find_by_title(title)

        if todo:
            todo.delete_from_db()

        return {'message': 'todo deleted'}
예제 #6
0
파일: todo.py 프로젝트: jhlabs/todo-udacity
    def delete(self, id):
        todo = TodoModel.find_by_id(id)

        if todo:
            if current_identity.id == todo.user_id:
                todo.delete_from_db()
                return {'message': 'Todo deleted'}
            else:
                return {'message': 'Sorry, this todo was not created by you.'}
        return {'message': 'Todo does not exist.'}
예제 #7
0
    def delete(self, id):
        id = TodoModel.is_valid_id(id)
        if id == False:
            return {'message': 'invalid id'}, 400

        todo = TodoModel.find_by_id(id)
        if not todo:
            return {'message': 'todo was not found'}, 400

        current_user = current_identity

        if not todo.check_autherized(current_user.username):
            return {'message': 'not authorized to modify this todo'}, 401

        try:
            todo.delete_from_db()
        except:
            return {'message': 'something went wrong'}, 500

        return {'message': 'Deleted'}, 200
예제 #8
0
파일: todo.py 프로젝트: jhlabs/todo-udacity
    def post(self):
        data = Todos.parser.parse_args()
        todo = TodoModel(desc=data['desc'],
                         done='false',
                         project_id=data['project_id'],
                         user_id=data['user_id'])

        if (ProjectModel.find_by_id(todo.project_id)):
            if (UserModel.find_by_id(todo.user_id)):
                try:
                    todo.save_to_db()
                    return todo.json(), 201
                except:
                    return {
                        "message": "An error occurred inserting the todo."
                    }, 500
            else:
                return {"message": "The associated user does not exist."}, 500
        else:
            return {"message": "The associated project does not exist."}, 500
예제 #9
0
    def put(self, title):
        data = Todo.parser.parse_args()
        todo = TodoModel.find_by_title(title)

        if todo is None:
            todo = TodoModel(title, **data)
        else:
            todo.content = data['content']
        todo.save_to_db()
        return todo.json()
예제 #10
0
파일: todo.py 프로젝트: jhlabs/todo-udacity
 def put(self, id):
     data = Todo.parser.parse_args()
     todo = TodoModel.find_by_id(id)
     if todo:
         if current_identity.id == todo.user_id:
             todo.desc = data['desc']
             todo.done = data['done']
             todo.save_to_db()
             return todo.json()
         else:
             return {'message': 'Sorry, this todo was not created by you.'}
     else:
         return {'message': 'Todo not found'}, 404
예제 #11
0
    def put(self, todo_id):
        todo = TodoModel.find_by_id(todo_id)

        if todo:
            data = self.parser.parse_args()

            todo.description = data['description']
            todo.done = data['done']
            todo.createdAt = data['createdAt']

            todo.save_to_db()

            return todo.json()

        return {'message': 'Todo not found'}, 404
예제 #12
0
    def put(self, title):

        data = Todo.parser.parse_args()
        todo = TodoModel.find_by_title(title)

        if todo is None:
            todo = TodoModel(title, data['description'], data['description'])
        else:
            todo.description = data['description']
            todo.category_id = data['category']

        try:
            todo.save_to_db()
        except:
            return {'message': 'Error updating todo'}, 500

        return todo.json()
예제 #13
0
    def post(self, title):
        if TodoModel.find_by_title(title):
            return {
                'message': "the todo '{}' already exists".format(title)
            }, 400

        data = Todo.parser.parse_args()

        todo = TodoModel(title, data['content'])

        try:
            todo.save_to_db()
        except:
            return {"message": "An error occurred inserting the todo."}, 500

        return todo.json(), 201
예제 #14
0
    def post(self, title):

        if TodoModel.find_by_title(title):
            return {
                "message":
                "A todo with the title of '{}' already exists.".format(title)
            }

        data = Todo.parser.parse_args()
        todo = TodoModel(title, data['description'], data['category'])

        try:
            todo.save_to_db()
        except:
            return {'message': 'Error saving todo'}, 500

        return todo.json(), 201
예제 #15
0
 def test_todoの情報がjsonで返却される(self):
     todo = TodoModel('task1', 'waking')
     expected = {'title': 'task1', 'content': 'waking'}
     self.assertEqual(todo.json(), expected)
예제 #16
0
 def delete(self, title):
     todo = TodoModel.find_by_title(title)
     if todo:
         todo.delete_from_db()
     return {"message": "Todo deleted"}
예제 #17
0
 def get(self, title):
     todo = TodoModel.find_by_title(title)
     if todo:
         return todo.json()
     return {'message': 'Todo not found.'}, 404
예제 #18
0
    def get(self, todo_id):
        todo = TodoModel.find_by_id(todo_id)

        if todo:
            return todo.json()
        return {'message': 'Todo not found'}, 404
예제 #19
0
    def put(self, id):
        id = TodoModel.is_valid_id(id)
        data = Todo.parser.parse_args()

        if id == False:
            return {'message': 'invalid id'}, 400

        todo = TodoModel.find_by_id(id)

        current_user = current_identity

        if not todo:
            todo = TodoModel(id, current_user.username, data['text'], False)
            todo.save_to_db()
            return {'message': 'Saved a new todo'}, 201

        if not todo.check_autherized(current_user.username):
            return {'message': 'not authorized to modify this todo'}, 401

        todo.text = data.text
        todo.done = data.done

        todo.save_to_db()

        return {'message': 'updated'}
예제 #20
0
    def test_todoのインスタンスが作成されること(self):
        todo = TodoModel('task1', 'walking')

        self.assertEqual(todo.title, 'task1')
        self.assertEqual(todo.content, 'walking')
예제 #21
0
    def delete(self, todo_id):
        todo = TodoModel.find_by_id(todo_id)

        if todo:
            todo.delete_from_db()
        return {'message': 'Todo deleted'}