apexdevkit 1.6.6__tar.gz → 1.7.1__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.6.6 → apexdevkit-1.7.1}/PKG-INFO +1 -1
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/fastapi/response.py +30 -91
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/pyproject.toml +1 -1
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/LICENSE +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/README.md +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/__init__.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/annotation/__init__.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/annotation/deprecate.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/error.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/fastapi/__init__.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/fastapi/builder.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/fastapi/dependable.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/fastapi/docs.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/fastapi/resource.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/fastapi/router.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/fastapi/schema.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/fastapi/service.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/formatter.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/http/__init__.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/http/fake.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/http/fluent.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/http/httpx.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/http/json.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/http/url.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/py.typed +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/repository/__init__.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/repository/base.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/repository/connector.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/repository/database.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/repository/in_memory.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/repository/interface.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/testing/__init__.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/testing/database.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/testing/fake.py +0 -0
- {apexdevkit-1.6.6 → apexdevkit-1.7.1}/apexdevkit/testing/rest.py +0 -0
|
@@ -3,94 +3,35 @@ from __future__ import annotations
|
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
from typing import Any, Iterable
|
|
5
5
|
|
|
6
|
-
from fastapi import status
|
|
7
|
-
from fastapi.responses import JSONResponse
|
|
8
|
-
|
|
9
6
|
from apexdevkit.error import DoesNotExistError, ExistsError, ForbiddenError
|
|
10
7
|
from apexdevkit.testing import RestfulName
|
|
11
8
|
|
|
12
9
|
|
|
13
|
-
class SuccessResponse(dict[str, Any]):
|
|
14
|
-
def __init__(self, status_code: int, **kwargs: Any):
|
|
15
|
-
super().__init__(
|
|
16
|
-
{
|
|
17
|
-
"status": "success",
|
|
18
|
-
"code": status_code,
|
|
19
|
-
"data": {**kwargs},
|
|
20
|
-
}
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class ResourceFound(SuccessResponse):
|
|
25
|
-
def __init__(self, **kwargs: Any):
|
|
26
|
-
super().__init__(status_code=status.HTTP_200_OK, **kwargs)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class ResourceCreated(SuccessResponse):
|
|
30
|
-
def __init__(self, **kwargs: Any):
|
|
31
|
-
super().__init__(status_code=status.HTTP_201_CREATED, **kwargs)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class ErrorResponse(JSONResponse):
|
|
35
|
-
def __init__(self, status_code: int, message: str, **kwargs: Any):
|
|
36
|
-
content = {
|
|
37
|
-
"status": "fail",
|
|
38
|
-
"code": status_code,
|
|
39
|
-
"error": {"message": message},
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if kwargs:
|
|
43
|
-
content["data"] = {**kwargs}
|
|
44
|
-
|
|
45
|
-
super().__init__(status_code=status_code, content=content)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
class BadRequest(ErrorResponse):
|
|
49
|
-
def __init__(self, message: str, **kwargs: Any) -> None:
|
|
50
|
-
super().__init__(
|
|
51
|
-
status_code=status.HTTP_400_BAD_REQUEST,
|
|
52
|
-
message=message,
|
|
53
|
-
**kwargs,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
class ResourceNotFound(ErrorResponse):
|
|
58
|
-
def __init__(self, message: str):
|
|
59
|
-
super().__init__(status_code=status.HTTP_404_NOT_FOUND, message=message)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class ResourceExists(ErrorResponse):
|
|
63
|
-
def __init__(self, message: str, **kwargs: Any):
|
|
64
|
-
super().__init__(
|
|
65
|
-
status_code=status.HTTP_409_CONFLICT,
|
|
66
|
-
message=message,
|
|
67
|
-
**kwargs,
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
|
|
71
10
|
@dataclass
|
|
72
11
|
class RestfulResponse:
|
|
73
12
|
name: RestfulName
|
|
74
13
|
|
|
75
|
-
def
|
|
76
|
-
|
|
14
|
+
def ok(self) -> dict[str, Any]:
|
|
15
|
+
return self._response(200, data=None)
|
|
77
16
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
content["error"] = {"message": error}
|
|
17
|
+
def found_one(self, item: Any) -> dict[str, Any]:
|
|
18
|
+
return self._response(200, item)
|
|
81
19
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
content["data"] = {}
|
|
85
|
-
case list():
|
|
86
|
-
content["data"] = {self.name.plural: data, "count": len(data)}
|
|
87
|
-
case _:
|
|
88
|
-
content["data"] = {self.name.singular: data}
|
|
20
|
+
def found_many(self, items: list[Any]) -> dict[str, Any]:
|
|
21
|
+
return self._response(200, items)
|
|
89
22
|
|
|
90
|
-
|
|
23
|
+
def created_one(self, item: Any) -> dict[str, Any]:
|
|
24
|
+
return self._response(201, item)
|
|
91
25
|
|
|
92
|
-
def
|
|
93
|
-
return self._response(
|
|
26
|
+
def created_many(self, items: Iterable[Any]) -> dict[str, Any]:
|
|
27
|
+
return self._response(201, list(items))
|
|
28
|
+
|
|
29
|
+
def forbidden(self, e: ForbiddenError) -> dict[str, Any]:
|
|
30
|
+
return self._response(
|
|
31
|
+
403,
|
|
32
|
+
data={"id": str(e.id)},
|
|
33
|
+
error=e.message,
|
|
34
|
+
)
|
|
94
35
|
|
|
95
36
|
def not_found(self, e: DoesNotExistError) -> dict[str, Any]:
|
|
96
37
|
name = self.name.singular.capitalize()
|
|
@@ -110,21 +51,19 @@ class RestfulResponse:
|
|
|
110
51
|
error=f"An item<{name}> with the {e} already exists.",
|
|
111
52
|
)
|
|
112
53
|
|
|
113
|
-
def
|
|
114
|
-
|
|
115
|
-
403,
|
|
116
|
-
data={"id": str(e.id)},
|
|
117
|
-
error=e.message,
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
def created_one(self, item: Any) -> dict[str, Any]:
|
|
121
|
-
return self._response(201, item)
|
|
54
|
+
def _response(self, code: int, data: Any, error: str = "") -> dict[str, Any]:
|
|
55
|
+
content: dict[str, Any] = {"code": code, "status": "success"}
|
|
122
56
|
|
|
123
|
-
|
|
124
|
-
|
|
57
|
+
if error:
|
|
58
|
+
content["status"] = "fail"
|
|
59
|
+
content["error"] = {"message": error}
|
|
125
60
|
|
|
126
|
-
|
|
127
|
-
|
|
61
|
+
match data:
|
|
62
|
+
case None:
|
|
63
|
+
content["data"] = {}
|
|
64
|
+
case list():
|
|
65
|
+
content["data"] = {self.name.plural: data, "count": len(data)}
|
|
66
|
+
case _:
|
|
67
|
+
content["data"] = {self.name.singular: data}
|
|
128
68
|
|
|
129
|
-
|
|
130
|
-
return self._response(200, items)
|
|
69
|
+
return content
|
|
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
|