Skip to content

Commit

Permalink
Merge branch 'remove-request-from-schema-names-#297' into refactor-sy…
Browse files Browse the repository at this point in the history
…stem-repo-unit-tests-#90
  • Loading branch information
joelvdavies committed Jun 20, 2024
2 parents 28b3440 + 8eb622e commit 7bf025c
Show file tree
Hide file tree
Showing 23 changed files with 128 additions and 136 deletions.
6 changes: 6 additions & 0 deletions inventory_management_system_api/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Module for connecting to a MongoDB database.
"""

from typing import Annotated

from fastapi import Depends
from pymongo import MongoClient
from pymongo.database import Database

Expand All @@ -23,3 +26,6 @@ def get_database() -> Database:
:return: The MongoDB database object.
"""
return mongodb_client[db_config.name.get_secret_value()]


DatabaseDep = Annotated[Database, Depends(get_database)]
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
from datetime import datetime, timezone
from typing import List, Optional

from fastapi import Depends
from pymongo.client_session import ClientSession
from pymongo.collection import Collection
from pymongo.database import Database

from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.database import get_database
from inventory_management_system_api.core.database import DatabaseDep
from inventory_management_system_api.core.exceptions import (
ChildElementsExistError,
DuplicateRecordError,
Expand All @@ -36,7 +34,7 @@ class CatalogueCategoryRepo:
Repository for managing catalogue categories in a MongoDB database.
"""

def __init__(self, database: Database = Depends(get_database)) -> None:
def __init__(self, database: DatabaseDep) -> None:
"""
Initialize the `CatalogueCategoryRepo` with a MongoDB database instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
from typing import List, Optional

from bson import ObjectId
from fastapi import Depends
from pymongo.client_session import ClientSession
from pymongo.collection import Collection
from pymongo.database import Database

from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.database import get_database
from inventory_management_system_api.core.database import DatabaseDep
from inventory_management_system_api.core.exceptions import ChildElementsExistError, MissingRecordError
from inventory_management_system_api.models.catalogue_item import CatalogueItemIn, CatalogueItemOut, PropertyIn

Expand All @@ -25,7 +23,7 @@ class CatalogueItemRepo:
Repository for managing catalogue items in a MongoDB database.
"""

def __init__(self, database: Database = Depends(get_database)) -> None:
def __init__(self, database: DatabaseDep) -> None:
"""
Initialize the `CatalogueItemRepo` with a MongoDB database instance.
Expand Down
6 changes: 2 additions & 4 deletions inventory_management_system_api/repositories/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
from typing import List, Optional

from bson import ObjectId
from fastapi import Depends
from pymongo.client_session import ClientSession
from pymongo.collection import Collection
from pymongo.database import Database

from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.database import get_database
from inventory_management_system_api.core.database import DatabaseDep
from inventory_management_system_api.core.exceptions import MissingRecordError
from inventory_management_system_api.models.catalogue_item import PropertyIn
from inventory_management_system_api.models.item import ItemIn, ItemOut
Expand All @@ -26,7 +24,7 @@ class ItemRepo:
Repository for managing items in a MongoDB database.
"""

def __init__(self, database: Database = Depends(get_database)) -> None:
def __init__(self, database: DatabaseDep) -> None:
"""
Initialize the `ItemRepo` with a MongoDB database instance.
Expand Down
6 changes: 2 additions & 4 deletions inventory_management_system_api/repositories/manufacturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import logging
from typing import List, Optional

from fastapi import Depends
from pymongo.client_session import ClientSession
from pymongo.collection import Collection
from pymongo.database import Database

from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.database import get_database
from inventory_management_system_api.core.database import DatabaseDep
from inventory_management_system_api.core.exceptions import (
DuplicateRecordError,
MissingRecordError,
Expand All @@ -25,7 +23,7 @@
class ManufacturerRepo:
"""Repository for managing manufacturer in MongoDb database"""

def __init__(self, database: Database = Depends(get_database)) -> None:
def __init__(self, database: DatabaseDep) -> None:
"""Initialize the `ManufacturerRepo` with MongoDB database instance
:param database: The database to use.
Expand Down
6 changes: 2 additions & 4 deletions inventory_management_system_api/repositories/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import logging
from typing import Optional

from fastapi import Depends
from pymongo.client_session import ClientSession
from pymongo.collection import Collection
from pymongo.database import Database

from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.database import get_database
from inventory_management_system_api.core.database import DatabaseDep
from inventory_management_system_api.core.exceptions import (
ChildElementsExistError,
DuplicateRecordError,
Expand All @@ -30,7 +28,7 @@ class SystemRepo:
Repository for managing Systems in a MongoDB database
"""

def __init__(self, database: Database = Depends(get_database)) -> None:
def __init__(self, database: DatabaseDep) -> None:
"""
Initialise the `SystemRepo` with a MongoDB database instance
Expand Down
6 changes: 2 additions & 4 deletions inventory_management_system_api/repositories/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import logging
from typing import Optional

from fastapi import Depends
from pymongo.client_session import ClientSession
from pymongo.collection import Collection
from pymongo.database import Database

from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.database import get_database
from inventory_management_system_api.core.database import DatabaseDep
from inventory_management_system_api.core.exceptions import (
DuplicateRecordError,
MissingRecordError,
Expand All @@ -27,7 +25,7 @@ class UnitRepo:
Repository for managing Units in a MongoDB database
"""

def __init__(self, database: Database = Depends(get_database)) -> None:
def __init__(self, database: DatabaseDep) -> None:
"""
Initialise the `UnitRepo` with a MongoDB database instance
:param database: Database to use
Expand Down
7 changes: 2 additions & 5 deletions inventory_management_system_api/repositories/usage_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import logging
from typing import Optional

from fastapi import Depends

from pymongo.client_session import ClientSession
from pymongo.collection import Collection
from pymongo.database import Database

from inventory_management_system_api.core.custom_object_id import CustomObjectId
from inventory_management_system_api.core.database import get_database
from inventory_management_system_api.core.database import DatabaseDep
from inventory_management_system_api.core.exceptions import DuplicateRecordError, MissingRecordError, PartOfItemError
from inventory_management_system_api.models.usage_status import UsageStatusIn, UsageStatusOut

Expand All @@ -25,7 +22,7 @@ class UsageStatusRepo:
Repository for managing Usage statuses in a MongoDB database
"""

def __init__(self, database: Database = Depends(get_database)) -> None:
def __init__(self, database: DatabaseDep) -> None:
"""
Initialise the `UsageStatusRepo` with a MongoDB database instance
Expand Down
41 changes: 25 additions & 16 deletions inventory_management_system_api/routers/v1/catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@

router = APIRouter(prefix="/v1/catalogue-categories", tags=["catalogue categories"])

CatalogueCategoryServiceDep = Annotated[CatalogueCategoryService, Depends(CatalogueCategoryService)]

CatalogueCategoryPropertyServiceDep = Annotated[
CatalogueCategoryPropertyService, Depends(CatalogueCategoryPropertyService)
]


@router.get(path="", summary="Get catalogue categories", response_description="List of catalogue categories")
def get_catalogue_categories(
catalogue_category_service: CatalogueCategoryServiceDep,
parent_id: Annotated[Optional[str], Query(description="Filter catalogue categories by parent ID")] = None,
catalogue_category_service: CatalogueCategoryService = Depends(),
) -> List[CatalogueCategorySchema]:
# pylint: disable=missing-function-docstring
logger.info("Getting catalogue categories")
Expand All @@ -62,8 +68,8 @@ def get_catalogue_categories(
response_description="Single catalogue category",
)
def get_catalogue_category(
catalogue_category_id: str = Path(description="The ID of the catalogue category to get"),
catalogue_category_service: CatalogueCategoryService = Depends(),
catalogue_category_id: Annotated[str, Path(description="The ID of the catalogue category to get")],
catalogue_category_service: CatalogueCategoryServiceDep,
) -> CatalogueCategorySchema:
# pylint: disable=missing-function-docstring
logger.info("Getting catalogue category with ID: %s", catalogue_category_id)
Expand All @@ -80,8 +86,10 @@ def get_catalogue_category(

@router.get(path="/{catalogue_category_id}/breadcrumbs", summary="Get breadcrumbs data for a catalogue category")
def get_catalogue_category_breadcrumbs(
catalogue_category_id: str = Path(description="The ID of the catalogue category to get the breadcrumbs for"),
catalogue_category_service: CatalogueCategoryService = Depends(),
catalogue_category_id: Annotated[
str, Path(description="The ID of the catalogue category to get the breadcrumbs for")
],
catalogue_category_service: CatalogueCategoryServiceDep,
) -> BreadcrumbsGetSchema:
# pylint: disable=missing-function-docstring
logger.info("Getting breadcrumbs for catalogue category with ID: %s", catalogue_category_id)
Expand All @@ -107,8 +115,7 @@ def get_catalogue_category_breadcrumbs(
status_code=status.HTTP_201_CREATED,
)
def create_catalogue_category(
catalogue_category: CatalogueCategoryPostSchema,
catalogue_category_service: CatalogueCategoryService = Depends(),
catalogue_category: CatalogueCategoryPostSchema, catalogue_category_service: CatalogueCategoryServiceDep
) -> CatalogueCategorySchema:
# pylint: disable=missing-function-docstring
logger.info("Creating a new catalogue category")
Expand Down Expand Up @@ -148,8 +155,8 @@ def create_catalogue_category(
)
def partial_update_catalogue_category(
catalogue_category: CatalogueCategoryPatchSchema,
catalogue_category_id: str = Path(description="The ID of the catalogue category to update"),
catalogue_category_service: CatalogueCategoryService = Depends(),
catalogue_category_id: Annotated[str, Path(description="The ID of the catalogue category to update")],
catalogue_category_service: CatalogueCategoryServiceDep,
) -> CatalogueCategorySchema:
# pylint: disable=missing-function-docstring
logger.info("Partially updating catalogue category with ID: %s", catalogue_category_id)
Expand Down Expand Up @@ -205,8 +212,8 @@ def partial_update_catalogue_category(
status_code=status.HTTP_204_NO_CONTENT,
)
def delete_catalogue_category(
catalogue_category_id: str = Path(description="The ID of the catalogue category to delete"),
catalogue_category_service: CatalogueCategoryService = Depends(),
catalogue_category_id: Annotated[str, Path(description="The ID of the catalogue category to delete")],
catalogue_category_service: CatalogueCategoryServiceDep,
) -> None:
# pylint: disable=missing-function-docstring
logger.info("Deleting catalogue category with ID: %s", catalogue_category_id)
Expand All @@ -230,8 +237,8 @@ def delete_catalogue_category(
)
def create_property(
catalogue_category_property: CatalogueCategoryPropertyPostSchema,
catalogue_category_id: str = Path(description="The ID of the catalogue category to add a property to"),
catalogue_category_property_service: CatalogueCategoryPropertyService = Depends(),
catalogue_category_id: Annotated[str, Path(description="The ID of the catalogue category to add a property to")],
catalogue_category_property_service: CatalogueCategoryPropertyServiceDep,
) -> CatalogueCategoryPropertySchema:
# pylint: disable=missing-function-docstring
logger.info("Creating a new property at the catalogue category level")
Expand Down Expand Up @@ -271,9 +278,11 @@ def create_property(
)
def partial_update_property(
catalogue_category_property: CatalogueCategoryPropertyPatchSchema,
catalogue_category_id: str = Path(description="The ID of the catalogue category containing the property to patch"),
property_id: str = Path(description="The ID of the property to patch"),
catalogue_category_property_service: CatalogueCategoryPropertyService = Depends(),
catalogue_category_id: Annotated[
str, Path(description="The ID of the catalogue category containing the property to patch")
],
property_id: Annotated[str, Path(description="The ID of the property to patch")],
catalogue_category_property_service: CatalogueCategoryPropertyServiceDep,
) -> CatalogueCategoryPropertySchema:
# pylint: disable=missing-function-docstring
logger.info(
Expand Down
20 changes: 11 additions & 9 deletions inventory_management_system_api/routers/v1/catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from inventory_management_system_api.core.exceptions import (
ChildElementsExistError,
InvalidActionError,
InvalidPropertyTypeError,
InvalidObjectIdError,
InvalidPropertyTypeError,
MissingMandatoryProperty,
MissingRecordError,
NonLeafCatalogueCategoryError,
Expand All @@ -28,13 +28,15 @@

router = APIRouter(prefix="/v1/catalogue-items", tags=["catalogue items"])

CatalogueItemServiceDep = Annotated[CatalogueItemService, Depends(CatalogueItemService)]


@router.get(path="", summary="Get catalogue items", response_description="List of catalogue items")
def get_catalogue_items(
catalogue_item_service: CatalogueItemServiceDep,
catalogue_category_id: Annotated[
Optional[str], Query(description="Filter catalogue items by catalogue category ID")
] = None,
catalogue_item_service: CatalogueItemService = Depends(),
) -> List[CatalogueItemSchema]:
# pylint: disable=missing-function-docstring
logger.info("Getting catalogue items")
Expand All @@ -53,8 +55,8 @@ def get_catalogue_items(
path="/{catalogue_item_id}", summary="Get a catalogue item by ID", response_description="Single catalogue item"
)
def get_catalogue_item(
catalogue_item_id: str = Path(description="The ID of the catalogue item to get"),
catalogue_item_service: CatalogueItemService = Depends(),
catalogue_item_id: Annotated[str, Path(description="The ID of the catalogue item to get")],
catalogue_item_service: CatalogueItemServiceDep,
) -> CatalogueItemSchema:
# pylint: disable=missing-function-docstring
logger.info("Getting catalogue item with ID: %s", catalogue_item_id)
Expand All @@ -76,7 +78,7 @@ def get_catalogue_item(
status_code=status.HTTP_201_CREATED,
)
def create_catalogue_item(
catalogue_item: CatalogueItemPostSchema, catalogue_item_service: CatalogueItemService = Depends()
catalogue_item: CatalogueItemPostSchema, catalogue_item_service: CatalogueItemServiceDep
) -> CatalogueItemSchema:
# pylint: disable=missing-function-docstring
logger.info("Creating a new catalogue item")
Expand Down Expand Up @@ -113,8 +115,8 @@ def create_catalogue_item(
)
def partial_update_catalogue_item(
catalogue_item: CatalogueItemPatchSchema,
catalogue_item_id: str = Path(description="The ID of the catalogue item to update"),
catalogue_item_service: CatalogueItemService = Depends(),
catalogue_item_id: Annotated[str, Path(description="The ID of the catalogue item to update")],
catalogue_item_service: CatalogueItemServiceDep,
) -> CatalogueItemSchema:
# pylint: disable=missing-function-docstring
logger.info("Partially updating catalogue item with ID: %s", catalogue_item_id)
Expand Down Expand Up @@ -175,8 +177,8 @@ def partial_update_catalogue_item(
status_code=status.HTTP_204_NO_CONTENT,
)
def delete_catalogue_item(
catalogue_item_id: str = Path(description="The ID of the catalogue item to delete"),
catalogue_item_service: CatalogueItemService = Depends(),
catalogue_item_id: Annotated[str, Path(description="The ID of the catalogue item to delete")],
catalogue_item_service: CatalogueItemServiceDep,
) -> None:
# pylint: disable=missing-function-docstring
logger.info("Deleting catalogue item with ID: %s", catalogue_item_id)
Expand Down
Loading

0 comments on commit 7bf025c

Please sign in to comment.