Skip to content

Commit

Permalink
Merge pull request #298 from ral-facilities/remove-request-from-schem…
Browse files Browse the repository at this point in the history
…a-names-#297

Remove 'Request' from schema names #297
  • Loading branch information
joelvdavies authored Jun 20, 2024
2 parents d0e7c2e + 8eb622e commit 6c05a1e
Show file tree
Hide file tree
Showing 28 changed files with 245 additions and 257 deletions.
16 changes: 8 additions & 8 deletions inventory_management_system_api/routers/v1/catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
)
from inventory_management_system_api.schemas.breadcrumbs import BreadcrumbsGetSchema
from inventory_management_system_api.schemas.catalogue_category import (
CatalogueCategoryPatchRequestSchema,
CatalogueCategoryPostRequestSchema,
CatalogueCategoryPropertyPatchRequestSchema,
CatalogueCategoryPropertyPostRequestSchema,
CatalogueCategoryPatchSchema,
CatalogueCategoryPostSchema,
CatalogueCategoryPropertyPatchSchema,
CatalogueCategoryPropertyPostSchema,
CatalogueCategoryPropertySchema,
CatalogueCategorySchema,
)
Expand Down Expand Up @@ -115,7 +115,7 @@ def get_catalogue_category_breadcrumbs(
status_code=status.HTTP_201_CREATED,
)
def create_catalogue_category(
catalogue_category: CatalogueCategoryPostRequestSchema, catalogue_category_service: CatalogueCategoryServiceDep
catalogue_category: CatalogueCategoryPostSchema, catalogue_category_service: CatalogueCategoryServiceDep
) -> CatalogueCategorySchema:
# pylint: disable=missing-function-docstring
logger.info("Creating a new catalogue category")
Expand Down Expand Up @@ -154,7 +154,7 @@ def create_catalogue_category(
response_description="Catalogue category updated successfully",
)
def partial_update_catalogue_category(
catalogue_category: CatalogueCategoryPatchRequestSchema,
catalogue_category: CatalogueCategoryPatchSchema,
catalogue_category_id: Annotated[str, Path(description="The ID of the catalogue category to update")],
catalogue_category_service: CatalogueCategoryServiceDep,
) -> CatalogueCategorySchema:
Expand Down Expand Up @@ -236,7 +236,7 @@ def delete_catalogue_category(
status_code=status.HTTP_201_CREATED,
)
def create_property(
catalogue_category_property: CatalogueCategoryPropertyPostRequestSchema,
catalogue_category_property: CatalogueCategoryPropertyPostSchema,
catalogue_category_id: Annotated[str, Path(description="The ID of the catalogue category to add a property to")],
catalogue_category_property_service: CatalogueCategoryPropertyServiceDep,
) -> CatalogueCategoryPropertySchema:
Expand Down Expand Up @@ -277,7 +277,7 @@ def create_property(
response_description="The updated property as defined at the catalogue category level",
)
def partial_update_property(
catalogue_category_property: CatalogueCategoryPropertyPatchRequestSchema,
catalogue_category_property: CatalogueCategoryPropertyPatchSchema,
catalogue_category_id: Annotated[
str, Path(description="The ID of the catalogue category containing the property to patch")
],
Expand Down
10 changes: 5 additions & 5 deletions inventory_management_system_api/routers/v1/catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
from inventory_management_system_api.core.exceptions import (
ChildElementsExistError,
InvalidActionError,
InvalidPropertyTypeError,
InvalidObjectIdError,
InvalidPropertyTypeError,
MissingMandatoryProperty,
MissingRecordError,
NonLeafCatalogueCategoryError,
)
from inventory_management_system_api.schemas.catalogue_item import (
CatalogueItemPatchRequestSchema,
CatalogueItemPostRequestSchema,
CatalogueItemPatchSchema,
CatalogueItemPostSchema,
CatalogueItemSchema,
)
from inventory_management_system_api.services.catalogue_item import CatalogueItemService
Expand Down Expand Up @@ -78,7 +78,7 @@ def get_catalogue_item(
status_code=status.HTTP_201_CREATED,
)
def create_catalogue_item(
catalogue_item: CatalogueItemPostRequestSchema, catalogue_item_service: CatalogueItemServiceDep
catalogue_item: CatalogueItemPostSchema, catalogue_item_service: CatalogueItemServiceDep
) -> CatalogueItemSchema:
# pylint: disable=missing-function-docstring
logger.info("Creating a new catalogue item")
Expand Down Expand Up @@ -114,7 +114,7 @@ def create_catalogue_item(
response_description="Catalogue item updated successfully",
)
def partial_update_catalogue_item(
catalogue_item: CatalogueItemPatchRequestSchema,
catalogue_item: CatalogueItemPatchSchema,
catalogue_item_id: Annotated[str, Path(description="The ID of the catalogue item to update")],
catalogue_item_service: CatalogueItemServiceDep,
) -> CatalogueItemSchema:
Expand Down
12 changes: 6 additions & 6 deletions inventory_management_system_api/routers/v1/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import logging
from typing import Annotated, List, Optional

from fastapi import APIRouter, Query, status, HTTPException, Depends, Path
from fastapi import APIRouter, Depends, HTTPException, Path, Query, status

from inventory_management_system_api.core.exceptions import (
DatabaseIntegrityError,
InvalidActionError,
InvalidObjectIdError,
InvalidPropertyTypeError,
MissingMandatoryProperty,
MissingRecordError,
DatabaseIntegrityError,
InvalidPropertyTypeError,
)
from inventory_management_system_api.schemas.item import ItemPatchRequestSchema, ItemPostRequestSchema, ItemSchema
from inventory_management_system_api.schemas.item import ItemPatchSchema, ItemPostSchema, ItemSchema
from inventory_management_system_api.services.item import ItemService

logger = logging.getLogger()
Expand All @@ -31,7 +31,7 @@
response_description="The created item",
status_code=status.HTTP_201_CREATED,
)
def create_item(item: ItemPostRequestSchema, item_service: ItemServiceDep) -> ItemSchema:
def create_item(item: ItemPostSchema, item_service: ItemServiceDep) -> ItemSchema:
# pylint: disable=missing-function-docstring
logger.info("Creating a new item")
logger.debug("Item data: %s", item)
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_item(
response_description="Item updated successfully",
)
def partial_update_item(
item: ItemPatchRequestSchema,
item: ItemPatchSchema,
item_id: Annotated[str, Path(description="The ID of the item to update")],
item_service: ItemServiceDep,
) -> ItemSchema:
Expand Down
14 changes: 7 additions & 7 deletions inventory_management_system_api/routers/v1/manufacturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

