fastapi-factory-utilities 0.2.6__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.

@@ -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
- document: DocumentGenericType = self._document_type(**entity.model_dump())
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,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: fastapi_factory_utilities
3
- Version: 0.2.6
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
@@ -23,9 +23,9 @@ fastapi_factory_utilities/core/plugins/odm_plugin/__init__.py,sha256=L6iZW7beZLp
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=ENEB-Lm3T7_tN1xuIYPsUh8fpWj4aqh0xmrZt6vJCK0,1075
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=Wxh5C_gnU4jY8H5qpvcFuSlaM1dLrsDXqxGuuaxwB68,6912
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.6.dist-info/LICENSE,sha256=iO1nLzMMst6vEiqgSUrfrbetM7b0bvdzXhbed5tqG8o,1074
68
- fastapi_factory_utilities-0.2.6.dist-info/METADATA,sha256=LuzPSV0nloOtFJ345Lqj3r1i3aqC1g5frzlEOYVG_2M,3314
69
- fastapi_factory_utilities-0.2.6.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
70
- fastapi_factory_utilities-0.2.6.dist-info/entry_points.txt,sha256=IK0VcBexXo4uXQmTrbfhhnnfq4GmXPRn0GBB8hzlsq4,101
71
- fastapi_factory_utilities-0.2.6.dist-info/RECORD,,
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,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.1
2
+ Generator: poetry-core 2.1.2
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any