Skip to content

Commit

Permalink
feat(repo): add processing for case when value is not found when upda…
Browse files Browse the repository at this point in the history
…ting in the database
  • Loading branch information
raf-nr committed Oct 2, 2024
1 parent b2ffbe3 commit 673611c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/dto/repository/exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ModelNotFoundException(Exception):
def __init__(self, message: str):
super().__init__(message)
6 changes: 6 additions & 0 deletions internal/repository/relational/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
BaseResponseSchema,
)
from internal.infrastructure.data_storage import Context
from internal.dto.repository.exception import ModelNotFoundException


class CRUD[
Expand Down Expand Up @@ -70,6 +71,11 @@ def update(
) -> ResponseSchema:

db_model_instance = self._find(find_schema, context)
if not db_model_instance:
raise ModelNotFoundException(
"When updating data, the required row was not found in the database."
)

update_schema_dict = update_schema.model_dump()
fields_to_update_if_none = (
fields_to_update_if_none if fields_to_update_if_none else set()
Expand Down

0 comments on commit 673611c

Please sign in to comment.