architectonics 0.0.33__py3-none-any.whl → 0.0.35__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.
- architectonics/core/models/base_model.py +11 -1
- architectonics/core/models/deleted_models.py +8 -0
- architectonics/core/services/base_service.py +28 -30
- architectonics/infrastructure/repositories/base_repository.py +17 -24
- {architectonics-0.0.33.dist-info → architectonics-0.0.35.dist-info}/METADATA +1 -1
- {architectonics-0.0.33.dist-info → architectonics-0.0.35.dist-info}/RECORD +7 -6
- {architectonics-0.0.33.dist-info → architectonics-0.0.35.dist-info}/WHEEL +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from dataclasses import dataclass, field
|
|
1
|
+
from dataclasses import asdict, dataclass, field
|
|
2
2
|
from datetime import datetime
|
|
3
3
|
import uuid
|
|
4
4
|
|
|
@@ -18,3 +18,13 @@ class BaseModel:
|
|
|
18
18
|
updated_at: datetime = field(
|
|
19
19
|
default_factory=datetime.utcnow,
|
|
20
20
|
)
|
|
21
|
+
|
|
22
|
+
def to_update_dict(self) -> dict[str, any]:
|
|
23
|
+
now = datetime.utcnow()
|
|
24
|
+
|
|
25
|
+
values = {k: v for k, v in asdict(self).items() if k not in {"id", "created_at"} and v is not None}
|
|
26
|
+
|
|
27
|
+
values["updated_at"] = now
|
|
28
|
+
self.updated_at = now
|
|
29
|
+
|
|
30
|
+
return values
|
|
@@ -6,6 +6,7 @@ from starlette.status import (
|
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
from architectonics.core.models.base_model import BaseModel
|
|
9
|
+
from architectonics.core.models.deleted_models import DeletedModel
|
|
9
10
|
from architectonics.core.result.service_result import ServiceResult
|
|
10
11
|
from architectonics.core.services.base_schemas import (
|
|
11
12
|
BaseModelCreateSchema,
|
|
@@ -80,50 +81,47 @@ class BaseService:
|
|
|
80
81
|
value=model,
|
|
81
82
|
)
|
|
82
83
|
|
|
83
|
-
"""
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
84
|
async def update_model(
|
|
89
85
|
self,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
) -> tuple[BaseModel | None, str | dict[str, list[str]] | None, int]:
|
|
93
|
-
|
|
94
|
-
schema_dict = update_schema.model_dump(by_alias=False)
|
|
86
|
+
model: BaseModel,
|
|
87
|
+
) -> ServiceResult[BaseModel, BaseModelValidationErrors]:
|
|
95
88
|
|
|
96
|
-
|
|
89
|
+
validation_errors = await self.validate(model)
|
|
97
90
|
|
|
98
|
-
if
|
|
99
|
-
return
|
|
91
|
+
if validation_errors.has_errors():
|
|
92
|
+
return ServiceResult[BaseModel, BaseModelValidationErrors].validation_failure(
|
|
93
|
+
validation_errors=validation_errors,
|
|
94
|
+
)
|
|
100
95
|
|
|
101
96
|
try:
|
|
102
97
|
model = await self._repository.update_model(
|
|
103
|
-
|
|
104
|
-
values=attrs,
|
|
98
|
+
model=model,
|
|
105
99
|
)
|
|
106
|
-
except IntegrityErrorException as
|
|
107
|
-
return
|
|
100
|
+
except IntegrityErrorException as error:
|
|
101
|
+
return ServiceResult[BaseModel, BaseModelValidationErrors].failure(error_message=error)
|
|
108
102
|
except ObjectNotFoundException:
|
|
109
|
-
return
|
|
103
|
+
return ServiceResult[BaseModel, BaseModelValidationErrors].failure(
|
|
104
|
+
error_message="object_not_found",
|
|
105
|
+
)
|
|
110
106
|
|
|
111
|
-
return
|
|
107
|
+
return ServiceResult[BaseModel, BaseModelValidationErrors].success(value=model)
|
|
112
108
|
|
|
113
109
|
async def delete_model(
|
|
114
110
|
self,
|
|
115
111
|
model_id: str,
|
|
116
|
-
) ->
|
|
112
|
+
) -> ServiceResult[DeletedModel, BaseModelValidationErrors]:
|
|
117
113
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return
|
|
114
|
+
try:
|
|
115
|
+
await self._repository.delete_model(
|
|
116
|
+
model_id=model_id,
|
|
117
|
+
)
|
|
118
|
+
except ObjectNotFoundException:
|
|
119
|
+
return ServiceResult[BaseModel, BaseModelValidationErrors].failure(
|
|
120
|
+
error_message="object_not_found",
|
|
121
|
+
)
|
|
124
122
|
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
return ServiceResult[DeletedModel, BaseModelValidationErrors].success(
|
|
124
|
+
value=DeletedModel(
|
|
125
|
+
id=model_id,
|
|
126
|
+
),
|
|
127
127
|
)
|
|
128
|
-
|
|
129
|
-
return "object_deleted", None, HTTP_200_OK"""
|
|
@@ -2,17 +2,17 @@ from abc import ABC
|
|
|
2
2
|
from typing import Callable
|
|
3
3
|
|
|
4
4
|
from asyncpg.exceptions import ForeignKeyViolationError
|
|
5
|
+
from sqlalchemy import delete, select, update
|
|
6
|
+
from sqlalchemy.exc import IntegrityError
|
|
7
|
+
from sqlalchemy.ext.asyncio import AsyncSession
|
|
8
|
+
|
|
9
|
+
from architectonics.core.models.base_model import BaseModel
|
|
5
10
|
from architectonics.infrastructure.entities.base_entity import BaseEntity
|
|
6
11
|
from architectonics.infrastructure.repositories.base_exceptions import (
|
|
7
12
|
IntegrityErrorException,
|
|
8
13
|
ObjectAlreadyExistsException,
|
|
9
14
|
ObjectNotFoundException,
|
|
10
15
|
)
|
|
11
|
-
from sqlalchemy import delete, select, update
|
|
12
|
-
from sqlalchemy.exc import IntegrityError
|
|
13
|
-
from sqlalchemy.ext.asyncio import AsyncSession
|
|
14
|
-
|
|
15
|
-
from architectonics.core.models.base_model import BaseModel
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class BaseRepository(ABC):
|
|
@@ -72,30 +72,23 @@ class BaseRepository(ABC):
|
|
|
72
72
|
|
|
73
73
|
async def update_model(
|
|
74
74
|
self,
|
|
75
|
-
|
|
76
|
-
values: dict[str, any],
|
|
75
|
+
model: BaseModel,
|
|
77
76
|
) -> BaseModel:
|
|
78
77
|
|
|
79
|
-
|
|
78
|
+
updated_values = model.to_update_dict()
|
|
80
79
|
|
|
81
80
|
update_statement = (
|
|
82
81
|
update(
|
|
83
82
|
self._entity,
|
|
84
83
|
)
|
|
85
84
|
.where(
|
|
86
|
-
self._entity.id ==
|
|
85
|
+
self._entity.id == model.id,
|
|
87
86
|
)
|
|
88
87
|
.values(
|
|
89
|
-
**
|
|
88
|
+
**updated_values,
|
|
90
89
|
)
|
|
91
90
|
)
|
|
92
91
|
|
|
93
|
-
get_statement = select(
|
|
94
|
-
self._entity,
|
|
95
|
-
).where(
|
|
96
|
-
self._entity.id == model_id,
|
|
97
|
-
)
|
|
98
|
-
|
|
99
92
|
async with self.get_session() as session:
|
|
100
93
|
try:
|
|
101
94
|
result = await session.execute(update_statement)
|
|
@@ -109,13 +102,7 @@ class BaseRepository(ABC):
|
|
|
109
102
|
|
|
110
103
|
raise IntegrityErrorException(e)
|
|
111
104
|
|
|
112
|
-
|
|
113
|
-
model = result.scalars().first()
|
|
114
|
-
|
|
115
|
-
if model is None:
|
|
116
|
-
raise ObjectNotFoundException()
|
|
117
|
-
|
|
118
|
-
return model.to_model()
|
|
105
|
+
return model
|
|
119
106
|
|
|
120
107
|
async def delete_model(
|
|
121
108
|
self,
|
|
@@ -129,7 +116,13 @@ class BaseRepository(ABC):
|
|
|
129
116
|
)
|
|
130
117
|
|
|
131
118
|
async with self.get_session() as session:
|
|
132
|
-
await session.execute(
|
|
119
|
+
result = await session.execute(
|
|
120
|
+
statement=statement,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
if result.rowcount == 0:
|
|
124
|
+
raise ObjectNotFoundException()
|
|
125
|
+
|
|
133
126
|
await session.commit()
|
|
134
127
|
|
|
135
128
|
async def get_models_list(
|
|
@@ -7,12 +7,13 @@ architectonics/core/config/application_settings.py,sha256=DmCjQCbm4BsxMoZuQ212Pj
|
|
|
7
7
|
architectonics/core/factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
architectonics/core/factory/factory.py,sha256=C9TDhkhq5lcdcBnICy4DgJj0yjeCIhq-UVSwaf-aTmM,748
|
|
9
9
|
architectonics/core/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
architectonics/core/models/base_model.py,sha256
|
|
10
|
+
architectonics/core/models/base_model.py,sha256=-dT4UqQCSW41Ip6Cb41Bkudh45Co71EsReYOdwF4BMs,663
|
|
11
|
+
architectonics/core/models/deleted_models.py,sha256=9hqdZgCC2JhAriA_GA7P2uA32rk5UAEXvGA3u8HVIME,151
|
|
11
12
|
architectonics/core/result/error_message.py,sha256=sMIMVt58wGo33E9lD4r6k9tRkgL2TpO7yjX-BZc6PHI,97
|
|
12
13
|
architectonics/core/result/service_result.py,sha256=VwjegZKR38ocAEriY_0rnnPn69u09HDja4y3iKq0z9w,1879
|
|
13
14
|
architectonics/core/schemas/base_schemas.py,sha256=4ghwg7h06uIoBRkXGtWDFQA7Yb6Hvo4AsIA80xmSlFk,415
|
|
14
15
|
architectonics/core/services/base_schemas.py,sha256=9PpCcf5GaE68s2VDKiAWRNufhFL2iN5djOcMsir8HMk,295
|
|
15
|
-
architectonics/core/services/base_service.py,sha256=
|
|
16
|
+
architectonics/core/services/base_service.py,sha256=hYYQ73icgMnwnDRjGd1rqYlE5qvsVvneKHosjEEHysU,4149
|
|
16
17
|
architectonics/core/validation/base_model_validation_errors.py,sha256=Z3nGM3XaHbkW0z2qhVjwd8t0EbYULArIHARa0IYCNVg,306
|
|
17
18
|
architectonics/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
19
|
architectonics/infrastructure/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -21,7 +22,7 @@ architectonics/infrastructure/config/database_settings.py,sha256=d1HA8rQj3LMACEv
|
|
|
21
22
|
architectonics/infrastructure/entities/base_entity.py,sha256=EqmmY2aVzqIdgJPsKBUBtesOfsmSSNrRuBGGQQ6bpJA,818
|
|
22
23
|
architectonics/infrastructure/repositories/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
24
|
architectonics/infrastructure/repositories/base_exceptions.py,sha256=kOeu3p90LHMxCcp2cCL_Anrsz4CTLtELWqma_RCQSqM,303
|
|
24
|
-
architectonics/infrastructure/repositories/base_repository.py,sha256=
|
|
25
|
-
architectonics-0.0.
|
|
26
|
-
architectonics-0.0.
|
|
27
|
-
architectonics-0.0.
|
|
25
|
+
architectonics/infrastructure/repositories/base_repository.py,sha256=y9Q2SPj1t55gRrUaNrSZ7SnuEGVYRAlwuU3fhNwtzt8,3585
|
|
26
|
+
architectonics-0.0.35.dist-info/WHEEL,sha256=y3eDiaFVSNTPbgzfNn0nYn5tEn1cX6WrdetDlQM4xWw,83
|
|
27
|
+
architectonics-0.0.35.dist-info/METADATA,sha256=xAEwbOoRpQui4bDEHoq492lae0wJ4ZrVXjEFseJtgpQ,469
|
|
28
|
+
architectonics-0.0.35.dist-info/RECORD,,
|
|
File without changes
|