import logging
from typing import Annotated, List
from fastapi import APIRouter, status, Depends, HTTPException, Path

from fastapi import APIRouter, Depends, HTTPException, Path, status

from inventory_management_system_api.core.exceptions import (
DuplicateRecordError,
InvalidObjectIdError,
MissingRecordError,
PartOfCatalogueItemError,
)

from inventory_management_system_api.schemas.manufacturer import (
ManufacturerPatchRequestSchema,
ManufacturerPostRequestSchema,
ManufacturerPatchSchema,
ManufacturerPostSchema,
ManufacturerSchema,
)
from inventory_management_system_api.services.manufacturer import ManufacturerService


logger = logging.getLogger()

router = APIRouter(prefix="/v1/manufacturers", tags=["manufacturers"])
Expand All @@ -35,7 +35,7 @@
status_code=status.HTTP_201_CREATED,
)
def create_manufacturer(
manufacturer: ManufacturerPostRequestSchema, manufacturer_service: ManufacturerServiceDep
manufacturer: ManufacturerPostSchema, manufacturer_service: ManufacturerServiceDep
) -> ManufacturerSchema:
# pylint: disable=missing-function-docstring
logger.info("Creating a new manufacturer")
Expand Down Expand Up @@ -93,7 +93,7 @@ def get_one_manufacturer(
response_description="Manufacturer updated successfully",
)
def edit_manufacturer(
manufacturer: ManufacturerPatchRequestSchema,
manufacturer: ManufacturerPatchSchema,
manufacturer_id: Annotated[str, Path(description="The ID of the manufacturer that is to be updated")],
manufacturer_service: ManufacturerServiceDep,
) -> ManufacturerSchema:
Expand Down
6 changes: 3 additions & 3 deletions inventory_management_system_api/routers/v1/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import logging
from typing import Annotated

from fastapi import APIRouter, Depends, status, HTTPException, Path
from fastapi import APIRouter, Depends, HTTPException, Path, status

from inventory_management_system_api.core.exceptions import (
DuplicateRecordError,
InvalidObjectIdError,
MissingRecordError,
PartOfCatalogueCategoryError,
)
from inventory_management_system_api.schemas.unit import UnitPostRequestSchema, UnitSchema
from inventory_management_system_api.schemas.unit import UnitPostSchema, UnitSchema
from inventory_management_system_api.services.unit import UnitService

