fastapi-factory-utilities 0.2.5__py3-none-any.whl → 0.2.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fastapi-factory-utilities might be problematic. Click here for more details.
- fastapi_factory_utilities/core/plugins/odm_plugin/__init__.py +3 -0
- fastapi_factory_utilities/core/plugins/odm_plugin/documents.py +1 -0
- fastapi_factory_utilities/core/plugins/odm_plugin/repositories.py +46 -1
- {fastapi_factory_utilities-0.2.5.dist-info → fastapi_factory_utilities-0.2.7.dist-info}/METADATA +1 -1
- {fastapi_factory_utilities-0.2.5.dist-info → fastapi_factory_utilities-0.2.7.dist-info}/RECORD +8 -8
- {fastapi_factory_utilities-0.2.5.dist-info → fastapi_factory_utilities-0.2.7.dist-info}/WHEEL +1 -1
- {fastapi_factory_utilities-0.2.5.dist-info → fastapi_factory_utilities-0.2.7.dist-info}/LICENSE +0 -0
- {fastapi_factory_utilities-0.2.5.dist-info → fastapi_factory_utilities-0.2.7.dist-info}/entry_points.txt +0 -0
|
@@ -24,6 +24,7 @@ from fastapi_factory_utilities.core.services.status.types import (
|
|
|
24
24
|
from .builder import ODMBuilder
|
|
25
25
|
from .depends import depends_odm_client, depends_odm_database
|
|
26
26
|
from .documents import BaseDocument
|
|
27
|
+
from .exceptions import OperationError, UnableToCreateEntityDueToDuplicateKeyError
|
|
27
28
|
from .repositories import AbstractRepository
|
|
28
29
|
|
|
29
30
|
_logger: BoundLogger = get_logger()
|
|
@@ -161,6 +162,8 @@ async def on_shutdown(application: ApplicationAbstractProtocol) -> None:
|
|
|
161
162
|
__all__: list[str] = [
|
|
162
163
|
"BaseDocument",
|
|
163
164
|
"AbstractRepository",
|
|
165
|
+
"OperationError",
|
|
166
|
+
"UnableToCreateEntityDueToDuplicateKeyError",
|
|
164
167
|
"depends_odm_client",
|
|
165
168
|
"depends_odm_database",
|
|
166
169
|
]
|
|
@@ -17,6 +17,7 @@ class BaseDocument(Document):
|
|
|
17
17
|
default_factory=uuid4, description="The document ID."
|
|
18
18
|
)
|
|
19
19
|
|
|
20
|
+
revision_id: UUID | None
|
|
20
21
|
created_at: Annotated[datetime.datetime, Indexed(index_type=DESCENDING)] = Field( # pyright: ignore
|
|
21
22
|
default_factory=lambda: datetime.datetime.now(tz=datetime.UTC), description="Creation timestamp."
|
|
22
23
|
)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"""Provides the abstract classes for the repositories."""
|
|
2
2
|
|
|
3
|
+
import datetime
|
|
3
4
|
from abc import ABC
|
|
4
5
|
from collections.abc import AsyncGenerator, Callable
|
|
5
6
|
from contextlib import asynccontextmanager
|
|
6
7
|
from typing import Any, Generic, TypeVar, get_args
|
|
7
8
|
from uuid import UUID
|
|
9
|
+
from venv import create
|
|
8
10
|
|
|
9
11
|
from motor.motor_asyncio import AsyncIOMotorClientSession, AsyncIOMotorDatabase
|
|
10
12
|
from pydantic import BaseModel
|
|
@@ -77,8 +79,13 @@ class AbstractRepository(ABC, Generic[DocumentGenericType, EntityGenericType]):
|
|
|
77
79
|
UnableToCreateEntityDueToDuplicateKeyError: If the entity cannot be created due to a duplicate key error.
|
|
78
80
|
OperationError: If the operation fails.
|
|
79
81
|
"""
|
|
82
|
+
insert_time: datetime.datetime = datetime.datetime.now(tz=datetime.timezone.utc)
|
|
80
83
|
try:
|
|
81
|
-
|
|
84
|
+
entity_dump: dict[str, Any] = entity.model_dump()
|
|
85
|
+
entity_dump["created_at"] = insert_time
|
|
86
|
+
entity_dump["updated_at"] = insert_time
|
|
87
|
+
document: DocumentGenericType = self._document_type(**entity_dump)
|
|
88
|
+
|
|
82
89
|
except ValueError as error:
|
|
83
90
|
raise ValueError(f"Failed to create document from entity: {error}") from error
|
|
84
91
|
|
|
@@ -96,6 +103,44 @@ class AbstractRepository(ABC, Generic[DocumentGenericType, EntityGenericType]):
|
|
|
96
103
|
|
|
97
104
|
return entity_created
|
|
98
105
|
|
|
106
|
+
@managed_session()
|
|
107
|
+
async def update(
|
|
108
|
+
self, entity: EntityGenericType, session: AsyncIOMotorClientSession | None = None
|
|
109
|
+
) -> EntityGenericType:
|
|
110
|
+
"""Update the entity in the database.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
entity (EntityGenericType): The entity to update.
|
|
114
|
+
session (AsyncIOMotorClientSession | None): The session to use. Defaults to None. (managed by decorator)
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
EntityGenericType: The updated entity.
|
|
118
|
+
|
|
119
|
+
Raises:
|
|
120
|
+
ValueError: If the entity cannot be created from the document.
|
|
121
|
+
OperationError: If the operation fails.
|
|
122
|
+
"""
|
|
123
|
+
update_time: datetime.datetime = datetime.datetime.now(tz=datetime.timezone.utc)
|
|
124
|
+
try:
|
|
125
|
+
entity_dump: dict[str, Any] = entity.model_dump()
|
|
126
|
+
entity_dump["updated_at"] = update_time
|
|
127
|
+
document: DocumentGenericType = self._document_type(**entity_dump)
|
|
128
|
+
|
|
129
|
+
except ValueError as error:
|
|
130
|
+
raise ValueError(f"Failed to create document from entity: {error}") from error
|
|
131
|
+
|
|
132
|
+
try:
|
|
133
|
+
document_updated: DocumentGenericType = await document.save(session=session)
|
|
134
|
+
except PyMongoError as error:
|
|
135
|
+
raise OperationError(f"Failed to update document: {error}") from error
|
|
136
|
+
|
|
137
|
+
try:
|
|
138
|
+
entity_updated: EntityGenericType = self._entity_type(**document_updated.model_dump())
|
|
139
|
+
except ValueError as error:
|
|
140
|
+
raise ValueError(f"Failed to create entity from document: {error}") from error
|
|
141
|
+
|
|
142
|
+
return entity_updated
|
|
143
|
+
|
|
99
144
|
@managed_session()
|
|
100
145
|
async def get_one_by_id(
|
|
101
146
|
self,
|
{fastapi_factory_utilities-0.2.5.dist-info → fastapi_factory_utilities-0.2.7.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: fastapi_factory_utilities
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Consolidate libraries and utilities to create microservices in Python with FastAPI, Beanie, Httpx, AioPika and OpenTelemetry.
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: python,fastapi,beanie,httpx,opentelemetry,microservices
|
{fastapi_factory_utilities-0.2.5.dist-info → fastapi_factory_utilities-0.2.7.dist-info}/RECORD
RENAMED
|
@@ -19,13 +19,13 @@ fastapi_factory_utilities/core/exceptions.py,sha256=7ntbaMptYn5OOPeKPVR4zU98NIC0
|
|
|
19
19
|
fastapi_factory_utilities/core/plugins/__init__.py,sha256=W-BCkqP0xG980980z3mc8T6Vrp1Akv4szA0PRzkUbiU,756
|
|
20
20
|
fastapi_factory_utilities/core/plugins/example/__init__.py,sha256=GF69IygLXxzrCh7VryekEWun663kKBhWtRS3w-1tzBc,1030
|
|
21
21
|
fastapi_factory_utilities/core/plugins/httpx_plugin/__init__.py,sha256=P5FUyv7mQr8RZWQ8ifkoK8GXvqSI71q2b2dm-ag2JhQ,1028
|
|
22
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/__init__.py,sha256=
|
|
22
|
+
fastapi_factory_utilities/core/plugins/odm_plugin/__init__.py,sha256=L6iZW7beZLpvXbcXoTjP6iALEwWWymworb6Mok72s2w,5741
|
|
23
23
|
fastapi_factory_utilities/core/plugins/odm_plugin/builder.py,sha256=3B5EgY8deS_dr9NYZbeJq9cibPs65kN0Ogg-1yecF3s,8547
|
|
24
24
|
fastapi_factory_utilities/core/plugins/odm_plugin/configs.py,sha256=zQoJC1wLNyq2pZyFhl0bKeNsTl4y_4_82BHCCaOEjCQ,331
|
|
25
25
|
fastapi_factory_utilities/core/plugins/odm_plugin/depends.py,sha256=OcLsfTLzMBk_xFV6qsMy_-qFkiphEbbEuaHUooagxg8,730
|
|
26
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/documents.py,sha256=
|
|
26
|
+
fastapi_factory_utilities/core/plugins/odm_plugin/documents.py,sha256=nmvSAqMqwg0VdEaZFpBAYc6bcstlCP3sKs4gI7uzUN8,1104
|
|
27
27
|
fastapi_factory_utilities/core/plugins/odm_plugin/exceptions.py,sha256=acnKJB0lGAzDs-7-LjBap8shjP3iV1a7dw7ouPVF27o,551
|
|
28
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/repositories.py,sha256=
|
|
28
|
+
fastapi_factory_utilities/core/plugins/odm_plugin/repositories.py,sha256=5hZ5Cvdqqlnb4NITWlrg_o078B4U0U61MjAXG3VxcH8,8747
|
|
29
29
|
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/__init__.py,sha256=UsXPjiAASn5GIHW8vrF32mklxGNq8ajILV-ty4K1Tbs,4371
|
|
30
30
|
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/builder.py,sha256=DsD1vUtTIMXCxLsQ2KbMaQthdPfvZsI95uLdD7pkeiE,9838
|
|
31
31
|
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/configs.py,sha256=4mMa5SrmnPY1R_gVFRtFhi9WNaTGEGZL5iNNhyjcZQ0,3448
|
|
@@ -64,8 +64,8 @@ fastapi_factory_utilities/example/models/books/repository.py,sha256=7K63uAsSEGZ2
|
|
|
64
64
|
fastapi_factory_utilities/example/services/books/__init__.py,sha256=Z06yNRoA7Zg3TGN-Q9rrvJg6Bbx-qJw661MVwukV6vQ,148
|
|
65
65
|
fastapi_factory_utilities/example/services/books/services.py,sha256=-x7d4hotUWLzWo5uImMjFmtNcSTHwWv2bfttIbYYKbA,5380
|
|
66
66
|
fastapi_factory_utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
67
|
-
fastapi_factory_utilities-0.2.
|
|
68
|
-
fastapi_factory_utilities-0.2.
|
|
69
|
-
fastapi_factory_utilities-0.2.
|
|
70
|
-
fastapi_factory_utilities-0.2.
|
|
71
|
-
fastapi_factory_utilities-0.2.
|
|
67
|
+
fastapi_factory_utilities-0.2.7.dist-info/LICENSE,sha256=iO1nLzMMst6vEiqgSUrfrbetM7b0bvdzXhbed5tqG8o,1074
|
|
68
|
+
fastapi_factory_utilities-0.2.7.dist-info/METADATA,sha256=I0J9iqi3kmbs5k1-3VKjB7HqWsCufqLZE3XOYK05GrA,3314
|
|
69
|
+
fastapi_factory_utilities-0.2.7.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
70
|
+
fastapi_factory_utilities-0.2.7.dist-info/entry_points.txt,sha256=IK0VcBexXo4uXQmTrbfhhnnfq4GmXPRn0GBB8hzlsq4,101
|
|
71
|
+
fastapi_factory_utilities-0.2.7.dist-info/RECORD,,
|
{fastapi_factory_utilities-0.2.5.dist-info → fastapi_factory_utilities-0.2.7.dist-info}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|