From 609fe7645e9d4ce7bc2a74434a4564ac3d718a57 Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Sat, 12 Nov 2022 21:13:00 +0100 Subject: [PATCH 01/11] refactor: map entity fields to request and response models --- api/src/common/entity_mapper.py | 37 ++ .../repositories/TodoRepository.py | 2 +- api/src/entities/TodoItem.py | 31 +- api/src/features/todo/shared_models.py | 8 + api/src/features/todo/todo_feature.py | 30 +- api/src/features/todo/use_cases/add_todo.py | 36 +- .../todo/use_cases/delete_todo_by_id.py | 6 +- .../features/todo/use_cases/get_todo_all.py | 18 +- .../features/todo/use_cases/get_todo_by_id.py | 20 +- .../features/todo/use_cases/update_todo.py | 28 +- .../features/todo/test_todo_feature.py | 2 +- .../features/todo/use_cases/test_add_todo.py | 12 +- .../todo/use_cases/test_delete_todo_by_id.py | 7 +- .../todo/use_cases/test_get_todo_by_id.py | 7 +- .../todo/use_cases/test_update_todo.py | 2 +- generate-api-typescript-client.sh | 2 +- .../api/generated/.openapi-generator/FILES | 11 +- web/src/api/generated/api.ts | 4 +- web/src/api/generated/api/health-check-api.ts | 4 +- .../api/personal-access-token-api.ts | 459 ------------------ web/src/api/generated/api/todos-api.ts | 167 ++----- web/src/api/generated/api/whoami-api.ts | 4 +- web/src/api/generated/base.ts | 4 +- web/src/api/generated/common.ts | 4 +- web/src/api/generated/configuration.ts | 4 +- web/src/api/generated/index.ts | 4 +- web/src/api/generated/models/access-level.ts | 24 - .../api/generated/models/add-todo-request.ts | 31 -- .../generated/models/delete-pat-response.ts | 27 -- .../models/delete-todo-by-id-response.ts | 31 -- .../generated/models/delete-todo-response.ts | 31 ++ .../api/generated/models/error-response.ts | 4 +- .../models/get-pat-by-username-response.ts | 33 -- .../generated/models/get-todo-all-response.ts | 43 -- .../models/get-todo-by-id-response.ts | 43 -- .../generated/models/httpvalidation-error.ts | 29 -- web/src/api/generated/models/index.ts | 10 +- .../{add-todo-response.ts => todo-item.ts} | 14 +- .../generated/models/update-todo-request.ts | 37 -- .../generated/models/update-todo-response.ts | 31 -- web/src/api/generated/models/update-todo.ts | 37 ++ .../api/generated/models/validation-error.ts | 39 -- web/src/features/todos/todo-list/TodoItem.tsx | 8 +- web/src/features/todos/todo-list/TodoList.tsx | 10 +- web/src/hooks/useTodos.tsx | 31 +- 45 files changed, 293 insertions(+), 1133 deletions(-) create mode 100644 api/src/common/entity_mapper.py create mode 100644 api/src/features/todo/shared_models.py delete mode 100644 web/src/api/generated/api/personal-access-token-api.ts delete mode 100644 web/src/api/generated/models/access-level.ts delete mode 100644 web/src/api/generated/models/add-todo-request.ts delete mode 100644 web/src/api/generated/models/delete-pat-response.ts delete mode 100644 web/src/api/generated/models/delete-todo-by-id-response.ts create mode 100644 web/src/api/generated/models/delete-todo-response.ts delete mode 100644 web/src/api/generated/models/get-pat-by-username-response.ts delete mode 100644 web/src/api/generated/models/get-todo-all-response.ts delete mode 100644 web/src/api/generated/models/get-todo-by-id-response.ts delete mode 100644 web/src/api/generated/models/httpvalidation-error.ts rename web/src/api/generated/models/{add-todo-response.ts => todo-item.ts} (50%) delete mode 100644 web/src/api/generated/models/update-todo-request.ts delete mode 100644 web/src/api/generated/models/update-todo-response.ts create mode 100644 web/src/api/generated/models/update-todo.ts delete mode 100644 web/src/api/generated/models/validation-error.ts diff --git a/api/src/common/entity_mapper.py b/api/src/common/entity_mapper.py new file mode 100644 index 00000000..dc6b2ed4 --- /dev/null +++ b/api/src/common/entity_mapper.py @@ -0,0 +1,37 @@ +from typing import Optional, Type + +from pydantic import BaseModel + + +def filter_fields( + name: Optional[str] = None, + include: Optional[list[str]] = None, + exclude: Optional[list[str]] = None, +): + """Return a decorator to filter model fields""" + + def decorator(cls: Type[BaseModel]): + config = cls.Config() + to_include = getattr(config, "include", include) + to_exclude = getattr(config, "exclude", exclude) + + if name: + cls.__name__ = name + + include_ = set(cls.__fields__.keys()) + + if to_include is not None: + include_ &= set(to_include) + + exclude_ = set() + if to_exclude is not None: + exclude_ = set(to_exclude) + if to_include and to_exclude and set(to_include) & set(to_exclude): + raise ValueError("include and exclude cannot contain the same fields") + + for field in list(cls.__fields__): + if field not in include_ or field in exclude_: + del cls.__fields__[field] + return cls + + return decorator diff --git a/api/src/data_providers/repositories/TodoRepository.py b/api/src/data_providers/repositories/TodoRepository.py index 8e85aad9..549c85b1 100644 --- a/api/src/data_providers/repositories/TodoRepository.py +++ b/api/src/data_providers/repositories/TodoRepository.py @@ -9,7 +9,7 @@ def to_dict(todo_item: TodoItem): - dict = todo_item.__dict__ + dict = todo_item.dict() dict["_id"] = todo_item.id return dict diff --git a/api/src/entities/TodoItem.py b/api/src/entities/TodoItem.py index 8bde68ff..0327d383 100644 --- a/api/src/entities/TodoItem.py +++ b/api/src/entities/TodoItem.py @@ -1,19 +1,34 @@ -from dataclasses import asdict, dataclass, fields +from __future__ import annotations +from typing import List -@dataclass(frozen=True) -class TodoItem: +from pydantic import BaseModel, Field + +title_field = Field( + ..., title="The title of the item", max_length=30, min_length=1, example="Read about clean architecture" +) + + +class User(BaseModel): + id: str + todos: List[TodoList] + + +class TodoList(BaseModel): + id: str + user: User + items: List[TodoItem] + + +class TodoItem(BaseModel): id: str user_id: str - title: str + title: str = title_field is_completed: bool = False - def to_dict(self): - return asdict(self) - @classmethod def from_dict(cls, dict_) -> "TodoItem": - class_fields = {f.name for f in fields(cls)} + class_fields = {field for field in cls.__fields__} if "_id" in dict_: dict_["id"] = dict_.pop("_id") data = {k: v for k, v in dict_.items() if k in class_fields} diff --git a/api/src/features/todo/shared_models.py b/api/src/features/todo/shared_models.py new file mode 100644 index 00000000..c7dd030f --- /dev/null +++ b/api/src/features/todo/shared_models.py @@ -0,0 +1,8 @@ +from common.entity_mapper import filter_fields +from entities.TodoItem import TodoItem + + +@filter_fields(name="TodoItem") +class TodoItemResponseModel(TodoItem): + class Config: + exclude = ["user_id"] diff --git a/api/src/features/todo/todo_feature.py b/api/src/features/todo/todo_feature.py index ce05eebf..b9c8b488 100644 --- a/api/src/features/todo/todo_feature.py +++ b/api/src/features/todo/todo_feature.py @@ -10,31 +10,29 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) +from features.todo.use_cases.delete_todo_by_id import DeleteTodoResponse -from .use_cases.add_todo import AddTodoRequest, AddTodoResponse, add_todo_use_case -from .use_cases.delete_todo_by_id import DeleteTodoByIdResponse, delete_todo_use_case -from .use_cases.get_todo_all import GetTodoAllResponse, get_todo_all_use_case -from .use_cases.get_todo_by_id import GetTodoByIdResponse, get_todo_by_id_use_case -from .use_cases.update_todo import ( - UpdateTodoRequest, - UpdateTodoResponse, - update_todo_use_case, -) +from .shared_models import TodoItemResponseModel +from .use_cases.add_todo import add_todo_use_case +from .use_cases.delete_todo_by_id import delete_todo_use_case +from .use_cases.get_todo_all import get_todo_all_use_case +from .use_cases.get_todo_by_id import get_todo_by_id_use_case +from .use_cases.update_todo import UpdateTodoRequest, update_todo_use_case router = APIRouter(tags=["todos"], prefix="/todos") -@router.post("", operation_id="create", response_model=AddTodoResponse) +@router.post("", operation_id="create", response_model=TodoItemResponseModel) @create_response(JSONResponse) def add_todo( - data: AddTodoRequest, + title: str, user: User = Depends(auth_with_jwt), todo_repository: TodoRepositoryInterface = Depends(get_todo_repository), ): - return add_todo_use_case(data=data, user_id=user.user_id, todo_repository=todo_repository).dict() + return add_todo_use_case(title=title, user_id=user.user_id, todo_repository=todo_repository).dict() -@router.get("/{id}", operation_id="get_by_id", response_model=GetTodoByIdResponse) +@router.get("/{id}", operation_id="get_by_id", response_model=TodoItemResponseModel) @create_response(JSONResponse) def get_todo_by_id( id: str, @@ -44,7 +42,7 @@ 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=DeleteTodoByIdResponse) +@router.delete("/{id}", operation_id="delete_by_id", response_model=DeleteTodoResponse) @create_response(JSONResponse) def delete_todo_by_id( id: str, @@ -54,7 +52,7 @@ def delete_todo_by_id( return delete_todo_use_case(id=id, user_id=user.user_id, todo_repository=todo_repository).dict() -@router.get("", operation_id="get_all", response_model=List[GetTodoAllResponse]) +@router.get("", operation_id="get_all", response_model=List[TodoItemResponseModel]) @create_response(JSONResponse) def get_todo_all( user: User = Depends(auth_with_jwt), todo_repository: TodoRepositoryInterface = Depends(get_todo_repository) @@ -62,7 +60,7 @@ def get_todo_all( return [todo.dict() for todo in get_todo_all_use_case(user_id=user.user_id, todo_repository=todo_repository)] -@router.put("/{id}", operation_id="update_by_id", response_model=UpdateTodoResponse) +@router.put("/{id}", operation_id="update_by_id", response_model=TodoItemResponseModel) @create_response(JSONResponse) def update_todo( id: str, diff --git a/api/src/features/todo/use_cases/add_todo.py b/api/src/features/todo/use_cases/add_todo.py index fdd30f17..eb91ffac 100644 --- a/api/src/features/todo/use_cases/add_todo.py +++ b/api/src/features/todo/use_cases/add_todo.py @@ -1,38 +1,24 @@ import uuid -from pydantic import BaseModel, Field - +from common.entity_mapper import filter_fields from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from entities.TodoItem import TodoItem - - -class AddTodoRequest(BaseModel): - title: str = Field( - ..., - title="The title of the item", - max_length=300, - min_length=1, - example="Read about clean architecture", - ) - +from entities.TodoItem import TodoItem, title_field +from features.todo.shared_models import TodoItemResponseModel -class AddTodoResponse(BaseModel): - id: str = Field(example="vytxeTZskVKR7C7WgdSP3d") - title: str = Field(example="Read about clean architecture") - is_completed: bool = False - @staticmethod - def from_entity(todo_item: TodoItem) -> "AddTodoResponse": - return AddTodoResponse(id=todo_item.id, title=todo_item.title, is_completed=todo_item.is_completed) +@filter_fields(name="AddTodo") +class AddTodoRequestModel(TodoItem): + class Config: + include = ["title"] def add_todo_use_case( - data: AddTodoRequest, user_id: str, todo_repository: TodoRepositoryInterface, -) -> AddTodoResponse: - todo_item = TodoItem(id=str(uuid.uuid4()), title=data.title, user_id=user_id) + title: str = title_field, +) -> TodoItemResponseModel: + todo_item = TodoItem(id=str(uuid.uuid4()), title=title, user_id=user_id) todo_repository.create(todo_item) - return AddTodoResponse.from_entity(todo_item) + return TodoItemResponseModel.parse_obj(todo_item) 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 59eada21..e8c7f33c 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 @@ -6,15 +6,15 @@ ) -class DeleteTodoByIdResponse(BaseModel): +class DeleteTodoResponse(BaseModel): success: bool = Field(...) -def delete_todo_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> DeleteTodoByIdResponse: +def delete_todo_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> DeleteTodoResponse: 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 DeleteTodoByIdResponse(success=True) + return DeleteTodoResponse(success=True) diff --git a/api/src/features/todo/use_cases/get_todo_all.py b/api/src/features/todo/use_cases/get_todo_all.py index 8806acf3..7461f688 100644 --- a/api/src/features/todo/use_cases/get_todo_all.py +++ b/api/src/features/todo/use_cases/get_todo_all.py @@ -1,29 +1,17 @@ from typing import List -from pydantic import BaseModel, Field - from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from entities.TodoItem import TodoItem - - -class GetTodoAllResponse(BaseModel): - id: str = Field(...) - title: str = Field(...) - is_completed: bool - - @staticmethod - def from_entity(todo_item: TodoItem): - return GetTodoAllResponse(id=todo_item.id, title=todo_item.title, is_completed=todo_item.is_completed) +from features.todo.shared_models import TodoItemResponseModel def get_todo_all_use_case( user_id: str, todo_repository: TodoRepositoryInterface, -) -> List[GetTodoAllResponse]: +) -> List[TodoItemResponseModel]: return [ - GetTodoAllResponse.from_entity(todo_item) + TodoItemResponseModel.parse_obj(todo_item) for todo_item in todo_repository.get_all() if todo_item.user_id == user_id ] diff --git a/api/src/features/todo/use_cases/get_todo_by_id.py b/api/src/features/todo/use_cases/get_todo_by_id.py index 78b710c6..114f905e 100644 --- a/api/src/features/todo/use_cases/get_todo_by_id.py +++ b/api/src/features/todo/use_cases/get_todo_by_id.py @@ -1,26 +1,12 @@ -from typing import cast - -from pydantic import BaseModel, Field - from common.exceptions import MissingPrivilegeException from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from entities.TodoItem import TodoItem - - -class GetTodoByIdResponse(BaseModel): - id: str = Field(...) - title: str = Field(...) - is_completed: bool = False - - @staticmethod - def from_entity(todo_item: TodoItem) -> "GetTodoByIdResponse": - return GetTodoByIdResponse(id=todo_item.id, title=todo_item.title, is_completed=todo_item.is_completed) +from features.todo.shared_models import TodoItemResponseModel -def get_todo_by_id_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> GetTodoByIdResponse: +def get_todo_by_id_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> TodoItemResponseModel: todo_item = todo_repository.get(id) if todo_item.user_id != user_id: raise MissingPrivilegeException - return GetTodoByIdResponse.from_entity(cast(TodoItem, todo_item)) + return TodoItemResponseModel.parse_obj(todo_item) diff --git a/api/src/features/todo/use_cases/update_todo.py b/api/src/features/todo/use_cases/update_todo.py index cc186e4e..9af4dc61 100644 --- a/api/src/features/todo/use_cases/update_todo.py +++ b/api/src/features/todo/use_cases/update_todo.py @@ -1,24 +1,16 @@ -from pydantic import BaseModel, Field - +from common.entity_mapper import filter_fields from common.exceptions import MissingPrivilegeException from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) from entities.TodoItem import TodoItem +from features.todo.shared_models import TodoItemResponseModel -class UpdateTodoRequest(BaseModel): - title: str = Field( - "", - title="The title of the item", - max_length=300, - min_length=1, - ) - is_completed: bool - - -class UpdateTodoResponse(BaseModel): - success: bool = Field(...) +@filter_fields(name="UpdateTodo") +class UpdateTodoRequest(TodoItem): + class Config: + include = ["title", "is_completed"] def update_todo_use_case( @@ -26,12 +18,10 @@ def update_todo_use_case( data: UpdateTodoRequest, user_id: str, todo_repository: TodoRepositoryInterface, -) -> UpdateTodoResponse: +) -> TodoItemResponseModel: todo_item = todo_repository.get(id) if todo_item.user_id != user_id: raise MissingPrivilegeException - updated_todo_item = TodoItem(id=todo_item.id, title=data.title, is_completed=data.is_completed, user_id=user_id) - if todo_repository.update(updated_todo_item): - return UpdateTodoResponse(success=True) - return UpdateTodoResponse(success=False) + todo_repository.update(updated_todo_item) + return TodoItemResponseModel.parse_obj(updated_todo_item) diff --git a/api/src/tests/integration/features/todo/test_todo_feature.py b/api/src/tests/integration/features/todo/test_todo_feature.py index 362f56a5..f9498d32 100644 --- a/api/src/tests/integration/features/todo/test_todo_feature.py +++ b/api/src/tests/integration/features/todo/test_todo_feature.py @@ -59,7 +59,7 @@ def test_update_todo(self, test_app): response = test_app.put("/todos/1", json={"title": "title 1 updated", "is_completed": False}) assert response.status_code == HTTP_200_OK - assert response.json()["success"] + assert response.json()["title"] == "title 1 updated" def test_update_todo_should_return_not_found(self, test_app): response = test_app.put("/todos/unknown", json={"title": "something", "is_completed": False}) diff --git a/api/src/tests/unit/features/todo/use_cases/test_add_todo.py b/api/src/tests/unit/features/todo/use_cases/test_add_todo.py index e2d0b7e2..44502c25 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_add_todo.py +++ b/api/src/tests/unit/features/todo/use_cases/test_add_todo.py @@ -4,16 +4,16 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.add_todo import AddTodoRequest, add_todo_use_case +from features.todo.use_cases.add_todo import add_todo_use_case def test_add_with_valid_title_should_return_todo(todo_repository: TodoRepositoryInterface): - data = AddTodoRequest(title="new todo") - result = add_todo_use_case(data, user_id="xyz", todo_repository=todo_repository) - assert result.title == data.title + title = "new todo" + result = add_todo_use_case(title=title, user_id="xyz", todo_repository=todo_repository) + assert result.title == title def test_add_with_empty_title_should_throw_validation_error(todo_repository: TodoRepositoryInterface): with pytest.raises(ValidationError): - data = AddTodoRequest(title="") - add_todo_use_case(data, user_id="xyz", todo_repository=todo_repository) + title = "" + add_todo_use_case(title=title, user_id="xyz", todo_repository=todo_repository) 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 4faf142a..a76e1110 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 @@ -4,15 +4,12 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.delete_todo_by_id import ( - DeleteTodoByIdResponse, - delete_todo_use_case, -) +from features.todo.use_cases.delete_todo_by_id import delete_todo_use_case def test_delete_todo_should_return_success(todo_repository: TodoRepositoryInterface): id = "dh2109" - result: DeleteTodoByIdResponse = delete_todo_use_case(id=id, user_id="xyz", todo_repository=todo_repository) + result = delete_todo_use_case(id=id, user_id="xyz", todo_repository=todo_repository) assert result.success diff --git a/api/src/tests/unit/features/todo/use_cases/test_get_todo_by_id.py b/api/src/tests/unit/features/todo/use_cases/test_get_todo_by_id.py index 3eef9b66..396710e9 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_get_todo_by_id.py +++ b/api/src/tests/unit/features/todo/use_cases/test_get_todo_by_id.py @@ -6,15 +6,12 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.get_todo_by_id import ( - GetTodoByIdResponse, - get_todo_by_id_use_case, -) +from features.todo.use_cases.get_todo_by_id import get_todo_by_id_use_case def test_get_todo_by_id_should_return_todo(todo_repository: TodoRepositoryInterface, todo_test_data: Dict[str, dict]): id = "dh2109" - todo: GetTodoByIdResponse = get_todo_by_id_use_case(id, user_id="xyz", todo_repository=todo_repository) + todo = get_todo_by_id_use_case(id, user_id="xyz", todo_repository=todo_repository) assert todo.title == todo_test_data[id]["title"] diff --git a/api/src/tests/unit/features/todo/use_cases/test_update_todo.py b/api/src/tests/unit/features/todo/use_cases/test_update_todo.py index 47381b14..8006bea1 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_update_todo.py +++ b/api/src/tests/unit/features/todo/use_cases/test_update_todo.py @@ -8,4 +8,4 @@ def test_update_todo_should_return_success(todo_repository: TodoRepositoryInterf id = "dh2109" data = UpdateTodoRequest(title="new title", is_completed=False) result = update_todo_use_case(id, data, user_id="xyz", todo_repository=todo_repository) - assert result.success + assert data.title == result.title diff --git a/generate-api-typescript-client.sh b/generate-api-typescript-client.sh index 5e6b7a2d..efda2710 100755 --- a/generate-api-typescript-client.sh +++ b/generate-api-typescript-client.sh @@ -5,5 +5,5 @@ docker run --ulimit nofile=122880:122880 --rm --network="host" -v ${PWD}/web/src/api:/local openapitools/openapi-generator-cli:v5.1.0 generate \ -i http://127.0.0.1:5000/openapi.json \ -g typescript-axios \ - --additional-properties=useSingleRequestParameter=true,withSeparateModelsAndApi=true,apiPackage=api,modelPackage=models \ + --additional-properties=withSeparateModelsAndApi=true,apiPackage=api,modelPackage=models \ -o /local/generated \ No newline at end of file diff --git a/web/src/api/generated/.openapi-generator/FILES b/web/src/api/generated/.openapi-generator/FILES index ef44509b..41d63b25 100644 --- a/web/src/api/generated/.openapi-generator/FILES +++ b/web/src/api/generated/.openapi-generator/FILES @@ -1,5 +1,6 @@ .gitignore .npmignore +.openapi-generator-ignore api.ts api/health-check-api.ts api/todos-api.ts @@ -9,12 +10,8 @@ common.ts configuration.ts git_push.sh index.ts -models/add-todo-request.ts -models/add-todo-response.ts -models/delete-todo-by-id-response.ts +models/delete-todo-response.ts models/error-response.ts -models/get-todo-all-response.ts -models/get-todo-by-id-response.ts models/index.ts -models/update-todo-request.ts -models/update-todo-response.ts +models/todo-item.ts +models/update-todo.ts diff --git a/web/src/api/generated/api.ts b/web/src/api/generated/api.ts index 283196b8..74d2e0d0 100644 --- a/web/src/api/generated/api.ts +++ b/web/src/api/generated/api.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/api/health-check-api.ts b/web/src/api/generated/api/health-check-api.ts index ccdcaf1f..dd55f1c1 100644 --- a/web/src/api/generated/api/health-check-api.ts +++ b/web/src/api/generated/api/health-check-api.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/api/personal-access-token-api.ts b/web/src/api/generated/api/personal-access-token-api.ts deleted file mode 100644 index 48bc772c..00000000 --- a/web/src/api/generated/api/personal-access-token-api.ts +++ /dev/null @@ -1,459 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios' -import { Configuration } from '../configuration' -// Some imports not used depending on template conditions -// @ts-ignore -import { - DUMMY_BASE_URL, - assertParamExists, - setApiKeyToObject, - setBasicAuthToObject, - setBearerAuthToObject, - setOAuthToObject, - setSearchParams, - serializeDataIfNeeded, - toPathString, - createRequestFunction, -} from '../common' -// @ts-ignore -import { - BASE_PATH, - COLLECTION_FORMATS, - RequestArgs, - BaseAPI, - RequiredError, -} from '../base' -// @ts-ignore -import { AccessLevel } from '../models' -// @ts-ignore -import { DeletePatResponse } from '../models' -// @ts-ignore -import { GetPatByUsernameResponse } from '../models' -// @ts-ignore -import { HTTPValidationError } from '../models' -/** - * PersonalAccessTokenApi - axios parameter creator - * @export - */ -export const PersonalAccessTokenApiAxiosParamCreator = function ( - configuration?: Configuration -) { - return { - /** - * - * @summary New Personal Access Token - * @param {AccessLevel} [scope] - * @param {number} [timeToLive] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - createToken: async ( - scope?: AccessLevel, - timeToLive?: number, - options: any = {} - ): Promise => { - const localVarPath = `/api/v1/token` - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL) - let baseOptions - if (configuration) { - baseOptions = configuration.baseOptions - } - - const localVarRequestOptions = { - method: 'POST', - ...baseOptions, - ...options, - } - const localVarHeaderParameter = {} as any - const localVarQueryParameter = {} as any - - // authentication OAuth2AuthorizationCodeBearer required - // oauth required - await setOAuthToObject( - localVarHeaderParameter, - 'OAuth2AuthorizationCodeBearer', - [], - configuration - ) - - if (scope !== undefined) { - localVarQueryParameter['scope'] = scope - } - - if (timeToLive !== undefined) { - localVarQueryParameter['time_to_live'] = timeToLive - } - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query) - let headersFromBaseOptions = - baseOptions && baseOptions.headers ? baseOptions.headers : {} - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - } - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - } - }, - /** - * - * @summary Revoke Personal Access Token - * @param {string} tokenId - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - tokenDelete: async ( - tokenId: string, - options: any = {} - ): Promise => { - // verify required parameter 'tokenId' is not null or undefined - assertParamExists('tokenDelete', 'tokenId', tokenId) - const localVarPath = `/api/v1/token/token/{token_id}`.replace( - `{${'token_id'}}`, - encodeURIComponent(String(tokenId)) - ) - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL) - let baseOptions - if (configuration) { - baseOptions = configuration.baseOptions - } - - const localVarRequestOptions = { - method: 'DELETE', - ...baseOptions, - ...options, - } - const localVarHeaderParameter = {} as any - const localVarQueryParameter = {} as any - - // authentication OAuth2AuthorizationCodeBearer required - // oauth required - await setOAuthToObject( - localVarHeaderParameter, - 'OAuth2AuthorizationCodeBearer', - [], - configuration - ) - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query) - let headersFromBaseOptions = - baseOptions && baseOptions.headers ? baseOptions.headers : {} - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - } - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - } - }, - /** - * - * @summary List All Pats - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - tokenListAll: async (options: any = {}): Promise => { - const localVarPath = `/api/v1/token/token` - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL) - let baseOptions - if (configuration) { - baseOptions = configuration.baseOptions - } - - const localVarRequestOptions = { - method: 'GET', - ...baseOptions, - ...options, - } - const localVarHeaderParameter = {} as any - const localVarQueryParameter = {} as any - - // authentication OAuth2AuthorizationCodeBearer required - // oauth required - await setOAuthToObject( - localVarHeaderParameter, - 'OAuth2AuthorizationCodeBearer', - [], - configuration - ) - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query) - let headersFromBaseOptions = - baseOptions && baseOptions.headers ? baseOptions.headers : {} - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - } - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - } - }, - } -} - -/** - * PersonalAccessTokenApi - functional programming interface - * @export - */ -export const PersonalAccessTokenApiFp = function ( - configuration?: Configuration -) { - const localVarAxiosParamCreator = - PersonalAccessTokenApiAxiosParamCreator(configuration) - return { - /** - * - * @summary New Personal Access Token - * @param {AccessLevel} [scope] - * @param {number} [timeToLive] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async createToken( - scope?: AccessLevel, - timeToLive?: number, - options?: any - ): Promise< - (axios?: AxiosInstance, basePath?: string) => AxiosPromise - > { - const localVarAxiosArgs = await localVarAxiosParamCreator.createToken( - scope, - timeToLive, - options - ) - return createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration - ) - }, - /** - * - * @summary Revoke Personal Access Token - * @param {string} tokenId - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async tokenDelete( - tokenId: string, - options?: any - ): Promise< - ( - axios?: AxiosInstance, - basePath?: string - ) => AxiosPromise - > { - const localVarAxiosArgs = await localVarAxiosParamCreator.tokenDelete( - tokenId, - options - ) - return createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration - ) - }, - /** - * - * @summary List All Pats - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async tokenListAll( - options?: any - ): Promise< - ( - axios?: AxiosInstance, - basePath?: string - ) => AxiosPromise - > { - const localVarAxiosArgs = await localVarAxiosParamCreator.tokenListAll( - options - ) - return createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration - ) - }, - } -} - -/** - * PersonalAccessTokenApi - factory interface - * @export - */ -export const PersonalAccessTokenApiFactory = function ( - configuration?: Configuration, - basePath?: string, - axios?: AxiosInstance -) { - const localVarFp = PersonalAccessTokenApiFp(configuration) - return { - /** - * - * @summary New Personal Access Token - * @param {AccessLevel} [scope] - * @param {number} [timeToLive] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - createToken( - scope?: AccessLevel, - timeToLive?: number, - options?: any - ): AxiosPromise { - return localVarFp - .createToken(scope, timeToLive, options) - .then((request) => request(axios, basePath)) - }, - /** - * - * @summary Revoke Personal Access Token - * @param {string} tokenId - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - tokenDelete( - tokenId: string, - options?: any - ): AxiosPromise { - return localVarFp - .tokenDelete(tokenId, options) - .then((request) => request(axios, basePath)) - }, - /** - * - * @summary List All Pats - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - tokenListAll(options?: any): AxiosPromise { - return localVarFp - .tokenListAll(options) - .then((request) => request(axios, basePath)) - }, - } -} - -/** - * Request parameters for createToken operation in PersonalAccessTokenApi. - * @export - * @interface PersonalAccessTokenApiCreateTokenRequest - */ -export interface PersonalAccessTokenApiCreateTokenRequest { - /** - * - * @type {AccessLevel} - * @memberof PersonalAccessTokenApiCreateToken - */ - readonly scope?: AccessLevel - - /** - * - * @type {number} - * @memberof PersonalAccessTokenApiCreateToken - */ - readonly timeToLive?: number -} - -/** - * Request parameters for tokenDelete operation in PersonalAccessTokenApi. - * @export - * @interface PersonalAccessTokenApiTokenDeleteRequest - */ -export interface PersonalAccessTokenApiTokenDeleteRequest { - /** - * - * @type {string} - * @memberof PersonalAccessTokenApiTokenDelete - */ - readonly tokenId: string -} - -/** - * PersonalAccessTokenApi - object-oriented interface - * @export - * @class PersonalAccessTokenApi - * @extends {BaseAPI} - */ -export class PersonalAccessTokenApi extends BaseAPI { - /** - * - * @summary New Personal Access Token - * @param {PersonalAccessTokenApiCreateTokenRequest} requestParameters Request parameters. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof PersonalAccessTokenApi - */ - public createToken( - requestParameters: PersonalAccessTokenApiCreateTokenRequest = {}, - options?: any - ) { - return PersonalAccessTokenApiFp(this.configuration) - .createToken( - requestParameters.scope, - requestParameters.timeToLive, - options - ) - .then((request) => request(this.axios, this.basePath)) - } - - /** - * - * @summary Revoke Personal Access Token - * @param {PersonalAccessTokenApiTokenDeleteRequest} requestParameters Request parameters. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof PersonalAccessTokenApi - */ - public tokenDelete( - requestParameters: PersonalAccessTokenApiTokenDeleteRequest, - options?: any - ) { - return PersonalAccessTokenApiFp(this.configuration) - .tokenDelete(requestParameters.tokenId, options) - .then((request) => request(this.axios, this.basePath)) - } - - /** - * - * @summary List All Pats - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof PersonalAccessTokenApi - */ - public tokenListAll(options?: any) { - return PersonalAccessTokenApiFp(this.configuration) - .tokenListAll(options) - .then((request) => request(this.axios, this.basePath)) - } -} diff --git a/web/src/api/generated/api/todos-api.ts b/web/src/api/generated/api/todos-api.ts index 4602732e..17418aad 100644 --- a/web/src/api/generated/api/todos-api.ts +++ b/web/src/api/generated/api/todos-api.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -21,21 +21,13 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj // @ts-ignore import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base'; // @ts-ignore -import { AddTodoRequest } from '../models'; -// @ts-ignore -import { AddTodoResponse } from '../models'; -// @ts-ignore -import { DeleteTodoByIdResponse } from '../models'; +import { DeleteTodoResponse } from '../models'; // @ts-ignore import { ErrorResponse } from '../models'; // @ts-ignore -import { GetTodoAllResponse } from '../models'; -// @ts-ignore -import { GetTodoByIdResponse } from '../models'; +import { TodoItem } from '../models'; // @ts-ignore -import { UpdateTodoRequest } from '../models'; -// @ts-ignore -import { UpdateTodoResponse } from '../models'; +import { UpdateTodo } from '../models'; /** * TodosApi - axios parameter creator * @export @@ -45,13 +37,13 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration /** * * @summary Add Todo - * @param {AddTodoRequest} addTodoRequest + * @param {string} title * @param {*} [options] Override http request option. * @throws {RequiredError} */ - create: async (addTodoRequest: AddTodoRequest, options: any = {}): Promise => { - // verify required parameter 'addTodoRequest' is not null or undefined - assertParamExists('create', 'addTodoRequest', addTodoRequest) + create: async (title: string, options: any = {}): Promise => { + // verify required parameter 'title' is not null or undefined + assertParamExists('create', 'title', title) const localVarPath = `/todos`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -68,14 +60,15 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration // oauth required await setOAuthToObject(localVarHeaderParameter, "OAuth2AuthorizationCodeBearer", [], configuration) + if (title !== undefined) { + localVarQueryParameter['title'] = title; + } - - localVarHeaderParameter['Content-Type'] = 'application/json'; + setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(addTodoRequest, localVarRequestOptions, configuration) return { url: toPathString(localVarUrlObj), @@ -196,15 +189,15 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * * @summary Update Todo * @param {string} id - * @param {UpdateTodoRequest} updateTodoRequest + * @param {UpdateTodo} updateTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - updateById: async (id: string, updateTodoRequest: UpdateTodoRequest, options: any = {}): Promise => { + updateById: async (id: string, updateTodo: UpdateTodo, options: any = {}): Promise => { // verify required parameter 'id' is not null or undefined assertParamExists('updateById', 'id', id) - // verify required parameter 'updateTodoRequest' is not null or undefined - assertParamExists('updateById', 'updateTodoRequest', updateTodoRequest) + // verify required parameter 'updateTodo' is not null or undefined + assertParamExists('updateById', 'updateTodo', updateTodo) const localVarPath = `/todos/{id}` .replace(`{${"id"}}`, encodeURIComponent(String(id))); // use dummy base URL string because the URL constructor only accepts absolute URLs. @@ -229,7 +222,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(updateTodoRequest, localVarRequestOptions, configuration) + localVarRequestOptions.data = serializeDataIfNeeded(updateTodo, localVarRequestOptions, configuration) return { url: toPathString(localVarUrlObj), @@ -249,12 +242,12 @@ export const TodosApiFp = function(configuration?: Configuration) { /** * * @summary Add Todo - * @param {AddTodoRequest} addTodoRequest + * @param {string} title * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async create(addTodoRequest: AddTodoRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.create(addTodoRequest, options); + async create(title: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.create(title, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, /** @@ -264,7 +257,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async deleteById(id: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async deleteById(id: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.deleteById(id, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -274,7 +267,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getAll(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + async getAll(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { const localVarAxiosArgs = await localVarAxiosParamCreator.getAll(options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -285,7 +278,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getById(id: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async getById(id: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.getById(id, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -293,12 +286,12 @@ export const TodosApiFp = function(configuration?: Configuration) { * * @summary Update Todo * @param {string} id - * @param {UpdateTodoRequest} updateTodoRequest + * @param {UpdateTodo} updateTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async updateById(id: string, updateTodoRequest: UpdateTodoRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.updateById(id, updateTodoRequest, options); + async updateById(id: string, updateTodo: UpdateTodo, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.updateById(id, updateTodo, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, } @@ -314,12 +307,12 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath /** * * @summary Add Todo - * @param {AddTodoRequest} addTodoRequest + * @param {string} title * @param {*} [options] Override http request option. * @throws {RequiredError} */ - create(addTodoRequest: AddTodoRequest, options?: any): AxiosPromise { - return localVarFp.create(addTodoRequest, options).then((request) => request(axios, basePath)); + create(title: string, options?: any): AxiosPromise { + return localVarFp.create(title, options).then((request) => request(axios, basePath)); }, /** * @@ -328,7 +321,7 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath * @param {*} [options] Override http request option. * @throws {RequiredError} */ - deleteById(id: string, options?: any): AxiosPromise { + deleteById(id: string, options?: any): AxiosPromise { return localVarFp.deleteById(id, options).then((request) => request(axios, basePath)); }, /** @@ -337,7 +330,7 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getAll(options?: any): AxiosPromise> { + getAll(options?: any): AxiosPromise> { return localVarFp.getAll(options).then((request) => request(axios, basePath)); }, /** @@ -347,86 +340,23 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getById(id: string, options?: any): AxiosPromise { + getById(id: string, options?: any): AxiosPromise { return localVarFp.getById(id, options).then((request) => request(axios, basePath)); }, /** * * @summary Update Todo * @param {string} id - * @param {UpdateTodoRequest} updateTodoRequest + * @param {UpdateTodo} updateTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - updateById(id: string, updateTodoRequest: UpdateTodoRequest, options?: any): AxiosPromise { - return localVarFp.updateById(id, updateTodoRequest, options).then((request) => request(axios, basePath)); + updateById(id: string, updateTodo: UpdateTodo, options?: any): AxiosPromise { + return localVarFp.updateById(id, updateTodo, options).then((request) => request(axios, basePath)); }, }; }; -/** - * Request parameters for create operation in TodosApi. - * @export - * @interface TodosApiCreateRequest - */ -export interface TodosApiCreateRequest { - /** - * - * @type {AddTodoRequest} - * @memberof TodosApiCreate - */ - readonly addTodoRequest: AddTodoRequest -} - -/** - * Request parameters for deleteById operation in TodosApi. - * @export - * @interface TodosApiDeleteByIdRequest - */ -export interface TodosApiDeleteByIdRequest { - /** - * - * @type {string} - * @memberof TodosApiDeleteById - */ - readonly id: string -} - -/** - * Request parameters for getById operation in TodosApi. - * @export - * @interface TodosApiGetByIdRequest - */ -export interface TodosApiGetByIdRequest { - /** - * - * @type {string} - * @memberof TodosApiGetById - */ - readonly id: string -} - -/** - * Request parameters for updateById operation in TodosApi. - * @export - * @interface TodosApiUpdateByIdRequest - */ -export interface TodosApiUpdateByIdRequest { - /** - * - * @type {string} - * @memberof TodosApiUpdateById - */ - readonly id: string - - /** - * - * @type {UpdateTodoRequest} - * @memberof TodosApiUpdateById - */ - readonly updateTodoRequest: UpdateTodoRequest -} - /** * TodosApi - object-oriented interface * @export @@ -437,25 +367,25 @@ export class TodosApi extends BaseAPI { /** * * @summary Add Todo - * @param {TodosApiCreateRequest} requestParameters Request parameters. + * @param {string} title * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TodosApi */ - public create(requestParameters: TodosApiCreateRequest, options?: any) { - return TodosApiFp(this.configuration).create(requestParameters.addTodoRequest, options).then((request) => request(this.axios, this.basePath)); + public create(title: string, options?: any) { + return TodosApiFp(this.configuration).create(title, options).then((request) => request(this.axios, this.basePath)); } /** * * @summary Delete Todo By Id - * @param {TodosApiDeleteByIdRequest} requestParameters Request parameters. + * @param {string} id * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TodosApi */ - public deleteById(requestParameters: TodosApiDeleteByIdRequest, options?: any) { - return TodosApiFp(this.configuration).deleteById(requestParameters.id, options).then((request) => request(this.axios, this.basePath)); + public deleteById(id: string, options?: any) { + return TodosApiFp(this.configuration).deleteById(id, options).then((request) => request(this.axios, this.basePath)); } /** @@ -472,24 +402,25 @@ export class TodosApi extends BaseAPI { /** * * @summary Get Todo By Id - * @param {TodosApiGetByIdRequest} requestParameters Request parameters. + * @param {string} id * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TodosApi */ - public getById(requestParameters: TodosApiGetByIdRequest, options?: any) { - return TodosApiFp(this.configuration).getById(requestParameters.id, options).then((request) => request(this.axios, this.basePath)); + public getById(id: string, options?: any) { + return TodosApiFp(this.configuration).getById(id, options).then((request) => request(this.axios, this.basePath)); } /** * * @summary Update Todo - * @param {TodosApiUpdateByIdRequest} requestParameters Request parameters. + * @param {string} id + * @param {UpdateTodo} updateTodo * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TodosApi */ - public updateById(requestParameters: TodosApiUpdateByIdRequest, options?: any) { - return TodosApiFp(this.configuration).updateById(requestParameters.id, requestParameters.updateTodoRequest, options).then((request) => request(this.axios, this.basePath)); + public updateById(id: string, updateTodo: UpdateTodo, options?: any) { + return TodosApiFp(this.configuration).updateById(id, updateTodo, options).then((request) => request(this.axios, this.basePath)); } } diff --git a/web/src/api/generated/api/whoami-api.ts b/web/src/api/generated/api/whoami-api.ts index c20ed6af..55ebe7a2 100644 --- a/web/src/api/generated/api/whoami-api.ts +++ b/web/src/api/generated/api/whoami-api.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/base.ts b/web/src/api/generated/base.ts index 1e702006..e479ee00 100644 --- a/web/src/api/generated/base.ts +++ b/web/src/api/generated/base.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/common.ts b/web/src/api/generated/common.ts index e17affb3..8fda6c63 100644 --- a/web/src/api/generated/common.ts +++ b/web/src/api/generated/common.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/configuration.ts b/web/src/api/generated/configuration.ts index 0839251f..205cc90e 100644 --- a/web/src/api/generated/configuration.ts +++ b/web/src/api/generated/configuration.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/index.ts b/web/src/api/generated/index.ts index 530ea503..636d9151 100644 --- a/web/src/api/generated/index.ts +++ b/web/src/api/generated/index.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/models/access-level.ts b/web/src/api/generated/models/access-level.ts deleted file mode 100644 index 86df01a6..00000000 --- a/web/src/api/generated/models/access-level.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -/** - * An enumeration. - * @export - * @enum {string} - */ -export enum AccessLevel { - WRITE = 2, - READ = 1, - NONE = 0, -} diff --git a/web/src/api/generated/models/add-todo-request.ts b/web/src/api/generated/models/add-todo-request.ts deleted file mode 100644 index df7b5cbf..00000000 --- a/web/src/api/generated/models/add-todo-request.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface AddTodoRequest - */ -export interface AddTodoRequest { - /** - * - * @type {string} - * @memberof AddTodoRequest - */ - title?: string; -} - - diff --git a/web/src/api/generated/models/delete-pat-response.ts b/web/src/api/generated/models/delete-pat-response.ts deleted file mode 100644 index 03ccdd1d..00000000 --- a/web/src/api/generated/models/delete-pat-response.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -/** - * - * @export - * @interface DeletePatResponse - */ -export interface DeletePatResponse { - /** - * - * @type {boolean} - * @memberof DeletePatResponse - */ - success: boolean -} diff --git a/web/src/api/generated/models/delete-todo-by-id-response.ts b/web/src/api/generated/models/delete-todo-by-id-response.ts deleted file mode 100644 index 5fc0151a..00000000 --- a/web/src/api/generated/models/delete-todo-by-id-response.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface DeleteTodoByIdResponse - */ -export interface DeleteTodoByIdResponse { - /** - * - * @type {boolean} - * @memberof DeleteTodoByIdResponse - */ - success: boolean; -} - - diff --git a/web/src/api/generated/models/delete-todo-response.ts b/web/src/api/generated/models/delete-todo-response.ts new file mode 100644 index 00000000..3fa13d3b --- /dev/null +++ b/web/src/api/generated/models/delete-todo-response.ts @@ -0,0 +1,31 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Template FastAPI React + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * + * The version of the OpenAPI document: 1.2.1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface DeleteTodoResponse + */ +export interface DeleteTodoResponse { + /** + * + * @type {boolean} + * @memberof DeleteTodoResponse + */ + success: boolean; +} + + diff --git a/web/src/api/generated/models/error-response.ts b/web/src/api/generated/models/error-response.ts index 6cccf46f..964b370e 100644 --- a/web/src/api/generated/models/error-response.ts +++ b/web/src/api/generated/models/error-response.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/models/get-pat-by-username-response.ts b/web/src/api/generated/models/get-pat-by-username-response.ts deleted file mode 100644 index 7911580d..00000000 --- a/web/src/api/generated/models/get-pat-by-username-response.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -/** - * - * @export - * @interface GetPatByUsernameResponse - */ -export interface GetPatByUsernameResponse { - /** - * - * @type {string} - * @memberof GetPatByUsernameResponse - */ - id: string - /** - * - * @type {string} - * @memberof GetPatByUsernameResponse - */ - title: string -} diff --git a/web/src/api/generated/models/get-todo-all-response.ts b/web/src/api/generated/models/get-todo-all-response.ts deleted file mode 100644 index b7f153c3..00000000 --- a/web/src/api/generated/models/get-todo-all-response.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface GetTodoAllResponse - */ -export interface GetTodoAllResponse { - /** - * - * @type {string} - * @memberof GetTodoAllResponse - */ - id: string; - /** - * - * @type {string} - * @memberof GetTodoAllResponse - */ - title: string; - /** - * - * @type {boolean} - * @memberof GetTodoAllResponse - */ - is_completed: boolean; -} - - diff --git a/web/src/api/generated/models/get-todo-by-id-response.ts b/web/src/api/generated/models/get-todo-by-id-response.ts deleted file mode 100644 index 34b931c1..00000000 --- a/web/src/api/generated/models/get-todo-by-id-response.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface GetTodoByIdResponse - */ -export interface GetTodoByIdResponse { - /** - * - * @type {string} - * @memberof GetTodoByIdResponse - */ - id: string; - /** - * - * @type {string} - * @memberof GetTodoByIdResponse - */ - title: string; - /** - * - * @type {boolean} - * @memberof GetTodoByIdResponse - */ - is_completed?: boolean; -} - - diff --git a/web/src/api/generated/models/httpvalidation-error.ts b/web/src/api/generated/models/httpvalidation-error.ts deleted file mode 100644 index 29a00744..00000000 --- a/web/src/api/generated/models/httpvalidation-error.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import { ValidationError } from './validation-error' - -/** - * - * @export - * @interface HTTPValidationError - */ -export interface HTTPValidationError { - /** - * - * @type {Array} - * @memberof HTTPValidationError - */ - detail?: Array -} diff --git a/web/src/api/generated/models/index.ts b/web/src/api/generated/models/index.ts index 3954695d..ddfc4dcc 100644 --- a/web/src/api/generated/models/index.ts +++ b/web/src/api/generated/models/index.ts @@ -1,8 +1,4 @@ -export * from './add-todo-request'; -export * from './add-todo-response'; -export * from './delete-todo-by-id-response'; +export * from './delete-todo-response'; export * from './error-response'; -export * from './get-todo-all-response'; -export * from './get-todo-by-id-response'; -export * from './update-todo-request'; -export * from './update-todo-response'; +export * from './todo-item'; +export * from './update-todo'; diff --git a/web/src/api/generated/models/add-todo-response.ts b/web/src/api/generated/models/todo-item.ts similarity index 50% rename from web/src/api/generated/models/add-todo-response.ts rename to web/src/api/generated/models/todo-item.ts index 7fb60a77..8ec6930c 100644 --- a/web/src/api/generated/models/add-todo-response.ts +++ b/web/src/api/generated/models/todo-item.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.2.1 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -17,25 +17,25 @@ /** * * @export - * @interface AddTodoResponse + * @interface TodoItem */ -export interface AddTodoResponse { +export interface TodoItem { /** * * @type {string} - * @memberof AddTodoResponse + * @memberof TodoItem */ id: string; /** * * @type {string} - * @memberof AddTodoResponse + * @memberof TodoItem */ title: string; /** * * @type {boolean} - * @memberof AddTodoResponse + * @memberof TodoItem */ is_completed?: boolean; } diff --git a/web/src/api/generated/models/update-todo-request.ts b/web/src/api/generated/models/update-todo-request.ts deleted file mode 100644 index 9a5aae30..00000000 --- a/web/src/api/generated/models/update-todo-request.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface UpdateTodoRequest - */ -export interface UpdateTodoRequest { - /** - * - * @type {string} - * @memberof UpdateTodoRequest - */ - title?: string; - /** - * - * @type {boolean} - * @memberof UpdateTodoRequest - */ - is_completed: boolean; -} - - diff --git a/web/src/api/generated/models/update-todo-response.ts b/web/src/api/generated/models/update-todo-response.ts deleted file mode 100644 index 4b7fd830..00000000 --- a/web/src/api/generated/models/update-todo-response.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface UpdateTodoResponse - */ -export interface UpdateTodoResponse { - /** - * - * @type {boolean} - * @memberof UpdateTodoResponse - */ - success: boolean; -} - - diff --git a/web/src/api/generated/models/update-todo.ts b/web/src/api/generated/models/update-todo.ts new file mode 100644 index 00000000..77f36e56 --- /dev/null +++ b/web/src/api/generated/models/update-todo.ts @@ -0,0 +1,37 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Template FastAPI React + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * + * The version of the OpenAPI document: 1.2.1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface UpdateTodo + */ +export interface UpdateTodo { + /** + * + * @type {string} + * @memberof UpdateTodo + */ + title: string; + /** + * + * @type {boolean} + * @memberof UpdateTodo + */ + is_completed?: boolean; +} + + diff --git a/web/src/api/generated/models/validation-error.ts b/web/src/api/generated/models/validation-error.ts deleted file mode 100644 index b902a124..00000000 --- a/web/src/api/generated/models/validation-error.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -/** - * - * @export - * @interface ValidationError - */ -export interface ValidationError { - /** - * - * @type {Array} - * @memberof ValidationError - */ - loc: Array - /** - * - * @type {string} - * @memberof ValidationError - */ - msg: string - /** - * - * @type {string} - * @memberof ValidationError - */ - type: string -} diff --git a/web/src/features/todos/todo-list/TodoItem.tsx b/web/src/features/todos/todo-list/TodoItem.tsx index eb623988..4c27be8b 100644 --- a/web/src/features/todos/todo-list/TodoItem.tsx +++ b/web/src/features/todos/todo-list/TodoItem.tsx @@ -7,10 +7,10 @@ import { Tooltip, } from '@equinor/eds-core-react' import { undo, done, remove_outlined } from '@equinor/eds-icons' -import { AddTodoResponse } from '../../../api/generated' +import { TodoItem } from '../../../api/generated' -const TodoItem = (props: { - todo: AddTodoResponse +const TodoItemElement = (props: { + todo: TodoItem onToggle: (id: string) => void onRemove: (id: string) => void }) => { @@ -49,4 +49,4 @@ const TodoItem = (props: { ) } -export default TodoItem +export default TodoItemElement diff --git a/web/src/features/todos/todo-list/TodoList.tsx b/web/src/features/todos/todo-list/TodoList.tsx index 34084e58..a73bd2df 100644 --- a/web/src/features/todos/todo-list/TodoList.tsx +++ b/web/src/features/todos/todo-list/TodoList.tsx @@ -1,8 +1,8 @@ import useTodos from '../../../hooks/useTodos' import { FormEventHandler, useState } from 'react' import { Button, Input, Progress } from '@equinor/eds-core-react' -import TodoItem from './TodoItem' -import { AddTodoResponse } from '../../../api/generated' +import TodoItemElement from './TodoItem' +import { TodoItem } from '../../../api/generated' import { StyledTodoList, StyledInput, @@ -42,14 +42,16 @@ const TodoList = () => { const { todos, isLoading, addItem, removeItem, toggleItem, error } = useTodos() + console.log(error) + if (error) return
{error?.response?.data.message ?? 'Something went wrong!'}
return ( - {todos?.map((todo: AddTodoResponse) => ( - ( + void removeItem: (id: string) => void toggleItem: (id: string) => void error: AxiosError | null } => { - const [todos, setTodos] = useState([]) + const [todos, setTodos] = useState([]) const [isLoading, setLoading] = useState(true) const [error, setError] = useState | null>(null) const todoAPI = useTodoAPI() @@ -28,13 +28,9 @@ const useTodos = (): { const addItem = (title: string) => { setLoading(true) todoAPI - .create({ - addTodoRequest: { - title: title, - }, - }) + .create(title) .then((response) => { - const item: AddTodoResponse = response.data + const item: TodoItem = response.data setTodos([...todos, item]) }) .catch((error: AxiosError) => { @@ -46,10 +42,10 @@ const useTodos = (): { const removeItem = (id: string) => { setLoading(true) todoAPI - .deleteById({ id: id }) + .deleteById(id) .then(() => { const tmpTodos = todos.filter( - (todoItem: AddTodoResponse) => todoItem.id !== id + (todoItem: TodoItem) => todoItem.id !== id ) setTodos(tmpTodos) }) @@ -59,17 +55,12 @@ const useTodos = (): { const toggleItem = (id: string) => { setLoading(true) - const index: number = todos.findIndex( - (item: AddTodoResponse) => item.id === id - ) + const index: number = todos.findIndex((item: TodoItem) => item.id === id) const todoItem = todos[index] todoAPI - .updateById({ - id: id, - updateTodoRequest: { - is_completed: !todoItem.is_completed, - title: todoItem.title, - }, + .updateById(id, { + is_completed: !todoItem.is_completed, + title: todoItem.title, }) .then(() => { const items = todos From 4c94e478bc09d9b4cd65f2da4d8ad7546a218c68 Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Mon, 14 Nov 2022 18:37:15 +0100 Subject: [PATCH 02/11] test: add include, exclude and rename for filter_fields decorator --- .../tests/unit/common/test_entity_mapper.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 api/src/tests/unit/common/test_entity_mapper.py diff --git a/api/src/tests/unit/common/test_entity_mapper.py b/api/src/tests/unit/common/test_entity_mapper.py new file mode 100644 index 00000000..385b996b --- /dev/null +++ b/api/src/tests/unit/common/test_entity_mapper.py @@ -0,0 +1,38 @@ +from pydantic import BaseModel + +from common.entity_mapper import filter_fields + + +class MyEntity(BaseModel): + a: int + b: str + + +def test_include_fields(): + @filter_fields() + class MyModel(MyEntity): + class Config: + include = ["a"] + + schema = MyModel.schema() + assert schema["properties"] == {"a": {"title": "A", "type": "integer"}} + + +def test_exclude_fields(): + @filter_fields() + class MyModel(MyEntity): + class Config: + exclude = ["b"] + + schema = MyModel.schema() + assert schema["properties"] == {"a": {"title": "A", "type": "integer"}} + + +def test_rename(): + @filter_fields(name="MySpecialModel") + class MyModel(MyEntity): + pass + + schema = MyModel.schema() + + assert schema["title"] == "MySpecialModel" From 318ab2481f82126ae125a97ff81827b230bc0f94 Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Tue, 15 Nov 2022 10:44:45 +0100 Subject: [PATCH 03/11] refactor: add request model for add todo --- api/src/features/todo/shared_models.py | 2 ++ api/src/features/todo/todo_feature.py | 5 +-- api/src/features/todo/use_cases/add_todo.py | 12 +++---- .../features/todo/use_cases/update_todo.py | 2 ++ .../tests/unit/common/test_entity_mapper.py | 7 ++++ .../features/todo/use_cases/test_add_todo.py | 8 +++-- .../api/generated/.openapi-generator/FILES | 1 + web/src/api/generated/api/todos-api.ts | 35 ++++++++++--------- web/src/api/generated/models/add-todo.ts | 31 ++++++++++++++++ web/src/api/generated/models/index.ts | 1 + web/src/hooks/useTodos.tsx | 2 +- 11 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 web/src/api/generated/models/add-todo.ts diff --git a/api/src/features/todo/shared_models.py b/api/src/features/todo/shared_models.py index c7dd030f..fa058659 100644 --- a/api/src/features/todo/shared_models.py +++ b/api/src/features/todo/shared_models.py @@ -2,6 +2,8 @@ from entities.TodoItem import TodoItem +# An alternative solution is to use Pydantic BaseModel +# and to duplicate all the fields except user_id @filter_fields(name="TodoItem") class TodoItemResponseModel(TodoItem): class Config: diff --git a/api/src/features/todo/todo_feature.py b/api/src/features/todo/todo_feature.py index b9c8b488..1b4d3815 100644 --- a/api/src/features/todo/todo_feature.py +++ b/api/src/features/todo/todo_feature.py @@ -10,6 +10,7 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) +from features.todo.use_cases.add_todo import AddTodoRequest from features.todo.use_cases.delete_todo_by_id import DeleteTodoResponse from .shared_models import TodoItemResponseModel @@ -25,11 +26,11 @@ @router.post("", operation_id="create", response_model=TodoItemResponseModel) @create_response(JSONResponse) def add_todo( - title: str, + data: AddTodoRequest, user: User = Depends(auth_with_jwt), todo_repository: TodoRepositoryInterface = Depends(get_todo_repository), ): - return add_todo_use_case(title=title, user_id=user.user_id, todo_repository=todo_repository).dict() + return add_todo_use_case(data=data, user_id=user.user_id, todo_repository=todo_repository).dict() @router.get("/{id}", operation_id="get_by_id", response_model=TodoItemResponseModel) diff --git a/api/src/features/todo/use_cases/add_todo.py b/api/src/features/todo/use_cases/add_todo.py index eb91ffac..831d4eed 100644 --- a/api/src/features/todo/use_cases/add_todo.py +++ b/api/src/features/todo/use_cases/add_todo.py @@ -4,21 +4,21 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from entities.TodoItem import TodoItem, title_field +from entities.TodoItem import TodoItem from features.todo.shared_models import TodoItemResponseModel +# An alternative solution is to use Pydantic BaseModel +# and to duplicate the title and is_completed fields @filter_fields(name="AddTodo") -class AddTodoRequestModel(TodoItem): +class AddTodoRequest(TodoItem): class Config: include = ["title"] def add_todo_use_case( - user_id: str, - todo_repository: TodoRepositoryInterface, - title: str = title_field, + data: AddTodoRequest, user_id: str, todo_repository: TodoRepositoryInterface ) -> TodoItemResponseModel: - todo_item = TodoItem(id=str(uuid.uuid4()), title=title, user_id=user_id) + todo_item = TodoItem(id=str(uuid.uuid4()), title=data.title, user_id=user_id) todo_repository.create(todo_item) return TodoItemResponseModel.parse_obj(todo_item) diff --git a/api/src/features/todo/use_cases/update_todo.py b/api/src/features/todo/use_cases/update_todo.py index 9af4dc61..7682cc8e 100644 --- a/api/src/features/todo/use_cases/update_todo.py +++ b/api/src/features/todo/use_cases/update_todo.py @@ -7,6 +7,8 @@ from features.todo.shared_models import TodoItemResponseModel +# An alternative solution is to use Pydantic BaseModel +# and to duplicate the title and is_completed fields @filter_fields(name="UpdateTodo") class UpdateTodoRequest(TodoItem): class Config: diff --git a/api/src/tests/unit/common/test_entity_mapper.py b/api/src/tests/unit/common/test_entity_mapper.py index 385b996b..06eeb881 100644 --- a/api/src/tests/unit/common/test_entity_mapper.py +++ b/api/src/tests/unit/common/test_entity_mapper.py @@ -1,3 +1,5 @@ +from dataclasses import dataclass + from pydantic import BaseModel from common.entity_mapper import filter_fields @@ -8,6 +10,11 @@ class MyEntity(BaseModel): b: str +@dataclass +class InventoryItem: + a: int + + def test_include_fields(): @filter_fields() class MyModel(MyEntity): diff --git a/api/src/tests/unit/features/todo/use_cases/test_add_todo.py b/api/src/tests/unit/features/todo/use_cases/test_add_todo.py index 44502c25..51fe04d2 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_add_todo.py +++ b/api/src/tests/unit/features/todo/use_cases/test_add_todo.py @@ -4,16 +4,18 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.add_todo import add_todo_use_case +from features.todo.use_cases.add_todo import AddTodoRequest, add_todo_use_case def test_add_with_valid_title_should_return_todo(todo_repository: TodoRepositoryInterface): title = "new todo" - result = add_todo_use_case(title=title, user_id="xyz", todo_repository=todo_repository) + data = AddTodoRequest(title=title) + result = add_todo_use_case(data=data, user_id="xyz", todo_repository=todo_repository) assert result.title == title def test_add_with_empty_title_should_throw_validation_error(todo_repository: TodoRepositoryInterface): with pytest.raises(ValidationError): title = "" - add_todo_use_case(title=title, user_id="xyz", todo_repository=todo_repository) + data = AddTodoRequest(title=title) + add_todo_use_case(data=data, user_id="xyz", todo_repository=todo_repository) diff --git a/web/src/api/generated/.openapi-generator/FILES b/web/src/api/generated/.openapi-generator/FILES index 41d63b25..24320353 100644 --- a/web/src/api/generated/.openapi-generator/FILES +++ b/web/src/api/generated/.openapi-generator/FILES @@ -10,6 +10,7 @@ common.ts configuration.ts git_push.sh index.ts +models/add-todo.ts models/delete-todo-response.ts models/error-response.ts models/index.ts diff --git a/web/src/api/generated/api/todos-api.ts b/web/src/api/generated/api/todos-api.ts index 17418aad..cb081cb1 100644 --- a/web/src/api/generated/api/todos-api.ts +++ b/web/src/api/generated/api/todos-api.ts @@ -21,6 +21,8 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj // @ts-ignore import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base'; // @ts-ignore +import { AddTodo } from '../models'; +// @ts-ignore import { DeleteTodoResponse } from '../models'; // @ts-ignore import { ErrorResponse } from '../models'; @@ -37,13 +39,13 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration /** * * @summary Add Todo - * @param {string} title + * @param {AddTodo} addTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - create: async (title: string, options: any = {}): Promise => { - // verify required parameter 'title' is not null or undefined - assertParamExists('create', 'title', title) + create: async (addTodo: AddTodo, options: any = {}): Promise => { + // verify required parameter 'addTodo' is not null or undefined + assertParamExists('create', 'addTodo', addTodo) const localVarPath = `/todos`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -60,15 +62,14 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration // oauth required await setOAuthToObject(localVarHeaderParameter, "OAuth2AuthorizationCodeBearer", [], configuration) - if (title !== undefined) { - localVarQueryParameter['title'] = title; - } - + localVarHeaderParameter['Content-Type'] = 'application/json'; + setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(addTodo, localVarRequestOptions, configuration) return { url: toPathString(localVarUrlObj), @@ -242,12 +243,12 @@ export const TodosApiFp = function(configuration?: Configuration) { /** * * @summary Add Todo - * @param {string} title + * @param {AddTodo} addTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async create(title: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.create(title, options); + async create(addTodo: AddTodo, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.create(addTodo, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, /** @@ -307,12 +308,12 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath /** * * @summary Add Todo - * @param {string} title + * @param {AddTodo} addTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - create(title: string, options?: any): AxiosPromise { - return localVarFp.create(title, options).then((request) => request(axios, basePath)); + create(addTodo: AddTodo, options?: any): AxiosPromise { + return localVarFp.create(addTodo, options).then((request) => request(axios, basePath)); }, /** * @@ -367,13 +368,13 @@ export class TodosApi extends BaseAPI { /** * * @summary Add Todo - * @param {string} title + * @param {AddTodo} addTodo * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TodosApi */ - public create(title: string, options?: any) { - return TodosApiFp(this.configuration).create(title, options).then((request) => request(this.axios, this.basePath)); + public create(addTodo: AddTodo, options?: any) { + return TodosApiFp(this.configuration).create(addTodo, options).then((request) => request(this.axios, this.basePath)); } /** diff --git a/web/src/api/generated/models/add-todo.ts b/web/src/api/generated/models/add-todo.ts new file mode 100644 index 00000000..3cd6a0bf --- /dev/null +++ b/web/src/api/generated/models/add-todo.ts @@ -0,0 +1,31 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Template FastAPI React + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * + * The version of the OpenAPI document: 1.2.1 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface AddTodo + */ +export interface AddTodo { + /** + * + * @type {string} + * @memberof AddTodo + */ + title: string; +} + + diff --git a/web/src/api/generated/models/index.ts b/web/src/api/generated/models/index.ts index ddfc4dcc..2be8ca9b 100644 --- a/web/src/api/generated/models/index.ts +++ b/web/src/api/generated/models/index.ts @@ -1,3 +1,4 @@ +export * from './add-todo'; export * from './delete-todo-response'; export * from './error-response'; export * from './todo-item'; diff --git a/web/src/hooks/useTodos.tsx b/web/src/hooks/useTodos.tsx index ce474fec..c2fb6d31 100644 --- a/web/src/hooks/useTodos.tsx +++ b/web/src/hooks/useTodos.tsx @@ -28,7 +28,7 @@ const useTodos = (): { const addItem = (title: string) => { setLoading(true) todoAPI - .create(title) + .create({ title: title }) .then((response) => { const item: TodoItem = response.data setTodos([...todos, item]) From 944d6d2cf1858fb4bba467523fce9b5593b074b5 Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Tue, 15 Nov 2022 10:46:21 +0100 Subject: [PATCH 04/11] refactor: remove entities (need to rebase after PR finished) --- api/src/entities/TodoItem.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/api/src/entities/TodoItem.py b/api/src/entities/TodoItem.py index 0327d383..09b0fc8b 100644 --- a/api/src/entities/TodoItem.py +++ b/api/src/entities/TodoItem.py @@ -1,7 +1,5 @@ from __future__ import annotations -from typing import List - from pydantic import BaseModel, Field title_field = Field( @@ -9,17 +7,6 @@ ) -class User(BaseModel): - id: str - todos: List[TodoList] - - -class TodoList(BaseModel): - id: str - user: User - items: List[TodoItem] - - class TodoItem(BaseModel): id: str user_id: str From da0d4d1bf36d05610e470b5b041a9e451508c00a Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Tue, 15 Nov 2022 10:47:19 +0100 Subject: [PATCH 05/11] refactor: remove console log (need to rebase after PR) --- web/src/features/todos/todo-list/TodoList.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/web/src/features/todos/todo-list/TodoList.tsx b/web/src/features/todos/todo-list/TodoList.tsx index a73bd2df..232976da 100644 --- a/web/src/features/todos/todo-list/TodoList.tsx +++ b/web/src/features/todos/todo-list/TodoList.tsx @@ -42,8 +42,6 @@ const TodoList = () => { const { todos, isLoading, addItem, removeItem, toggleItem, error } = useTodos() - console.log(error) - if (error) return
{error?.response?.data.message ?? 'Something went wrong!'}
From 8a9fcc5c5cb10f34752f90ca9ce60e8a8a952a20 Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Tue, 15 Nov 2022 11:52:34 +0100 Subject: [PATCH 06/11] refactor: re-generate API again (must rebase after PR) --- api/src/entities/TodoItem.py | 2 - api/src/features/todo/todo_feature.py | 5 +-- api/src/features/todo/use_cases/add_todo.py | 4 +- .../features/todo/use_cases/test_add_todo.py | 6 +-- generate-api-typescript-client.sh | 2 +- .../api/generated/.openapi-generator/VERSION | 2 +- web/src/api/generated/api/health-check-api.ts | 10 ++--- web/src/api/generated/api/todos-api.ts | 42 +++++++++---------- web/src/api/generated/api/whoami-api.ts | 10 ++--- web/src/api/generated/base.ts | 4 +- web/src/api/generated/common.ts | 42 ++++++++++++------- web/src/api/generated/git_push.sh | 7 ++-- web/src/api/generated/models/add-todo.ts | 3 +- .../generated/models/delete-todo-response.ts | 3 +- .../api/generated/models/error-response.ts | 11 +++-- web/src/api/generated/models/todo-item.ts | 7 ++-- web/src/api/generated/models/update-todo.ts | 5 +-- 17 files changed, 83 insertions(+), 82 deletions(-) diff --git a/api/src/entities/TodoItem.py b/api/src/entities/TodoItem.py index 09b0fc8b..7e8c4969 100644 --- a/api/src/entities/TodoItem.py +++ b/api/src/entities/TodoItem.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from pydantic import BaseModel, Field title_field = Field( diff --git a/api/src/features/todo/todo_feature.py b/api/src/features/todo/todo_feature.py index 1b4d3815..cf76a25f 100644 --- a/api/src/features/todo/todo_feature.py +++ b/api/src/features/todo/todo_feature.py @@ -10,11 +10,10 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.add_todo import AddTodoRequest from features.todo.use_cases.delete_todo_by_id import DeleteTodoResponse from .shared_models import TodoItemResponseModel -from .use_cases.add_todo import add_todo_use_case +from .use_cases.add_todo import AddTodoRequestModel, add_todo_use_case from .use_cases.delete_todo_by_id import delete_todo_use_case from .use_cases.get_todo_all import get_todo_all_use_case from .use_cases.get_todo_by_id import get_todo_by_id_use_case @@ -26,7 +25,7 @@ @router.post("", operation_id="create", response_model=TodoItemResponseModel) @create_response(JSONResponse) def add_todo( - data: AddTodoRequest, + data: AddTodoRequestModel, user: User = Depends(auth_with_jwt), todo_repository: TodoRepositoryInterface = Depends(get_todo_repository), ): diff --git a/api/src/features/todo/use_cases/add_todo.py b/api/src/features/todo/use_cases/add_todo.py index 831d4eed..040ef3db 100644 --- a/api/src/features/todo/use_cases/add_todo.py +++ b/api/src/features/todo/use_cases/add_todo.py @@ -11,13 +11,13 @@ # An alternative solution is to use Pydantic BaseModel # and to duplicate the title and is_completed fields @filter_fields(name="AddTodo") -class AddTodoRequest(TodoItem): +class AddTodoRequestModel(TodoItem): class Config: include = ["title"] def add_todo_use_case( - data: AddTodoRequest, user_id: str, todo_repository: TodoRepositoryInterface + data: AddTodoRequestModel, user_id: str, todo_repository: TodoRepositoryInterface ) -> TodoItemResponseModel: todo_item = TodoItem(id=str(uuid.uuid4()), title=data.title, user_id=user_id) todo_repository.create(todo_item) diff --git a/api/src/tests/unit/features/todo/use_cases/test_add_todo.py b/api/src/tests/unit/features/todo/use_cases/test_add_todo.py index 51fe04d2..15b98d31 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_add_todo.py +++ b/api/src/tests/unit/features/todo/use_cases/test_add_todo.py @@ -4,12 +4,12 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.add_todo import AddTodoRequest, add_todo_use_case +from features.todo.use_cases.add_todo import AddTodoRequestModel, add_todo_use_case def test_add_with_valid_title_should_return_todo(todo_repository: TodoRepositoryInterface): title = "new todo" - data = AddTodoRequest(title=title) + data = AddTodoRequestModel(title=title) result = add_todo_use_case(data=data, user_id="xyz", todo_repository=todo_repository) assert result.title == title @@ -17,5 +17,5 @@ def test_add_with_valid_title_should_return_todo(todo_repository: TodoRepository def test_add_with_empty_title_should_throw_validation_error(todo_repository: TodoRepositoryInterface): with pytest.raises(ValidationError): title = "" - data = AddTodoRequest(title=title) + data = AddTodoRequestModel(title=title) add_todo_use_case(data=data, user_id="xyz", todo_repository=todo_repository) diff --git a/generate-api-typescript-client.sh b/generate-api-typescript-client.sh index efda2710..14f66be2 100755 --- a/generate-api-typescript-client.sh +++ b/generate-api-typescript-client.sh @@ -2,7 +2,7 @@ # This requires the API to be running on localhost port 5000 -docker run --ulimit nofile=122880:122880 --rm --network="host" -v ${PWD}/web/src/api:/local openapitools/openapi-generator-cli:v5.1.0 generate \ +docker run --ulimit nofile=122880:122880 --rm --network="host" -v ${PWD}/web/src/api:/local openapitools/openapi-generator-cli:v6.2.1 generate \ -i http://127.0.0.1:5000/openapi.json \ -g typescript-axios \ --additional-properties=withSeparateModelsAndApi=true,apiPackage=api,modelPackage=models \ diff --git a/web/src/api/generated/.openapi-generator/VERSION b/web/src/api/generated/.openapi-generator/VERSION index acf69b48..0df17dd0 100644 --- a/web/src/api/generated/.openapi-generator/VERSION +++ b/web/src/api/generated/.openapi-generator/VERSION @@ -1 +1 @@ -5.1.0 \ No newline at end of file +6.2.1 \ No newline at end of file diff --git a/web/src/api/generated/api/health-check-api.ts b/web/src/api/generated/api/health-check-api.ts index dd55f1c1..3de27170 100644 --- a/web/src/api/generated/api/health-check-api.ts +++ b/web/src/api/generated/api/health-check-api.ts @@ -13,7 +13,7 @@ */ -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; +import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; import { Configuration } from '../configuration'; // Some imports not used depending on template conditions // @ts-ignore @@ -34,7 +34,7 @@ export const HealthCheckApiAxiosParamCreator = function (configuration?: Configu * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getHealthCheckGet: async (options: any = {}): Promise => { + getHealthCheckGet: async (options: AxiosRequestConfig = {}): Promise => { const localVarPath = `/health-check`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -49,7 +49,7 @@ export const HealthCheckApiAxiosParamCreator = function (configuration?: Configu - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -74,7 +74,7 @@ export const HealthCheckApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getHealthCheckGet(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async getHealthCheckGet(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.getHealthCheckGet(options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -114,7 +114,7 @@ export class HealthCheckApi extends BaseAPI { * @throws {RequiredError} * @memberof HealthCheckApi */ - public getHealthCheckGet(options?: any) { + public getHealthCheckGet(options?: AxiosRequestConfig) { return HealthCheckApiFp(this.configuration).getHealthCheckGet(options).then((request) => request(this.axios, this.basePath)); } } diff --git a/web/src/api/generated/api/todos-api.ts b/web/src/api/generated/api/todos-api.ts index cb081cb1..52f0af48 100644 --- a/web/src/api/generated/api/todos-api.ts +++ b/web/src/api/generated/api/todos-api.ts @@ -13,7 +13,7 @@ */ -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; +import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; import { Configuration } from '../configuration'; // Some imports not used depending on template conditions // @ts-ignore @@ -43,7 +43,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - create: async (addTodo: AddTodo, options: any = {}): Promise => { + create: async (addTodo: AddTodo, options: AxiosRequestConfig = {}): Promise => { // verify required parameter 'addTodo' is not null or undefined assertParamExists('create', 'addTodo', addTodo) const localVarPath = `/todos`; @@ -66,7 +66,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration localVarHeaderParameter['Content-Type'] = 'application/json'; - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; localVarRequestOptions.data = serializeDataIfNeeded(addTodo, localVarRequestOptions, configuration) @@ -83,7 +83,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - deleteById: async (id: string, options: any = {}): Promise => { + deleteById: async (id: string, options: AxiosRequestConfig = {}): Promise => { // verify required parameter 'id' is not null or undefined assertParamExists('deleteById', 'id', id) const localVarPath = `/todos/{id}` @@ -105,7 +105,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -120,7 +120,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getAll: async (options: any = {}): Promise => { + getAll: async (options: AxiosRequestConfig = {}): Promise => { const localVarPath = `/todos`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -139,7 +139,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -155,7 +155,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getById: async (id: string, options: any = {}): Promise => { + getById: async (id: string, options: AxiosRequestConfig = {}): Promise => { // verify required parameter 'id' is not null or undefined assertParamExists('getById', 'id', id) const localVarPath = `/todos/{id}` @@ -177,7 +177,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -194,7 +194,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - updateById: async (id: string, updateTodo: UpdateTodo, options: any = {}): Promise => { + updateById: async (id: string, updateTodo: UpdateTodo, options: AxiosRequestConfig = {}): Promise => { // verify required parameter 'id' is not null or undefined assertParamExists('updateById', 'id', id) // verify required parameter 'updateTodo' is not null or undefined @@ -220,7 +220,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration localVarHeaderParameter['Content-Type'] = 'application/json'; - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; localVarRequestOptions.data = serializeDataIfNeeded(updateTodo, localVarRequestOptions, configuration) @@ -247,7 +247,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async create(addTodo: AddTodo, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async create(addTodo: AddTodo, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.create(addTodo, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -258,7 +258,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async deleteById(id: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async deleteById(id: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.deleteById(id, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -268,7 +268,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getAll(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + async getAll(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { const localVarAxiosArgs = await localVarAxiosParamCreator.getAll(options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -279,7 +279,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getById(id: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async getById(id: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.getById(id, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -291,7 +291,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async updateById(id: string, updateTodo: UpdateTodo, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async updateById(id: string, updateTodo: UpdateTodo, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.updateById(id, updateTodo, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -373,7 +373,7 @@ export class TodosApi extends BaseAPI { * @throws {RequiredError} * @memberof TodosApi */ - public create(addTodo: AddTodo, options?: any) { + public create(addTodo: AddTodo, options?: AxiosRequestConfig) { return TodosApiFp(this.configuration).create(addTodo, options).then((request) => request(this.axios, this.basePath)); } @@ -385,7 +385,7 @@ export class TodosApi extends BaseAPI { * @throws {RequiredError} * @memberof TodosApi */ - public deleteById(id: string, options?: any) { + public deleteById(id: string, options?: AxiosRequestConfig) { return TodosApiFp(this.configuration).deleteById(id, options).then((request) => request(this.axios, this.basePath)); } @@ -396,7 +396,7 @@ export class TodosApi extends BaseAPI { * @throws {RequiredError} * @memberof TodosApi */ - public getAll(options?: any) { + public getAll(options?: AxiosRequestConfig) { return TodosApiFp(this.configuration).getAll(options).then((request) => request(this.axios, this.basePath)); } @@ -408,7 +408,7 @@ export class TodosApi extends BaseAPI { * @throws {RequiredError} * @memberof TodosApi */ - public getById(id: string, options?: any) { + public getById(id: string, options?: AxiosRequestConfig) { return TodosApiFp(this.configuration).getById(id, options).then((request) => request(this.axios, this.basePath)); } @@ -421,7 +421,7 @@ export class TodosApi extends BaseAPI { * @throws {RequiredError} * @memberof TodosApi */ - public updateById(id: string, updateTodo: UpdateTodo, options?: any) { + public updateById(id: string, updateTodo: UpdateTodo, options?: AxiosRequestConfig) { return TodosApiFp(this.configuration).updateById(id, updateTodo, options).then((request) => request(this.axios, this.basePath)); } } diff --git a/web/src/api/generated/api/whoami-api.ts b/web/src/api/generated/api/whoami-api.ts index 55ebe7a2..a3cf6ee7 100644 --- a/web/src/api/generated/api/whoami-api.ts +++ b/web/src/api/generated/api/whoami-api.ts @@ -13,7 +13,7 @@ */ -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; +import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; import { Configuration } from '../configuration'; // Some imports not used depending on template conditions // @ts-ignore @@ -34,7 +34,7 @@ export const WhoamiApiAxiosParamCreator = function (configuration?: Configuratio * @param {*} [options] Override http request option. * @throws {RequiredError} */ - whoami: async (options: any = {}): Promise => { + whoami: async (options: AxiosRequestConfig = {}): Promise => { const localVarPath = `/whoami`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -53,7 +53,7 @@ export const WhoamiApiAxiosParamCreator = function (configuration?: Configuratio - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -78,7 +78,7 @@ export const WhoamiApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async whoami(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async whoami(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.whoami(options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -118,7 +118,7 @@ export class WhoamiApi extends BaseAPI { * @throws {RequiredError} * @memberof WhoamiApi */ - public whoami(options?: any) { + public whoami(options?: AxiosRequestConfig) { return WhoamiApiFp(this.configuration).whoami(options).then((request) => request(this.axios, this.basePath)); } } diff --git a/web/src/api/generated/base.ts b/web/src/api/generated/base.ts index e479ee00..2101be22 100644 --- a/web/src/api/generated/base.ts +++ b/web/src/api/generated/base.ts @@ -16,7 +16,7 @@ import { Configuration } from "./configuration"; // Some imports not used depending on template conditions // @ts-ignore -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; +import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; export const BASE_PATH = "http://127.0.0.1:5000/api".replace(/\/+$/, ""); @@ -38,7 +38,7 @@ export const COLLECTION_FORMATS = { */ export interface RequestArgs { url: string; - options: any; + options: AxiosRequestConfig; } /** diff --git a/web/src/api/generated/common.ts b/web/src/api/generated/common.ts index 8fda6c63..ce43ac57 100644 --- a/web/src/api/generated/common.ts +++ b/web/src/api/generated/common.ts @@ -14,8 +14,8 @@ import { Configuration } from "./configuration"; -import { RequiredError, RequestArgs } from "./base"; -import { AxiosInstance } from 'axios'; +import { RequiredError, RequestArgs } from "./base"; +import { AxiosInstance, AxiosResponse } from 'axios'; /** * @@ -83,24 +83,34 @@ export const setOAuthToObject = async function (object: any, name: string, scope } } +function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void { + if (typeof parameter === "object") { + if (Array.isArray(parameter)) { + (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); + } + else { + Object.keys(parameter).forEach(currentKey => + setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`) + ); + } + } + else { + if (urlSearchParams.has(key)) { + urlSearchParams.append(key, parameter); + } + else { + urlSearchParams.set(key, parameter); + } + } +} + /** * * @export */ export const setSearchParams = function (url: URL, ...objects: any[]) { const searchParams = new URLSearchParams(url.search); - for (const object of objects) { - for (const key in object) { - if (Array.isArray(object[key])) { - searchParams.delete(key); - for (const item of object[key]) { - searchParams.append(key, item); - } - } else { - searchParams.set(key, object[key]); - } - } - } + setFlattenedQueryParams(searchParams, objects); url.search = searchParams.toString(); } @@ -131,8 +141,8 @@ export const toPathString = function (url: URL) { * @export */ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) { - return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + return >(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url}; - return axios.request(axiosRequestArgs); + return axios.request(axiosRequestArgs); }; } diff --git a/web/src/api/generated/git_push.sh b/web/src/api/generated/git_push.sh index ced3be2b..f53a75d4 100644 --- a/web/src/api/generated/git_push.sh +++ b/web/src/api/generated/git_push.sh @@ -1,7 +1,7 @@ #!/bin/sh # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ # -# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" git_user_id=$1 git_repo_id=$2 @@ -38,14 +38,14 @@ git add . git commit -m "$release_note" # Sets the new remote -git_remote=`git remote` +git_remote=$(git remote) if [ "$git_remote" = "" ]; then # git remote not defined if [ "$GIT_TOKEN" = "" ]; then echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git else - git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git fi fi @@ -55,4 +55,3 @@ git pull origin master # Pushes (Forces) the changes in the local repository up to the remote repository echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" git push origin master 2>&1 | grep -v 'To https' - diff --git a/web/src/api/generated/models/add-todo.ts b/web/src/api/generated/models/add-todo.ts index 3cd6a0bf..3b393a10 100644 --- a/web/src/api/generated/models/add-todo.ts +++ b/web/src/api/generated/models/add-todo.ts @@ -25,7 +25,6 @@ export interface AddTodo { * @type {string} * @memberof AddTodo */ - title: string; + 'title': string; } - diff --git a/web/src/api/generated/models/delete-todo-response.ts b/web/src/api/generated/models/delete-todo-response.ts index 3fa13d3b..03c024e8 100644 --- a/web/src/api/generated/models/delete-todo-response.ts +++ b/web/src/api/generated/models/delete-todo-response.ts @@ -25,7 +25,6 @@ export interface DeleteTodoResponse { * @type {boolean} * @memberof DeleteTodoResponse */ - success: boolean; + 'success': boolean; } - diff --git a/web/src/api/generated/models/error-response.ts b/web/src/api/generated/models/error-response.ts index 964b370e..ebaf9c52 100644 --- a/web/src/api/generated/models/error-response.ts +++ b/web/src/api/generated/models/error-response.ts @@ -25,31 +25,30 @@ export interface ErrorResponse { * @type {number} * @memberof ErrorResponse */ - status?: number; + 'status'?: number; /** * * @type {string} * @memberof ErrorResponse */ - type?: string; + 'type'?: string; /** * * @type {string} * @memberof ErrorResponse */ - message?: string; + 'message'?: string; /** * * @type {string} * @memberof ErrorResponse */ - debug?: string; + 'debug'?: string; /** * * @type {object} * @memberof ErrorResponse */ - extra?: object; + 'extra'?: object; } - diff --git a/web/src/api/generated/models/todo-item.ts b/web/src/api/generated/models/todo-item.ts index 8ec6930c..9ce86d68 100644 --- a/web/src/api/generated/models/todo-item.ts +++ b/web/src/api/generated/models/todo-item.ts @@ -25,19 +25,18 @@ export interface TodoItem { * @type {string} * @memberof TodoItem */ - id: string; + 'id': string; /** * * @type {string} * @memberof TodoItem */ - title: string; + 'title': string; /** * * @type {boolean} * @memberof TodoItem */ - is_completed?: boolean; + 'is_completed'?: boolean; } - diff --git a/web/src/api/generated/models/update-todo.ts b/web/src/api/generated/models/update-todo.ts index 77f36e56..005de63b 100644 --- a/web/src/api/generated/models/update-todo.ts +++ b/web/src/api/generated/models/update-todo.ts @@ -25,13 +25,12 @@ export interface UpdateTodo { * @type {string} * @memberof UpdateTodo */ - title: string; + 'title': string; /** * * @type {boolean} * @memberof UpdateTodo */ - is_completed?: boolean; + 'is_completed'?: boolean; } - From 357f1eb31571530fbc73f653f6350d9f3f6b7cd6 Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Tue, 15 Nov 2022 12:02:50 +0100 Subject: [PATCH 07/11] refactor: remove delete response (need to rebase after PR) --- api/src/features/todo/todo_feature.py | 6 +++--- api/src/features/todo/use_cases/delete_todo_by_id.py | 9 +-------- .../features/todo/use_cases/test_delete_todo_by_id.py | 6 ++++-- 3 files changed, 8 insertions(+), 13 deletions(-) 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): From 44136031316acc3d7b73085a9570c6f2567b1418 Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Fri, 18 Nov 2022 14:42:06 +0100 Subject: [PATCH 08/11] refactor: wip --- web/src/features/todos/todo-list/TodoItem.tsx | 4 ++-- web/src/features/todos/todo-list/TodoList.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/features/todos/todo-list/TodoItem.tsx b/web/src/features/todos/todo-list/TodoItem.tsx index 4c27be8b..39614ef7 100644 --- a/web/src/features/todos/todo-list/TodoItem.tsx +++ b/web/src/features/todos/todo-list/TodoItem.tsx @@ -9,7 +9,7 @@ import { import { undo, done, remove_outlined } from '@equinor/eds-icons' import { TodoItem } from '../../../api/generated' -const TodoItemElement = (props: { +const TodoItemCard = (props: { todo: TodoItem onToggle: (id: string) => void onRemove: (id: string) => void @@ -49,4 +49,4 @@ const TodoItemElement = (props: { ) } -export default TodoItemElement +export default TodoItemCard diff --git a/web/src/features/todos/todo-list/TodoList.tsx b/web/src/features/todos/todo-list/TodoList.tsx index 232976da..36950e3d 100644 --- a/web/src/features/todos/todo-list/TodoList.tsx +++ b/web/src/features/todos/todo-list/TodoList.tsx @@ -1,7 +1,7 @@ import useTodos from '../../../hooks/useTodos' import { FormEventHandler, useState } from 'react' import { Button, Input, Progress } from '@equinor/eds-core-react' -import TodoItemElement from './TodoItem' +import TodoItemCard from './TodoItem' import { TodoItem } from '../../../api/generated' import { StyledTodoList, @@ -49,7 +49,7 @@ const TodoList = () => { {todos?.map((todo: TodoItem) => ( - Date: Fri, 18 Nov 2022 14:44:29 +0100 Subject: [PATCH 09/11] refactor: wip --- .../features/todos/todo-list/{TodoItem.tsx => TodoItemCard.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename web/src/features/todos/todo-list/{TodoItem.tsx => TodoItemCard.tsx} (100%) diff --git a/web/src/features/todos/todo-list/TodoItem.tsx b/web/src/features/todos/todo-list/TodoItemCard.tsx similarity index 100% rename from web/src/features/todos/todo-list/TodoItem.tsx rename to web/src/features/todos/todo-list/TodoItemCard.tsx From 956ba13d67808b8a5caae58c46a734f44cc56d8a Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Fri, 18 Nov 2022 14:48:00 +0100 Subject: [PATCH 10/11] refactor: wip --- .../api/generated/.openapi-generator/FILES | 1 - web/src/api/generated/api.ts | 2 +- web/src/api/generated/api/health-check-api.ts | 2 +- web/src/api/generated/api/todos-api.ts | 8 ++--- web/src/api/generated/api/whoami-api.ts | 2 +- web/src/api/generated/base.ts | 2 +- web/src/api/generated/common.ts | 2 +- web/src/api/generated/configuration.ts | 2 +- web/src/api/generated/index.ts | 2 +- web/src/api/generated/models/add-todo.ts | 2 +- .../generated/models/delete-todo-response.ts | 30 ------------------- .../api/generated/models/error-response.ts | 2 +- web/src/api/generated/models/index.ts | 1 - web/src/api/generated/models/todo-item.ts | 2 +- web/src/api/generated/models/update-todo.ts | 2 +- web/src/features/todos/todo-list/TodoList.tsx | 2 +- 16 files changed, 15 insertions(+), 49 deletions(-) delete mode 100644 web/src/api/generated/models/delete-todo-response.ts diff --git a/web/src/api/generated/.openapi-generator/FILES b/web/src/api/generated/.openapi-generator/FILES index 24320353..6c20cfb4 100644 --- a/web/src/api/generated/.openapi-generator/FILES +++ b/web/src/api/generated/.openapi-generator/FILES @@ -11,7 +11,6 @@ configuration.ts git_push.sh index.ts models/add-todo.ts -models/delete-todo-response.ts models/error-response.ts models/index.ts models/todo-item.ts diff --git a/web/src/api/generated/api.ts b/web/src/api/generated/api.ts index 74d2e0d0..a56d0fe0 100644 --- a/web/src/api/generated/api.ts +++ b/web/src/api/generated/api.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/api/health-check-api.ts b/web/src/api/generated/api/health-check-api.ts index 3de27170..eb9cad1b 100644 --- a/web/src/api/generated/api/health-check-api.ts +++ b/web/src/api/generated/api/health-check-api.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/api/todos-api.ts b/web/src/api/generated/api/todos-api.ts index 52f0af48..214eb34f 100644 --- a/web/src/api/generated/api/todos-api.ts +++ b/web/src/api/generated/api/todos-api.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -23,8 +23,6 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr // @ts-ignore import { AddTodo } from '../models'; // @ts-ignore -import { DeleteTodoResponse } from '../models'; -// @ts-ignore import { ErrorResponse } from '../models'; // @ts-ignore import { TodoItem } from '../models'; @@ -258,7 +256,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async deleteById(id: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async deleteById(id: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.deleteById(id, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -322,7 +320,7 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath * @param {*} [options] Override http request option. * @throws {RequiredError} */ - deleteById(id: string, options?: any): AxiosPromise { + deleteById(id: string, options?: any): AxiosPromise { return localVarFp.deleteById(id, options).then((request) => request(axios, basePath)); }, /** diff --git a/web/src/api/generated/api/whoami-api.ts b/web/src/api/generated/api/whoami-api.ts index a3cf6ee7..596b51fa 100644 --- a/web/src/api/generated/api/whoami-api.ts +++ b/web/src/api/generated/api/whoami-api.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/base.ts b/web/src/api/generated/base.ts index 2101be22..f5bd8e9f 100644 --- a/web/src/api/generated/base.ts +++ b/web/src/api/generated/base.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/common.ts b/web/src/api/generated/common.ts index ce43ac57..6ff9f89c 100644 --- a/web/src/api/generated/common.ts +++ b/web/src/api/generated/common.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/configuration.ts b/web/src/api/generated/configuration.ts index 205cc90e..f440e35a 100644 --- a/web/src/api/generated/configuration.ts +++ b/web/src/api/generated/configuration.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/index.ts b/web/src/api/generated/index.ts index 636d9151..b540f711 100644 --- a/web/src/api/generated/index.ts +++ b/web/src/api/generated/index.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/models/add-todo.ts b/web/src/api/generated/models/add-todo.ts index 3b393a10..c3c840aa 100644 --- a/web/src/api/generated/models/add-todo.ts +++ b/web/src/api/generated/models/add-todo.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/models/delete-todo-response.ts b/web/src/api/generated/models/delete-todo-response.ts deleted file mode 100644 index 03c024e8..00000000 --- a/web/src/api/generated/models/delete-todo-response.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.2.1 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface DeleteTodoResponse - */ -export interface DeleteTodoResponse { - /** - * - * @type {boolean} - * @memberof DeleteTodoResponse - */ - 'success': boolean; -} - diff --git a/web/src/api/generated/models/error-response.ts b/web/src/api/generated/models/error-response.ts index ebaf9c52..db650609 100644 --- a/web/src/api/generated/models/error-response.ts +++ b/web/src/api/generated/models/error-response.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/models/index.ts b/web/src/api/generated/models/index.ts index 2be8ca9b..d6056586 100644 --- a/web/src/api/generated/models/index.ts +++ b/web/src/api/generated/models/index.ts @@ -1,5 +1,4 @@ export * from './add-todo'; -export * from './delete-todo-response'; export * from './error-response'; export * from './todo-item'; export * from './update-todo'; diff --git a/web/src/api/generated/models/todo-item.ts b/web/src/api/generated/models/todo-item.ts index 9ce86d68..bbad6885 100644 --- a/web/src/api/generated/models/todo-item.ts +++ b/web/src/api/generated/models/todo-item.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/models/update-todo.ts b/web/src/api/generated/models/update-todo.ts index 005de63b..dd727fb1 100644 --- a/web/src/api/generated/models/update-todo.ts +++ b/web/src/api/generated/models/update-todo.ts @@ -4,7 +4,7 @@ * Template FastAPI React * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.2.1 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/features/todos/todo-list/TodoList.tsx b/web/src/features/todos/todo-list/TodoList.tsx index 36950e3d..a59c77ac 100644 --- a/web/src/features/todos/todo-list/TodoList.tsx +++ b/web/src/features/todos/todo-list/TodoList.tsx @@ -1,7 +1,7 @@ import useTodos from '../../../hooks/useTodos' import { FormEventHandler, useState } from 'react' import { Button, Input, Progress } from '@equinor/eds-core-react' -import TodoItemCard from './TodoItem' +import TodoItemCard from './TodoItemCard' import { TodoItem } from '../../../api/generated' import { StyledTodoList, From c44f9cdc871c5306bbbc7e803701aa590926b3b0 Mon Sep 17 00:00:00 2001 From: Eirik Ola Aksnes Date: Fri, 18 Nov 2022 14:59:14 +0100 Subject: [PATCH 11/11] refactor: wip --- api/src/features/todo/todo_feature.py | 3 +-- api/src/tests/integration/features/todo/test_todo_feature.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/api/src/features/todo/todo_feature.py b/api/src/features/todo/todo_feature.py index 0fc76d8d..4f4c9090 100644 --- a/api/src/features/todo/todo_feature.py +++ b/api/src/features/todo/todo_feature.py @@ -1,7 +1,6 @@ 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 @@ -42,7 +41,7 @@ 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", status_code=status.HTTP_204_NO_CONTENT) +@router.delete("/{id}", operation_id="delete_by_id") @create_response(JSONResponse) def delete_todo_by_id( id: str, diff --git a/api/src/tests/integration/features/todo/test_todo_feature.py b/api/src/tests/integration/features/todo/test_todo_feature.py index f9498d32..e446869c 100644 --- a/api/src/tests/integration/features/todo/test_todo_feature.py +++ b/api/src/tests/integration/features/todo/test_todo_feature.py @@ -74,7 +74,6 @@ def test_delete_todo(self, test_app: TestClient): response = test_app.delete("/todos/1") assert response.status_code == HTTP_200_OK - assert response.json()["success"] def test_delete_todo_should_return_not_found(self, test_app: TestClient): response = test_app.delete("/todos/unknown")