apexdevkit 1.3.3__tar.gz → 1.3.4__tar.gz
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.
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/PKG-INFO +1 -1
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/fastapi/router.py +40 -24
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/pyproject.toml +1 -1
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/LICENSE +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/README.md +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/error.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.3.3 → apexdevkit-1.3.4}/apexdevkit/testing/rest.py +0 -0
|
@@ -2,7 +2,7 @@ from dataclasses import dataclass, field
|
|
|
2
2
|
from functools import cached_property
|
|
3
3
|
from typing import Annotated, Any, Iterable, Self, TypeVar
|
|
4
4
|
|
|
5
|
-
from fastapi import APIRouter, Depends
|
|
5
|
+
from fastapi import APIRouter, Depends, Path
|
|
6
6
|
from fastapi.responses import JSONResponse
|
|
7
7
|
|
|
8
8
|
from apexdevkit.error import DoesNotExistError, ExistsError
|
|
@@ -88,6 +88,14 @@ class RestfulRouter:
|
|
|
88
88
|
def schema(self) -> RestfulSchema:
|
|
89
89
|
return RestfulSchema(name=self.name, fields=self.fields)
|
|
90
90
|
|
|
91
|
+
@property
|
|
92
|
+
def id_alias(self) -> str:
|
|
93
|
+
return self.name.singular + "_id"
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def item_path(self) -> str:
|
|
97
|
+
return "/{" + self.id_alias + "}"
|
|
98
|
+
|
|
91
99
|
def with_dataclass(self, value: Any) -> Self:
|
|
92
100
|
return self.with_name(RestfulName(value.__name__.lower())).with_fields(
|
|
93
101
|
DataclassFields(value)
|
|
@@ -104,7 +112,10 @@ class RestfulRouter:
|
|
|
104
112
|
return self
|
|
105
113
|
|
|
106
114
|
def with_create_one_endpoint(self, is_documented: bool = True) -> Self:
|
|
107
|
-
|
|
115
|
+
item_type = Annotated[
|
|
116
|
+
RawItem,
|
|
117
|
+
Depends(self.schema.for_create_one()),
|
|
118
|
+
]
|
|
108
119
|
|
|
109
120
|
@self.router.post(
|
|
110
121
|
"",
|
|
@@ -113,7 +124,7 @@ class RestfulRouter:
|
|
|
113
124
|
response_model=self.schema.for_item(),
|
|
114
125
|
include_in_schema=is_documented,
|
|
115
126
|
)
|
|
116
|
-
def create_one(item:
|
|
127
|
+
def create_one(item: item_type) -> _Response:
|
|
117
128
|
try:
|
|
118
129
|
item = self.service.create_one(item)
|
|
119
130
|
except ExistsError as e:
|
|
@@ -124,7 +135,10 @@ class RestfulRouter:
|
|
|
124
135
|
return self
|
|
125
136
|
|
|
126
137
|
def with_create_many_endpoint(self, is_documented: bool = True) -> Self:
|
|
127
|
-
|
|
138
|
+
collection_type = Annotated[
|
|
139
|
+
RawCollection,
|
|
140
|
+
Depends(self.schema.for_create_many()),
|
|
141
|
+
]
|
|
128
142
|
|
|
129
143
|
@self.router.post(
|
|
130
144
|
"/batch",
|
|
@@ -133,7 +147,7 @@ class RestfulRouter:
|
|
|
133
147
|
response_model=self.schema.for_collection(),
|
|
134
148
|
include_in_schema=is_documented,
|
|
135
149
|
)
|
|
136
|
-
def create_many(items:
|
|
150
|
+
def create_many(items: collection_type) -> _Response:
|
|
137
151
|
try:
|
|
138
152
|
return self.response.created_many(self.service.create_many(items))
|
|
139
153
|
except ExistsError as e:
|
|
@@ -142,16 +156,16 @@ class RestfulRouter:
|
|
|
142
156
|
return self
|
|
143
157
|
|
|
144
158
|
def with_read_one_endpoint(self, is_documented: bool = True) -> Self:
|
|
145
|
-
|
|
159
|
+
id_type = Annotated[str, Path(alias=self.id_alias)]
|
|
146
160
|
|
|
147
161
|
@self.router.get(
|
|
148
|
-
|
|
162
|
+
self.item_path,
|
|
149
163
|
status_code=200,
|
|
150
164
|
responses={404: {}},
|
|
151
|
-
response_model=schema,
|
|
165
|
+
response_model=self.schema.for_item(),
|
|
152
166
|
include_in_schema=is_documented,
|
|
153
167
|
)
|
|
154
|
-
def read_one(item_id:
|
|
168
|
+
def read_one(item_id: id_type) -> _Response:
|
|
155
169
|
try:
|
|
156
170
|
return self.response.found_one(self.service.read_one(item_id))
|
|
157
171
|
except DoesNotExistError as e:
|
|
@@ -160,13 +174,11 @@ class RestfulRouter:
|
|
|
160
174
|
return self
|
|
161
175
|
|
|
162
176
|
def with_read_all_endpoint(self, is_documented: bool = True) -> Self:
|
|
163
|
-
schema = self.schema.for_collection()
|
|
164
|
-
|
|
165
177
|
@self.router.get(
|
|
166
178
|
"",
|
|
167
179
|
status_code=200,
|
|
168
180
|
responses={},
|
|
169
|
-
response_model=schema,
|
|
181
|
+
response_model=self.schema.for_collection(),
|
|
170
182
|
include_in_schema=is_documented,
|
|
171
183
|
)
|
|
172
184
|
def read_all() -> _Response:
|
|
@@ -175,19 +187,20 @@ class RestfulRouter:
|
|
|
175
187
|
return self
|
|
176
188
|
|
|
177
189
|
def with_update_one_endpoint(self, is_documented: bool = True) -> Self:
|
|
178
|
-
|
|
190
|
+
id_type = Annotated[str, Path(alias=self.id_alias)]
|
|
191
|
+
update_type = Annotated[
|
|
192
|
+
RawItem,
|
|
193
|
+
Depends(self.schema.for_update_one()),
|
|
194
|
+
]
|
|
179
195
|
|
|
180
196
|
@self.router.patch(
|
|
181
|
-
|
|
197
|
+
self.item_path,
|
|
182
198
|
status_code=200,
|
|
183
199
|
responses={404: {}},
|
|
184
200
|
response_model=self.schema.for_no_data(),
|
|
185
201
|
include_in_schema=is_documented,
|
|
186
202
|
)
|
|
187
|
-
def update_one(
|
|
188
|
-
item_id: str,
|
|
189
|
-
updates: Annotated[RawItem, Depends(schema)],
|
|
190
|
-
) -> _Response:
|
|
203
|
+
def update_one(item_id: id_type, updates: update_type) -> _Response:
|
|
191
204
|
try:
|
|
192
205
|
self.service.update_one(item_id, **updates)
|
|
193
206
|
except DoesNotExistError as e:
|
|
@@ -198,7 +211,10 @@ class RestfulRouter:
|
|
|
198
211
|
return self
|
|
199
212
|
|
|
200
213
|
def with_update_many_endpoint(self, is_documented: bool = True) -> Self:
|
|
201
|
-
|
|
214
|
+
collection_type = Annotated[
|
|
215
|
+
RawCollection,
|
|
216
|
+
Depends(self.schema.for_update_many()),
|
|
217
|
+
]
|
|
202
218
|
|
|
203
219
|
@self.router.patch(
|
|
204
220
|
"",
|
|
@@ -207,7 +223,7 @@ class RestfulRouter:
|
|
|
207
223
|
response_model=self.schema.for_no_data(),
|
|
208
224
|
include_in_schema=is_documented,
|
|
209
225
|
)
|
|
210
|
-
def update_many(items:
|
|
226
|
+
def update_many(items: collection_type) -> _Response:
|
|
211
227
|
self.service.update_many(items)
|
|
212
228
|
|
|
213
229
|
return self.response.ok()
|
|
@@ -215,16 +231,16 @@ class RestfulRouter:
|
|
|
215
231
|
return self
|
|
216
232
|
|
|
217
233
|
def with_delete_one_endpoint(self, is_documented: bool = True) -> Self:
|
|
218
|
-
|
|
234
|
+
id_type = Annotated[str, Path(alias=self.id_alias)]
|
|
219
235
|
|
|
220
236
|
@self.router.delete(
|
|
221
|
-
|
|
237
|
+
self.item_path,
|
|
222
238
|
status_code=200,
|
|
223
239
|
responses={404: {}},
|
|
224
|
-
response_model=schema,
|
|
240
|
+
response_model=self.schema.for_no_data(),
|
|
225
241
|
include_in_schema=is_documented,
|
|
226
242
|
)
|
|
227
|
-
def delete_one(item_id:
|
|
243
|
+
def delete_one(item_id: id_type) -> _Response:
|
|
228
244
|
try:
|
|
229
245
|
self.service.delete_one(item_id)
|
|
230
246
|
except DoesNotExistError as e:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|