square-administration 1.0.0__py3-none-any.whl → 1.1.0__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.
- square_administration/messages.py +2 -0
- square_administration/pydantic_models/core.py +12 -0
- square_administration/routes/core.py +150 -1
- {square_administration-1.0.0.dist-info → square_administration-1.1.0.dist-info}/METADATA +5 -1
- {square_administration-1.0.0.dist-info → square_administration-1.1.0.dist-info}/RECORD +7 -7
- {square_administration-1.0.0.dist-info → square_administration-1.1.0.dist-info}/WHEEL +1 -1
- {square_administration-1.0.0.dist-info → square_administration-1.1.0.dist-info}/top_level.txt +0 -0
@@ -10,4 +10,6 @@ messages = {
|
|
10
10
|
"GENERIC_DELETE_SUCCESSFUL": "your records have been deleted successfully.",
|
11
11
|
"GENERIC_400": "the request is invalid or cannot be processed.",
|
12
12
|
"GENERIC_500": "an internal server error occurred. please try again later.",
|
13
|
+
"INCORRECT_ACCESS_TOKEN": "the access token provided is invalid or expired.",
|
14
|
+
"INCORRECT_REFRESH_TOKEN": "the refresh token provided is invalid or expired.",
|
13
15
|
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from typing import Optional, List
|
2
|
+
|
3
|
+
from pydantic import BaseModel, Field
|
4
|
+
from square_database_structure.square.greeting.tables import Greeting
|
5
|
+
|
6
|
+
|
7
|
+
class GetAllGreetingsV0(BaseModel):
|
8
|
+
order_by: List[str] = Field(
|
9
|
+
default_factory=lambda: [f"-{Greeting.greeting_datetime.name}"]
|
10
|
+
)
|
11
|
+
limit: Optional[int] = None
|
12
|
+
offset: int = 0
|
@@ -1,5 +1,154 @@
|
|
1
|
-
|
1
|
+
import json
|
2
|
+
from typing import Annotated
|
3
|
+
|
4
|
+
from fastapi import APIRouter, Header, status, HTTPException
|
5
|
+
from fastapi.responses import JSONResponse
|
6
|
+
from requests import HTTPError
|
7
|
+
from square_authentication_helper import TokenType
|
8
|
+
from square_commons import get_api_output_in_standard_format
|
9
|
+
from square_database_helper import FiltersV0
|
10
|
+
from square_database_helper.pydantic_models import FilterConditionsV0
|
11
|
+
from square_database_structure.square import global_string_database_name
|
12
|
+
from square_database_structure.square.authentication import (
|
13
|
+
global_string_schema_name as global_string_schema_name_authentication,
|
14
|
+
)
|
15
|
+
from square_database_structure.square.authentication.tables import UserCredential
|
16
|
+
from square_database_structure.square.greeting import global_string_schema_name
|
17
|
+
from square_database_structure.square.greeting.tables import Greeting
|
18
|
+
|
19
|
+
from square_administration.configuration import (
|
20
|
+
global_object_square_logger,
|
21
|
+
global_object_square_database_helper,
|
22
|
+
global_object_square_authentication_helper,
|
23
|
+
global_int_app_id,
|
24
|
+
)
|
25
|
+
from square_administration.messages import messages
|
26
|
+
from square_administration.pydantic_models.core import GetAllGreetingsV0
|
2
27
|
|
3
28
|
router = APIRouter(
|
4
29
|
tags=["core"],
|
5
30
|
)
|
31
|
+
|
32
|
+
|
33
|
+
@router.post("/get_all_greetings/v0")
|
34
|
+
@global_object_square_logger.async_auto_logger
|
35
|
+
async def get_all_greetings_v0(
|
36
|
+
access_token: Annotated[str, Header()], body: GetAllGreetingsV0
|
37
|
+
):
|
38
|
+
order_by = body.order_by
|
39
|
+
limit = body.limit
|
40
|
+
offset = body.offset
|
41
|
+
|
42
|
+
try:
|
43
|
+
"""
|
44
|
+
validation
|
45
|
+
"""
|
46
|
+
access_token_payload = global_object_square_authentication_helper.validate_and_get_payload_from_token_v0(
|
47
|
+
token=access_token, token_type=TokenType.access_token
|
48
|
+
)[
|
49
|
+
"data"
|
50
|
+
][
|
51
|
+
"main"
|
52
|
+
]
|
53
|
+
if access_token_payload["app_id"] != global_int_app_id:
|
54
|
+
output_content = get_api_output_in_standard_format(
|
55
|
+
message=messages["INCORRECT_ACCESS_TOKEN"], log="app id is incorrect."
|
56
|
+
)
|
57
|
+
return HTTPException(
|
58
|
+
status_code=status.HTTP_400_BAD_REQUEST,
|
59
|
+
detail=output_content,
|
60
|
+
)
|
61
|
+
|
62
|
+
"""
|
63
|
+
main process
|
64
|
+
"""
|
65
|
+
response = global_object_square_database_helper.get_rows_v0(
|
66
|
+
database_name=global_string_database_name,
|
67
|
+
schema_name=global_string_schema_name,
|
68
|
+
table_name=Greeting.__tablename__,
|
69
|
+
filters=FiltersV0(root={}),
|
70
|
+
apply_filters=False,
|
71
|
+
order_by=order_by,
|
72
|
+
limit=limit,
|
73
|
+
offset=offset,
|
74
|
+
)
|
75
|
+
all_user_ids = {
|
76
|
+
x[Greeting.user_id.name]
|
77
|
+
for x in response["data"]["main"]
|
78
|
+
if x[Greeting.user_id.name] is not None
|
79
|
+
}
|
80
|
+
user_credentials_response = global_object_square_database_helper.get_rows_v0(
|
81
|
+
database_name=global_string_database_name,
|
82
|
+
schema_name=global_string_schema_name_authentication,
|
83
|
+
table_name=UserCredential.__tablename__,
|
84
|
+
filters=FiltersV0(
|
85
|
+
root={
|
86
|
+
UserCredential.user_id.name: FilterConditionsV0(
|
87
|
+
in_=list(all_user_ids)
|
88
|
+
)
|
89
|
+
}
|
90
|
+
),
|
91
|
+
columns=[
|
92
|
+
UserCredential.user_id.name,
|
93
|
+
UserCredential.user_credential_username.name,
|
94
|
+
],
|
95
|
+
)["data"]["main"]
|
96
|
+
user_credentials_map = {
|
97
|
+
x[UserCredential.user_id.name]: x[
|
98
|
+
UserCredential.user_credential_username.name
|
99
|
+
]
|
100
|
+
for x in user_credentials_response
|
101
|
+
}
|
102
|
+
main = [
|
103
|
+
{
|
104
|
+
**greeting,
|
105
|
+
UserCredential.user_credential_username.name: user_credentials_map.get(
|
106
|
+
greeting[Greeting.user_id.name]
|
107
|
+
),
|
108
|
+
}
|
109
|
+
for greeting in response["data"]["main"]
|
110
|
+
]
|
111
|
+
|
112
|
+
"""
|
113
|
+
return value
|
114
|
+
"""
|
115
|
+
output_content = get_api_output_in_standard_format(
|
116
|
+
message=messages["GENERIC_READ_SUCCESSFUL"],
|
117
|
+
data={"main": main},
|
118
|
+
)
|
119
|
+
return JSONResponse(
|
120
|
+
status_code=status.HTTP_200_OK,
|
121
|
+
content=output_content,
|
122
|
+
)
|
123
|
+
except HTTPError as http_error:
|
124
|
+
global_object_square_logger.logger.error(http_error, exc_info=True)
|
125
|
+
"""
|
126
|
+
rollback logic
|
127
|
+
"""
|
128
|
+
# pass
|
129
|
+
return JSONResponse(
|
130
|
+
status_code=http_error.response.status_code,
|
131
|
+
content=json.loads(http_error.response.content),
|
132
|
+
)
|
133
|
+
except HTTPException as http_exception:
|
134
|
+
global_object_square_logger.logger.error(http_exception, exc_info=True)
|
135
|
+
"""
|
136
|
+
rollback logic
|
137
|
+
"""
|
138
|
+
# pass
|
139
|
+
return JSONResponse(
|
140
|
+
status_code=http_exception.status_code, content=http_exception.detail
|
141
|
+
)
|
142
|
+
except Exception as e:
|
143
|
+
global_object_square_logger.logger.error(e, exc_info=True)
|
144
|
+
"""
|
145
|
+
rollback logic
|
146
|
+
"""
|
147
|
+
# pass
|
148
|
+
output_content = get_api_output_in_standard_format(
|
149
|
+
message=messages["GENERIC_500"],
|
150
|
+
log=str(e),
|
151
|
+
)
|
152
|
+
return JSONResponse(
|
153
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=output_content
|
154
|
+
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: square-administration
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.1.0
|
4
4
|
Summary: common business layer for my personal server.
|
5
5
|
Home-page: https://github.com/thepmsquare/square_administration
|
6
6
|
Author: thePmSquare
|
@@ -42,6 +42,10 @@ pip install square_administration
|
|
42
42
|
|
43
43
|
## changelog
|
44
44
|
|
45
|
+
### v1.1.0
|
46
|
+
|
47
|
+
- add core -> get_all_greetings_v0.
|
48
|
+
|
45
49
|
### v1.0.0
|
46
50
|
|
47
51
|
- initial implementation.
|
@@ -1,16 +1,16 @@
|
|
1
1
|
square_administration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
square_administration/configuration.py,sha256=ldSmVp3FWOndN4u-dH-pf4i0olRZx1-uORJAj1qW-g8,4733
|
3
3
|
square_administration/main.py,sha256=H6YJ-PjqVKqj8Odot4jAHg02aAlYbuamHWmXKXy2aAk,1650
|
4
|
-
square_administration/messages.py,sha256=
|
4
|
+
square_administration/messages.py,sha256=93dzwW2J3romvGl66OGBt3z2ueGnInMz28pem9egnaw,984
|
5
5
|
square_administration/data/config.ini,sha256=NMpUnBSPEdwCW1Y-z5DOjpTQgXGjt4ZcqP4QQiAXr_U,997
|
6
6
|
square_administration/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
7
|
square_administration/pydantic_models/authentication.py,sha256=DWXctw5UWzkSVY7nMIQZsRhmgW3OK455OVcoUpJrPY0,202
|
8
|
-
square_administration/pydantic_models/core.py,sha256=
|
8
|
+
square_administration/pydantic_models/core.py,sha256=HUMrBmfKrXeL-126gE5j2povdVmktn8XLg2tHEdeXTk,344
|
9
9
|
square_administration/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
square_administration/routes/authentication.py,sha256=26PjMeyj4UYk3hcK0rLmBQi4tHYfK2a14gtAx7jcy2E,7046
|
11
|
-
square_administration/routes/core.py,sha256=
|
11
|
+
square_administration/routes/core.py,sha256=PTEI1zAGwBrr4EskUjE0WfJaBucZ1r11KRi5nzW3Iys,5306
|
12
12
|
square_administration/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
-
square_administration-1.
|
14
|
-
square_administration-1.
|
15
|
-
square_administration-1.
|
16
|
-
square_administration-1.
|
13
|
+
square_administration-1.1.0.dist-info/METADATA,sha256=Rp0wpauOQ9OlTnROgskdH0MXatbjTBkfyL9Ho2hsMNc,1254
|
14
|
+
square_administration-1.1.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
15
|
+
square_administration-1.1.0.dist-info/top_level.txt,sha256=8WFipDrMQUPRDo5AvipxU1YK3wZtWZyCUMWaR416zAw,22
|
16
|
+
square_administration-1.1.0.dist-info/RECORD,,
|
{square_administration-1.0.0.dist-info → square_administration-1.1.0.dist-info}/top_level.txt
RENAMED
File without changes
|