logger = logging.getLogger()
Expand All @@ -30,7 +30,7 @@
response_description="The created unit",
status_code=status.HTTP_201_CREATED,
)
def create_unit(unit: UnitPostRequestSchema, unit_service: UnitServiceDep) -> UnitSchema:
def create_unit(unit: UnitPostSchema, unit_service: UnitServiceDep) -> UnitSchema:
# pylint: disable=missing-function-docstring
logger.info("Creating a new unit")
logger.debug("Unit data: %s", unit)
Expand Down
6 changes: 3 additions & 3 deletions inventory_management_system_api/routers/v1/usage_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import logging
from typing import Annotated

from fastapi import APIRouter, Depends, status, HTTPException, Path
from fastapi import APIRouter, Depends, HTTPException, Path, status

from inventory_management_system_api.core.exceptions import (
DuplicateRecordError,
InvalidObjectIdError,
MissingRecordError,
PartOfItemError,
)
from inventory_management_system_api.schemas.usage_status import UsageStatusPostRequestSchema, UsageStatusSchema
from inventory_management_system_api.schemas.usage_status import UsageStatusPostSchema, UsageStatusSchema
from inventory_management_system_api.services.usage_status import UsageStatusService

logger = logging.getLogger()
Expand All @@ -31,7 +31,7 @@
status_code=status.HTTP_201_CREATED,
)
def create_usage_status(
usage_status: UsageStatusPostRequestSchema, usage_status_service: UsageStatusServiceDep
usage_status: UsageStatusPostSchema, usage_status_service: UsageStatusServiceDep
) -> UsageStatusSchema:
# pylint: disable=missing-function-docstring
logger.info("Creating a new usage status")
Expand Down
22 changes: 11 additions & 11 deletions inventory_management_system_api/schemas/catalogue_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AllowedValuesListSchema(BaseModel):
AllowedValuesSchema = Annotated[AllowedValuesListSchema, Field(discriminator="type")]


