Skip to content

Commit

Permalink
Add spares definition get endpoint #414
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Nov 22, 2024
1 parent f737d09 commit 3e8f3cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions inventory_management_system_api/routers/v1/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ def set_spares_definition(
message = "A specified usage status does not exist"
logger.exception(message)
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=message) from exc


@router.get(
path="/spares_definition", summary="Get the definition of a spare", response_description="Spares definition"
)
def get_spares_definition(setting_service: SettingServiceDep) -> SparesDefinitionSchema:
# pylint: disable=missing-function-docstring
logger.info("Getting spares definition")

spares_definition = setting_service.get_spares_definition()
if not spares_definition:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Spares definition not found.")
return spares_definition
9 changes: 9 additions & 0 deletions inventory_management_system_api/services/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,12 @@ def set_spares_definition(self, spares_definition: SparesDefinitionPutSchema) ->
return self._setting_repository.upsert(
SparesDefinitionIn(**spares_definition.model_dump()), SparesDefinitionOut
)

def get_spares_definition(self) -> SparesDefinitionOut:
"""
Retrieves the spares definition.
:return: Retrieved spares definition or `None` if not found.
"""

return self._setting_repository.get(SparesDefinitionOut)

Check warning on line 63 in inventory_management_system_api/services/setting.py

View check run for this annotation

Codecov / codecov/patch

inventory_management_system_api/services/setting.py#L63

Added line #L63 was not covered by tests

0 comments on commit 3e8f3cd

Please sign in to comment.