diff --git a/api/src/features/todo/todo_feature.py b/api/src/features/todo/todo_feature.py index cf76a25f..0fc76d8d 100644 --- a/api/src/features/todo/todo_feature.py +++ b/api/src/features/todo/todo_feature.py @@ -1,6 +1,7 @@ from typing import List from fastapi import APIRouter, Depends +from starlette import status from starlette.responses import JSONResponse from authentication.authentication import auth_with_jwt @@ -10,7 +11,6 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.delete_todo_by_id import DeleteTodoResponse from .shared_models import TodoItemResponseModel from .use_cases.add_todo import AddTodoRequestModel, add_todo_use_case @@ -42,14 +42,14 @@ def get_todo_by_id( return get_todo_by_id_use_case(id=id, user_id=user.user_id, todo_repository=todo_repository).dict() -@router.delete("/{id}", operation_id="delete_by_id", response_model=DeleteTodoResponse) +@router.delete("/{id}", operation_id="delete_by_id", status_code=status.HTTP_204_NO_CONTENT) @create_response(JSONResponse) def delete_todo_by_id( id: str, user: User = Depends(auth_with_jwt), todo_repository: TodoRepositoryInterface = Depends(get_todo_repository), ): - return delete_todo_use_case(id=id, user_id=user.user_id, todo_repository=todo_repository).dict() + return delete_todo_use_case(id=id, user_id=user.user_id, todo_repository=todo_repository) @router.get("", operation_id="get_all", response_model=List[TodoItemResponseModel]) diff --git a/api/src/features/todo/use_cases/delete_todo_by_id.py b/api/src/features/todo/use_cases/delete_todo_by_id.py index e8c7f33c..1199de62 100644 --- a/api/src/features/todo/use_cases/delete_todo_by_id.py +++ b/api/src/features/todo/use_cases/delete_todo_by_id.py @@ -1,20 +1,13 @@ -from pydantic import BaseModel, Field - from common.exceptions import MissingPrivilegeException, NotFoundException from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -class DeleteTodoResponse(BaseModel): - success: bool = Field(...) - - -def delete_todo_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> DeleteTodoResponse: +def delete_todo_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> None: todo_item = todo_repository.get(id) if todo_item is None: raise NotFoundException if todo_item.user_id != user_id: raise MissingPrivilegeException todo_repository.delete(id) - return DeleteTodoResponse(success=True) diff --git a/api/src/tests/unit/features/todo/use_cases/test_delete_todo_by_id.py b/api/src/tests/unit/features/todo/use_cases/test_delete_todo_by_id.py index a76e1110..1b43f7b8 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_delete_todo_by_id.py +++ b/api/src/tests/unit/features/todo/use_cases/test_delete_todo_by_id.py @@ -9,8 +9,10 @@ def test_delete_todo_should_return_success(todo_repository: TodoRepositoryInterface): id = "dh2109" - result = delete_todo_use_case(id=id, user_id="xyz", todo_repository=todo_repository) - assert result.success + try: + delete_todo_use_case(id=id, user_id="xyz", todo_repository=todo_repository) + except Exception: + assert False def test_delete_todo_should_return_not_success(todo_repository: TodoRepositoryInterface):