class CatalogueCategoryPostRequestPropertySchema(BaseModel):
class CatalogueCategoryPostPropertySchema(BaseModel):
"""
Schema model for a property within a catalogue category creation request.
"""
Expand Down Expand Up @@ -117,7 +117,7 @@ def check_valid_allowed_values(

for allowed_value in allowed_values.values:
# Ensure the value is the correct type
if not CatalogueCategoryPostRequestPropertySchema.is_valid_property_type(
if not CatalogueCategoryPostPropertySchema.is_valid_property_type(
expected_property_type=property_data["type"], property_value=allowed_value
):
raise ValueError(
Expand Down Expand Up @@ -150,12 +150,12 @@ def validate_allowed_values(
:return: The value of the `allowed_values` field.
"""

CatalogueCategoryPostRequestPropertySchema.check_valid_allowed_values(allowed_values, info.data)
CatalogueCategoryPostPropertySchema.check_valid_allowed_values(allowed_values, info.data)

return allowed_values


class CatalogueCategoryPropertySchema(CatalogueCategoryPostRequestPropertySchema):
class CatalogueCategoryPropertySchema(CatalogueCategoryPostPropertySchema):
"""
Schema model representing a property defined within a catalogue category
"""
Expand All @@ -164,7 +164,7 @@ class CatalogueCategoryPropertySchema(CatalogueCategoryPostRequestPropertySchema
unit: Optional[str] = Field(default=None, description="The unit of the property such as 'nm', 'mm', 'cm' etc")


class CatalogueCategoryPostRequestSchema(BaseModel):
class CatalogueCategoryPostSchema(BaseModel):
"""
Schema model for a catalogue category creation request.
"""
Expand All @@ -175,7 +175,7 @@ class CatalogueCategoryPostRequestSchema(BaseModel):
"elements but if it is not then it can only have catalogue categories as child elements."
)
parent_id: Optional[str] = Field(default=None, description="The ID of the parent catalogue category")
properties: Optional[List[CatalogueCategoryPostRequestPropertySchema]] = Field(
properties: Optional[List[CatalogueCategoryPostPropertySchema]] = Field(
default=None, description="The properties that the catalogue items in this category could/should have"
)

Expand All @@ -184,7 +184,7 @@ class CatalogueCategoryPostRequestSchema(BaseModel):
CATALOGUE_CATEGORY_WITH_CHILD_NON_EDITABLE_FIELDS = ["is_leaf", "properties"]


class CatalogueCategoryPatchRequestSchema(CatalogueCategoryPostRequestSchema):
class CatalogueCategoryPatchSchema(CatalogueCategoryPostSchema):
"""
Schema model for a catalogue category update request.
"""
Expand All @@ -197,7 +197,7 @@ class CatalogueCategoryPatchRequestSchema(CatalogueCategoryPostRequestSchema):
)


class CatalogueCategorySchema(CreatedModifiedSchemaMixin, CatalogueCategoryPostRequestSchema):
class CatalogueCategorySchema(CreatedModifiedSchemaMixin, CatalogueCategoryPostSchema):
"""
Schema model for a catalogue category response.
"""
Expand All @@ -209,7 +209,7 @@ class CatalogueCategorySchema(CreatedModifiedSchemaMixin, CatalogueCategoryPostR
)


class CatalogueCategoryPropertyPostRequestSchema(CatalogueCategoryPostRequestPropertySchema):
class CatalogueCategoryPropertyPostSchema(CatalogueCategoryPostPropertySchema):
"""
Schema model for a property creation request on a catalogue category
"""
Expand All @@ -234,7 +234,7 @@ def validate_default_value(cls, default_value: Any, info: ValidationInfo) -> Any
:return: The value of the `allowed_values` field.
"""
if default_value is not None:
if not CatalogueCategoryPostRequestPropertySchema.is_valid_property_type(
if not CatalogueCategoryPostPropertySchema.is_valid_property_type(
expected_property_type=info.data["type"], property_value=default_value
):
raise ValueError("default_value must be the same type as the property itself")
Expand All @@ -251,7 +251,7 @@ def validate_default_value(cls, default_value: Any, info: ValidationInfo) -> Any
return default_value


class CatalogueCategoryPropertyPatchRequestSchema(BaseModel):
class CatalogueCategoryPropertyPatchSchema(BaseModel):
"""
Schema model for a property patch request on a catalogue category
"""
Expand Down
12 changes: 6 additions & 6 deletions inventory_management_system_api/schemas/catalogue_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from inventory_management_system_api.schemas.mixins import CreatedModifiedSchemaMixin


class PropertyPostRequestSchema(BaseModel):
class PropertyPostSchema(BaseModel):
"""
Schema model for a property creation request.
"""
Expand All @@ -18,7 +18,7 @@ class PropertyPostRequestSchema(BaseModel):
value: Any = Field(default=None, description="The value of the property")


class PropertySchema(PropertyPostRequestSchema):
class PropertySchema(PropertyPostSchema):
"""
Schema model for a property response.
"""
Expand All @@ -28,7 +28,7 @@ class PropertySchema(PropertyPostRequestSchema):
unit: Optional[str] = Field(default=None, description="The unit of the property such as 'nm', 'mm', 'cm' etc")


class CatalogueItemPostRequestSchema(BaseModel):
class CatalogueItemPostSchema(BaseModel):
"""
Schema model for a catalogue item creation request.
"""
Expand All @@ -54,7 +54,7 @@ class CatalogueItemPostRequestSchema(BaseModel):
default=None, description="The ID of the catalogue item that replaces this catalogue item if obsolete"
)
notes: Optional[str] = Field(default=None, description="Any notes about the catalogue item")
properties: Optional[List[PropertyPostRequestSchema]] = Field(
properties: Optional[List[PropertyPostSchema]] = Field(
default=None,
description="The properties specific to this catalogue item as defined in the corresponding "
"catalogue category",
Expand All @@ -65,7 +65,7 @@ class CatalogueItemPostRequestSchema(BaseModel):
CATALOGUE_ITEM_WITH_CHILD_NON_EDITABLE_FIELDS = ["manufacturer_id", "properties"]


class CatalogueItemPatchRequestSchema(CatalogueItemPostRequestSchema):
class CatalogueItemPatchSchema(CatalogueItemPostSchema):
"""
Schema model for a catalogue item update request.
"""
Expand All @@ -82,7 +82,7 @@ class CatalogueItemPatchRequestSchema(CatalogueItemPostRequestSchema):
is_obsolete: Optional[bool] = Field(default=None, description="Whether the catalogue item is obsolete or not")


class CatalogueItemSchema(CreatedModifiedSchemaMixin, CatalogueItemPostRequestSchema):
class CatalogueItemSchema(CreatedModifiedSchemaMixin, CatalogueItemPostSchema):
"""
Schema model for a catalogue item response.
"""
Expand Down
Loading

0 comments on commit 6c05a1e

Please sign in to comment.