square-administration 1.0.0__tar.gz → 1.2.0__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.
Files changed (23) hide show
  1. {square_administration-1.0.0 → square_administration-1.2.0}/PKG-INFO +9 -1
  2. {square_administration-1.0.0 → square_administration-1.2.0}/README.md +8 -0
  3. {square_administration-1.0.0 → square_administration-1.2.0}/setup.py +1 -1
  4. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/main.py +1 -0
  5. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/messages.py +2 -0
  6. square_administration-1.2.0/square_administration/pydantic_models/core.py +12 -0
  7. square_administration-1.2.0/square_administration/routes/core.py +154 -0
  8. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration.egg-info/PKG-INFO +9 -1
  9. square_administration-1.0.0/square_administration/pydantic_models/core.py +0 -0
  10. square_administration-1.0.0/square_administration/routes/core.py +0 -5
  11. {square_administration-1.0.0 → square_administration-1.2.0}/setup.cfg +0 -0
  12. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/__init__.py +0 -0
  13. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/configuration.py +0 -0
  14. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/data/config.ini +0 -0
  15. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/pydantic_models/__init__.py +0 -0
  16. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/pydantic_models/authentication.py +0 -0
  17. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/routes/__init__.py +0 -0
  18. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/routes/authentication.py +0 -0
  19. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration/utils/__init__.py +0 -0
  20. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration.egg-info/SOURCES.txt +0 -0
  21. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration.egg-info/dependency_links.txt +0 -0
  22. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration.egg-info/requires.txt +0 -0
  23. {square_administration-1.0.0 → square_administration-1.2.0}/square_administration.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: square_administration
3
- Version: 1.0.0
3
+ Version: 1.2.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
@@ -32,6 +32,14 @@ pip install square_administration
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v1.2.0
36
+
37
+ - set allow_credentials=True.
38
+
39
+ ### v1.1.0
40
+
41
+ - add core -> get_all_greetings_v0.
42
+
35
43
  ### v1.0.0
36
44
 
37
45
  - initial implementation.
@@ -16,6 +16,14 @@ pip install square_administration
16
16
 
17
17
  ## changelog
18
18
 
19
+ ### v1.2.0
20
+
21
+ - set allow_credentials=True.
22
+
23
+ ### v1.1.0
24
+
25
+ - add core -> get_all_greetings_v0.
26
+
19
27
  ### v1.0.0
20
28
 
21
29
  - initial implementation.
@@ -4,7 +4,7 @@ package_name = "square_administration"
4
4
 
5
5
  setup(
6
6
  name=package_name,
7
- version="1.0.0",
7
+ version="1.2.0",
8
8
  packages=find_packages(),
9
9
  package_data={
10
10
  package_name: ["data/*"],
@@ -20,6 +20,7 @@ app = FastAPI()
20
20
 
21
21
  app.add_middleware(
22
22
  CORSMiddleware,
23
+ allow_credentials=True,
23
24
  allow_origins=["*"],
24
25
  allow_methods=["*"],
25
26
  allow_headers=["*"],
@@ -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
@@ -0,0 +1,154 @@
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
27
+
28
+ router = APIRouter(
29
+ tags=["core"],
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.0.0
3
+ Version: 1.2.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
@@ -32,6 +32,14 @@ pip install square_administration
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v1.2.0
36
+
37
+ - set allow_credentials=True.
38
+
39
+ ### v1.1.0
40
+
41
+ - add core -> get_all_greetings_v0.
42
+
35
43
  ### v1.0.0
36
44
 
37
45
  - initial implementation.
@@ -1,5 +0,0 @@
1
- from fastapi import APIRouter
2
-
3
- router = APIRouter(
4
- tags=["core"],
5
- )