apexdevkit 1.23.5__tar.gz → 1.23.7__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.23.5 → apexdevkit-1.23.7}/PKG-INFO +1 -1
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/resource.py +22 -5
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/router.py +26 -2
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/schema.py +25 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/service.py +5 -2
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/testing/rest.py +9 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/pyproject.toml +1 -1
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/LICENSE +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/README.md +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/date.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/environment.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/error.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/name.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/request.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fastapi/response.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/fluent.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/http/httpx/__init__.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/http/httpx/client.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/http/httpx/hooks.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/id.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/key_fn.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/query/__init__.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/query/generator.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/query/query.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/decorator.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/mssql.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/repository.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/sql.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/repository/sqlite.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/server.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/synchronization.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.23.5 → apexdevkit-1.23.7}/apexdevkit/value.py +0 -0
|
@@ -79,12 +79,23 @@ class RestfulResource:
|
|
|
79
79
|
|
|
80
80
|
return endpoint
|
|
81
81
|
|
|
82
|
-
def filter_with(self, Service) -> _Endpoint: # type: ignore
|
|
83
|
-
def endpoint(service: Service, options:
|
|
82
|
+
def filter_with(self, Service, QueryOptions) -> _Endpoint: # type: ignore
|
|
83
|
+
def endpoint(service: Service, options: QueryOptions) -> _Response:
|
|
84
84
|
try:
|
|
85
|
-
return self.response.found_many(
|
|
86
|
-
|
|
87
|
-
)
|
|
85
|
+
return self.response.found_many(list(service.filter_with(options)))
|
|
86
|
+
except ForbiddenError as e:
|
|
87
|
+
return JSONResponse(self.response.forbidden(e), 403)
|
|
88
|
+
|
|
89
|
+
return endpoint
|
|
90
|
+
|
|
91
|
+
def sum_with(self, Service, FilterOptions) -> _Endpoint: # type: ignore
|
|
92
|
+
def endpoint(service: Service, options: FilterOptions) -> _Response:
|
|
93
|
+
try:
|
|
94
|
+
return {
|
|
95
|
+
"status": "success",
|
|
96
|
+
"code": 200,
|
|
97
|
+
"count": service.sum_with(options),
|
|
98
|
+
}
|
|
88
99
|
except ForbiddenError as e:
|
|
89
100
|
return JSONResponse(self.response.forbidden(e), 403)
|
|
90
101
|
|
|
@@ -314,3 +325,9 @@ class SummaryResponse(BaseModel):
|
|
|
314
325
|
status: str
|
|
315
326
|
code: int
|
|
316
327
|
data: _SummaryListEnvelope
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
class SumResponse(BaseModel):
|
|
331
|
+
status: str
|
|
332
|
+
code: int
|
|
333
|
+
count: int
|
|
@@ -7,7 +7,7 @@ from fastapi import APIRouter, Depends, Path, Query
|
|
|
7
7
|
from fastapi.responses import JSONResponse
|
|
8
8
|
|
|
9
9
|
from apexdevkit.fastapi.name import RestfulName
|
|
10
|
-
from apexdevkit.fastapi.resource import RestfulResource, SummaryResponse
|
|
10
|
+
from apexdevkit.fastapi.resource import RestfulResource, SummaryResponse, SumResponse
|
|
11
11
|
from apexdevkit.fastapi.response import RestfulResponse
|
|
12
12
|
from apexdevkit.fastapi.schema import RestfulSchema, Schema, SchemaFields
|
|
13
13
|
from apexdevkit.fastapi.service import RawCollection, RawItem, RestfulService
|
|
@@ -171,7 +171,10 @@ class RestfulRouter:
|
|
|
171
171
|
) -> Self:
|
|
172
172
|
self.router.add_api_route(
|
|
173
173
|
"/filter",
|
|
174
|
-
self.resource.filter_with(
|
|
174
|
+
self.resource.filter_with(
|
|
175
|
+
Service=self._resolve(dependency),
|
|
176
|
+
QueryOptions=Annotated[RawItem, Depends(self.schema.for_filters())],
|
|
177
|
+
),
|
|
175
178
|
methods=["POST"],
|
|
176
179
|
status_code=200,
|
|
177
180
|
responses={},
|
|
@@ -182,6 +185,27 @@ class RestfulRouter:
|
|
|
182
185
|
|
|
183
186
|
return self
|
|
184
187
|
|
|
188
|
+
def with_sum_endpoint(
|
|
189
|
+
self,
|
|
190
|
+
dependency: Dependency | None = None,
|
|
191
|
+
is_documented: bool = True,
|
|
192
|
+
) -> Self:
|
|
193
|
+
self.router.add_api_route(
|
|
194
|
+
"/sum",
|
|
195
|
+
self.resource.sum_with(
|
|
196
|
+
Service=self._resolve(dependency),
|
|
197
|
+
FilterOptions=Annotated[RawItem, Depends(self.schema.for_sum())],
|
|
198
|
+
),
|
|
199
|
+
methods=["POST"],
|
|
200
|
+
status_code=200,
|
|
201
|
+
responses={},
|
|
202
|
+
response_model=SumResponse,
|
|
203
|
+
include_in_schema=is_documented,
|
|
204
|
+
summary="Sum",
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
return self
|
|
208
|
+
|
|
185
209
|
def with_read_all_endpoint(
|
|
186
210
|
self,
|
|
187
211
|
dependency: Dependency | None = None,
|
|
@@ -8,6 +8,7 @@ from pydantic import BaseModel, create_model
|
|
|
8
8
|
|
|
9
9
|
from apexdevkit.fastapi.name import RestfulName
|
|
10
10
|
from apexdevkit.fluent import FluentDict
|
|
11
|
+
from apexdevkit.http import JsonDict
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class SchemaFields(ABC):
|
|
@@ -20,6 +21,12 @@ class SchemaFields(ABC):
|
|
|
20
21
|
def editable(self) -> FluentDict[type]:
|
|
21
22
|
return self.readable().drop("id")
|
|
22
23
|
|
|
24
|
+
def filters(self) -> FluentDict[type]:
|
|
25
|
+
return JsonDict()
|
|
26
|
+
|
|
27
|
+
def sum_filters(self) -> FluentDict[type]:
|
|
28
|
+
return JsonDict()
|
|
29
|
+
|
|
23
30
|
@abstractmethod
|
|
24
31
|
def readable(self) -> FluentDict[type]: # pragma: no cover
|
|
25
32
|
pass
|
|
@@ -38,6 +45,8 @@ class RestfulSchema:
|
|
|
38
45
|
update_many_item = self._schema_for(
|
|
39
46
|
"UpdateManyItem", self.fields.editable().merge(self.fields.id())
|
|
40
47
|
)
|
|
48
|
+
self._schema_for("Filter", self.fields.filters())
|
|
49
|
+
self._schema_for("Sum", self.fields.sum_filters())
|
|
41
50
|
|
|
42
51
|
self._schema_for("Item", {self.name.singular: schema})
|
|
43
52
|
self._schema_for("Collection", {self.name.plural: list[schema], "count": int})
|
|
@@ -130,6 +139,22 @@ class RestfulSchema:
|
|
|
130
139
|
|
|
131
140
|
return _
|
|
132
141
|
|
|
142
|
+
def for_filters(self) -> Callable[[BaseModel], dict[str, Any]]:
|
|
143
|
+
schema = self.schemas["Filter"]
|
|
144
|
+
|
|
145
|
+
def _(request: schema) -> dict[str, Any]:
|
|
146
|
+
return request.model_dump()
|
|
147
|
+
|
|
148
|
+
return _
|
|
149
|
+
|
|
150
|
+
def for_sum(self) -> Callable[[BaseModel], dict[str, Any]]:
|
|
151
|
+
schema = self.schemas["Sum"]
|
|
152
|
+
|
|
153
|
+
def _(request: schema) -> dict[str, Any]:
|
|
154
|
+
return request.model_dump()
|
|
155
|
+
|
|
156
|
+
return _
|
|
157
|
+
|
|
133
158
|
|
|
134
159
|
@dataclass(frozen=True)
|
|
135
160
|
class Schema:
|
|
@@ -6,7 +6,7 @@ from functools import cached_property
|
|
|
6
6
|
from typing import Any, Generic, TypeVar
|
|
7
7
|
|
|
8
8
|
from apexdevkit.formatter import Formatter
|
|
9
|
-
from apexdevkit.query.query import FooterOptions,
|
|
9
|
+
from apexdevkit.query.query import FooterOptions, Summary
|
|
10
10
|
from apexdevkit.repository.decorator import BruteForceBatch
|
|
11
11
|
from apexdevkit.repository.interface import Repository
|
|
12
12
|
|
|
@@ -35,7 +35,10 @@ class RestfulService: # pragma: no cover
|
|
|
35
35
|
def read_many(self, **params: Any) -> RawCollection:
|
|
36
36
|
raise NotImplementedError(self.read_many.__name__)
|
|
37
37
|
|
|
38
|
-
def filter_with(self, options:
|
|
38
|
+
def filter_with(self, options: RawItem) -> RawCollection:
|
|
39
|
+
raise NotImplementedError(self.filter_with.__name__)
|
|
40
|
+
|
|
41
|
+
def sum_with(self, options: RawItem) -> int:
|
|
39
42
|
raise NotImplementedError(self.filter_with.__name__)
|
|
40
43
|
|
|
41
44
|
def read_all(self) -> RawCollection:
|
|
@@ -59,6 +59,15 @@ class _RestResource:
|
|
|
59
59
|
),
|
|
60
60
|
)
|
|
61
61
|
|
|
62
|
+
def sum_with(self) -> _TestRequest:
|
|
63
|
+
return _TestRequest(
|
|
64
|
+
self.name,
|
|
65
|
+
HttpRequest(
|
|
66
|
+
HttpMethod.post,
|
|
67
|
+
self.http.with_endpoint(self.name.plural).with_endpoint("sum"),
|
|
68
|
+
),
|
|
69
|
+
)
|
|
70
|
+
|
|
62
71
|
def read_all(self) -> _TestRequest:
|
|
63
72
|
return _TestRequest(
|
|
64
73
|
self.name,
|
|
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
|
|
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
|