zrb 1.0.0a21__py3-none-any.whl → 1.0.0b2__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.
- zrb/__init__.py +2 -1
- zrb/__main__.py +0 -3
- zrb/builtin/__init__.py +3 -0
- zrb/builtin/group.py +1 -0
- zrb/builtin/llm/llm_chat.py +2 -2
- zrb/builtin/llm/tool/web.py +1 -1
- zrb/builtin/project/add/fastapp/fastapp_task.py +2 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/config.py +5 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +80 -20
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +150 -42
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/my_entity_service.py +113 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/my_entity_service_factory.py +9 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/my_entity_db_repository.py +0 -10
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/my_entity_repository.py +37 -16
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/{factory.py → my_entity_repository_factory.py} +2 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/schema/my_entity.py +16 -6
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/client_method.py +57 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/gateway_subroute.py +72 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/format_task.py +1 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/input.py +13 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +23 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +42 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/gateway/subroute/my_module.py +7 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/my_module_api_client.py +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/{any_client.py → my_module_client.py} +1 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/my_module_client_factory.py +11 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/my_module_direct_client.py +5 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/route.py +11 -11
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/module_task_definition.py +2 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/task.py +8 -8
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/util.py +47 -20
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/app_factory.py +29 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/base_db_repository.py +185 -101
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/base_service.py +236 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/{db_engine.py → db_engine_factory.py} +1 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/error.py +12 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/logger_factory.py +10 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/parser_factory.py +7 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/app.py +47 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/parser.py +105 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/user_agent.py +58 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/view.py +37 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/config.py +25 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/main.py +1 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/auth_api_client.py +16 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/auth_client.py +163 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/auth_client_factory.py +9 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/auth_direct_client.py +15 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/migration/versions/3093c7336477_add_auth_tables.py +160 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/migration_metadata.py +18 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/route.py +7 -3
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/permission_service.py +117 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/permission_service_factory.py +11 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/repository/permission_db_repository.py +26 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/repository/permission_repository.py +61 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission/repository/permission_repository_factory.py +13 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/repository/role_db_repository.py +75 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/repository/role_repository.py +59 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/repository/role_repository_factory.py +13 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/role_service.py +105 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role/role_service_factory.py +7 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_db_repository.py +42 -13
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_repository.py +38 -17
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_repository_factory.py +2 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_service.py +105 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_service_factory.py +7 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/route.py +43 -14
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/subroute/auth.py +198 -28
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/util/view.py +74 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/error.html +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/homepage.html +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/images/android-chrome-192x192.png +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/images/android-chrome-512x512.png +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/images/favicon-32x32.png +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.amber.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.blue.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.cyan.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.fuchsia.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.green.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.grey.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.indigo.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.jade.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.lime.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.orange.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.pink.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.pumpkin.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.purple.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.red.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.sand.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.slate.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.violet.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.yellow.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.zinc.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/template/default.html +34 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/requirements.txt +1 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/permission.py +17 -5
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/role.py +50 -4
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/session.py +52 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/schema/user.py +30 -5
- zrb/builtin/python.py +1 -1
- zrb/builtin/random.py +61 -0
- zrb/cmd/cmd_val.py +6 -5
- zrb/content_transformer/any_content_transformer.py +7 -0
- zrb/content_transformer/content_transformer.py +6 -0
- zrb/runner/cli.py +14 -7
- zrb/runner/web_app.py +28 -280
- zrb/runner/web_config/config.py +91 -0
- zrb/runner/web_config/config_factory.py +26 -0
- zrb/runner/web_route/docs_route.py +17 -0
- zrb/runner/web_route/error_page/serve_default_404.py +28 -0
- zrb/runner/{web_controller/error_page/controller.py → web_route/error_page/show_error_page.py} +2 -2
- zrb/runner/{web_controller → web_route}/error_page/view.html +5 -0
- zrb/runner/web_route/home_page/home_page_route.py +51 -0
- zrb/runner/web_route/login_api_route.py +31 -0
- zrb/runner/web_route/login_page/login_page_route.py +39 -0
- zrb/runner/web_route/logout_api_route.py +18 -0
- zrb/runner/web_route/logout_page/logout_page_route.py +40 -0
- zrb/runner/{web_controller/group_info_page/controller.py → web_route/node_page/group/show_group_page.py} +3 -3
- zrb/runner/web_route/node_page/node_page_route.py +50 -0
- zrb/runner/{web_controller/session_page/controller.py → web_route/node_page/task/show_task_page.py} +3 -3
- zrb/runner/web_route/refresh_token_api_route.py +38 -0
- zrb/runner/web_route/static/static_route.py +44 -0
- zrb/runner/web_route/task_input_api_route.py +47 -0
- zrb/runner/web_route/task_session_api_route.py +102 -0
- zrb/runner/web_schema/session.py +5 -0
- zrb/runner/web_schema/token.py +11 -0
- zrb/runner/web_schema/user.py +32 -0
- zrb/runner/web_util/cookie.py +29 -0
- zrb/runner/{web_util.py → web_util/html.py} +1 -23
- zrb/runner/web_util/token.py +72 -0
- zrb/runner/web_util/user.py +63 -0
- zrb/session/session.py +6 -4
- zrb/session_state_logger/{default_session_state_logger.py → session_state_logger_factory.py} +1 -1
- zrb/task/base_task.py +53 -6
- zrb/task/base_trigger.py +2 -0
- zrb/task/cmd_task.py +9 -5
- zrb/task/http_check.py +2 -0
- zrb/task/llm_task.py +2 -0
- zrb/task/make_task.py +2 -0
- zrb/task/rsync_task.py +2 -0
- zrb/task/scaffolder.py +8 -5
- zrb/task/scheduler.py +2 -0
- zrb/task/tcp_check.py +2 -0
- zrb/task_status/task_status.py +4 -3
- zrb/util/cmd/command.py +1 -0
- zrb/util/file.py +7 -1
- {zrb-1.0.0a21.dist-info → zrb-1.0.0b2.dist-info}/METADATA +1 -1
- zrb-1.0.0b2.dist-info/RECORD +307 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/any_client_method.py +0 -27
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/my_entity_usecase.py +0 -65
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/api_client.py +0 -6
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/direct_client.py +0 -6
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/factory.py +0 -9
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/app.py +0 -20
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/base_usecase.py +0 -245
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/any_client.py +0 -33
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/api_client.py +0 -7
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/direct_client.py +0 -6
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/factory.py +0 -9
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/migration/versions/3093c7336477_add_user_table.py +0 -37
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_usecase.py +0 -53
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_usecase_factory.py +0 -6
- zrb/runner/web_config.py +0 -274
- zrb/runner/web_controller/home_page/controller.py +0 -33
- zrb/runner/web_controller/login_page/controller.py +0 -25
- zrb/runner/web_controller/logout_page/controller.py +0 -26
- zrb-1.0.0a21.dist-info/RECORD +0 -244
- /zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/{create_column_task.py → add_column_task.py} +0 -0
- /zrb/{runner/web_controller → builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/permission}/__init__.py +0 -0
- /zrb/{runner/web_controller/group_info_page → builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/role}/__init__.py +0 -0
- /zrb/runner/{web_controller/home_page → web_route}/__init__.py +0 -0
- /zrb/runner/{web_controller/session_page → web_route/home_page}/__init__.py +0 -0
- /zrb/runner/{web_controller → web_route}/home_page/view.html +0 -0
- /zrb/runner/{web_controller → web_route}/login_page/view.html +0 -0
- /zrb/runner/{web_controller → web_route}/logout_page/view.html +0 -0
- /zrb/runner/{web_controller/group_info_page → web_route/node_page/group}/view.html +0 -0
- /zrb/runner/{web_controller/session_page → web_route/node_page/task}/partial/input.html +0 -0
- /zrb/runner/{web_controller/session_page → web_route/node_page/task}/view.html +0 -0
- /zrb/runner/{refresh-token.template.js → web_route/static/refresh-token.template.js} +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/common.css +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/favicon-32x32.png +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/login/event.js +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/logout/event.js +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/pico.min.css +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/session/common-util.js +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/session/current-session.js +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/session/event.js +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/session/past-session.js +0 -0
- {zrb-1.0.0a21.dist-info → zrb-1.0.0b2.dist-info}/WHEEL +0 -0
- {zrb-1.0.0a21.dist-info → zrb-1.0.0b2.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
from logging import Logger
|
2
|
+
|
3
|
+
from my_app_name.common.base_service import BaseService
|
4
|
+
from my_app_name.module.my_module.service.my_entity.repository.my_entity_repository import (
|
5
|
+
MyEntityRepository,
|
6
|
+
)
|
7
|
+
from my_app_name.schema.my_entity import (
|
8
|
+
MultipleMyEntityResponse,
|
9
|
+
MyEntityCreateWithAudit,
|
10
|
+
MyEntityResponse,
|
11
|
+
MyEntityUpdateWithAudit,
|
12
|
+
)
|
13
|
+
|
14
|
+
|
15
|
+
class MyEntityService(BaseService):
|
16
|
+
|
17
|
+
def __init__(self, logger: Logger, my_entity_repository: MyEntityRepository):
|
18
|
+
super().__init__(logger)
|
19
|
+
self.my_entity_repository = my_entity_repository
|
20
|
+
|
21
|
+
@BaseService.route(
|
22
|
+
"/api/v1/my-entities/{my_entity_id}",
|
23
|
+
methods=["get"],
|
24
|
+
response_model=MyEntityResponse,
|
25
|
+
)
|
26
|
+
async def get_my_entity_by_id(self, my_entity_id: str) -> MyEntityResponse:
|
27
|
+
return await self.my_entity_repository.get_by_id(my_entity_id)
|
28
|
+
|
29
|
+
@BaseService.route(
|
30
|
+
"/api/v1/my-entities",
|
31
|
+
methods=["get"],
|
32
|
+
response_model=MultipleMyEntityResponse,
|
33
|
+
)
|
34
|
+
async def get_my_entities(
|
35
|
+
self,
|
36
|
+
page: int = 1,
|
37
|
+
page_size: int = 10,
|
38
|
+
sort: str | None = None,
|
39
|
+
filter: str | None = None,
|
40
|
+
) -> MultipleMyEntityResponse:
|
41
|
+
my_entities = await self.my_entity_repository.get(page, page_size, filter, sort)
|
42
|
+
count = await self.my_entity_repository.count(filter)
|
43
|
+
return MultipleMyEntityResponse(data=my_entities, count=count)
|
44
|
+
|
45
|
+
@BaseService.route(
|
46
|
+
"/api/v1/my-entities/bulk",
|
47
|
+
methods=["post"],
|
48
|
+
response_model=list[MyEntityResponse],
|
49
|
+
)
|
50
|
+
async def create_my_entity_bulk(
|
51
|
+
self, data: list[MyEntityCreateWithAudit]
|
52
|
+
) -> list[MyEntityResponse]:
|
53
|
+
my_entities = await self.my_entity_repository.create_bulk(data)
|
54
|
+
return await self.my_entity_repository.get_by_ids(
|
55
|
+
[my_entity.id for my_entity in my_entities]
|
56
|
+
)
|
57
|
+
|
58
|
+
@BaseService.route(
|
59
|
+
"/api/v1/my-entities",
|
60
|
+
methods=["post"],
|
61
|
+
response_model=MyEntityResponse,
|
62
|
+
)
|
63
|
+
async def create_my_entity(self, data: MyEntityCreateWithAudit) -> MyEntityResponse:
|
64
|
+
my_entity = await self.my_entity_repository.create(data)
|
65
|
+
return await self.my_entity_repository.get_by_id(my_entity.id)
|
66
|
+
|
67
|
+
@BaseService.route(
|
68
|
+
"/api/v1/my-entities/bulk",
|
69
|
+
methods=["put"],
|
70
|
+
response_model=MyEntityResponse,
|
71
|
+
)
|
72
|
+
async def update_my_entity_bulk(
|
73
|
+
self, my_entity_ids: list[str], data: MyEntityUpdateWithAudit
|
74
|
+
) -> MyEntityResponse:
|
75
|
+
my_entities = await self.my_entity_repository.update_bulk(my_entity_ids, data)
|
76
|
+
return await self.my_entity_repository.get_by_ids(
|
77
|
+
[my_entity.id for my_entity in my_entities]
|
78
|
+
)
|
79
|
+
|
80
|
+
@BaseService.route(
|
81
|
+
"/api/v1/my-entities/{my_entity_id}",
|
82
|
+
methods=["put"],
|
83
|
+
response_model=MyEntityResponse,
|
84
|
+
)
|
85
|
+
async def update_my_entity(
|
86
|
+
self, my_entity_id: str, data: MyEntityUpdateWithAudit
|
87
|
+
) -> MyEntityResponse:
|
88
|
+
my_entity = await self.my_entity_repository.update(my_entity_id, data)
|
89
|
+
return await self.my_entity_repository.get_by_id(my_entity.id)
|
90
|
+
|
91
|
+
@BaseService.route(
|
92
|
+
"/api/v1/my-entities/{my_entity_id}",
|
93
|
+
methods=["delete"],
|
94
|
+
response_model=MyEntityResponse,
|
95
|
+
)
|
96
|
+
async def delete_my_entity_bulk(
|
97
|
+
self, my_entity_ids: list[str], deleted_by: str
|
98
|
+
) -> MyEntityResponse:
|
99
|
+
my_entities = await self.my_entity_repository.delete_bulk(my_entity_ids)
|
100
|
+
return await self.my_entity_repository.get_by_ids(
|
101
|
+
[my_entity.id for my_entity in my_entities]
|
102
|
+
)
|
103
|
+
|
104
|
+
@BaseService.route(
|
105
|
+
"/api/v1/my-entities/{my_entity_id}",
|
106
|
+
methods=["delete"],
|
107
|
+
response_model=MyEntityResponse,
|
108
|
+
)
|
109
|
+
async def delete_my_entity(
|
110
|
+
self, my_entity_id: str, deleted_by: str
|
111
|
+
) -> MyEntityResponse:
|
112
|
+
my_entity = await self.my_entity_repository.delete(my_entity_id)
|
113
|
+
return await self.my_entity_repository.get_by_id(my_entity.id)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from my_app_name.common.logger_factory import logger
|
2
|
+
from my_app_name.module.my_module.service.my_entity.my_entity_service import (
|
3
|
+
MyEntityService,
|
4
|
+
)
|
5
|
+
from my_app_name.module.my_module.service.my_entity.repository.my_entity_repository_factory import (
|
6
|
+
my_entity_repository,
|
7
|
+
)
|
8
|
+
|
9
|
+
my_entity_service = MyEntityService(logger, my_entity_repository=my_entity_repository)
|
@@ -1,5 +1,4 @@
|
|
1
1
|
from my_app_name.common.base_db_repository import BaseDBRepository
|
2
|
-
from my_app_name.common.error import NotFoundError
|
3
2
|
from my_app_name.module.my_module.service.my_entity.repository.my_entity_repository import (
|
4
3
|
MyEntityRepository,
|
5
4
|
)
|
@@ -10,15 +9,6 @@ from my_app_name.schema.my_entity import (
|
|
10
9
|
MyEntityUpdateWithAudit,
|
11
10
|
)
|
12
11
|
from passlib.context import CryptContext
|
13
|
-
from sqlalchemy.ext.asyncio import AsyncSession
|
14
|
-
from sqlmodel import Session, select
|
15
|
-
|
16
|
-
# Password hashing context
|
17
|
-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
18
|
-
|
19
|
-
|
20
|
-
def hash_password(password: str) -> str:
|
21
|
-
return pwd_context.hash(password)
|
22
12
|
|
23
13
|
|
24
14
|
class MyEntityDBRepository(
|
@@ -9,30 +9,51 @@ from my_app_name.schema.my_entity import (
|
|
9
9
|
|
10
10
|
|
11
11
|
class MyEntityRepository(ABC):
|
12
|
+
|
13
|
+
@abstractmethod
|
14
|
+
async def get_by_id(self, id: str) -> MyEntityResponse:
|
15
|
+
"""Get my entity by id"""
|
16
|
+
|
17
|
+
@abstractmethod
|
18
|
+
async def get_by_ids(self, id_list: list[str]) -> MyEntityResponse:
|
19
|
+
"""Get my entities by ids"""
|
20
|
+
|
21
|
+
@abstractmethod
|
22
|
+
async def get(
|
23
|
+
self,
|
24
|
+
page: int = 1,
|
25
|
+
page_size: int = 10,
|
26
|
+
filter: str | None = None,
|
27
|
+
sort: str | None = None,
|
28
|
+
) -> list[MyEntity]:
|
29
|
+
"""Get my entities by filter and sort"""
|
30
|
+
|
31
|
+
@abstractmethod
|
32
|
+
async def count(self, filter: str | None = None) -> int:
|
33
|
+
"""Count my entities by filter"""
|
34
|
+
|
12
35
|
@abstractmethod
|
13
|
-
async def create(self,
|
14
|
-
|
36
|
+
async def create(self, data: MyEntityCreateWithAudit) -> MyEntity:
|
37
|
+
"""Create a new my entity"""
|
15
38
|
|
16
39
|
@abstractmethod
|
17
|
-
async def
|
18
|
-
|
40
|
+
async def create_bulk(self, data: list[MyEntityCreateWithAudit]) -> list[MyEntity]:
|
41
|
+
"""Create some my entities"""
|
19
42
|
|
20
43
|
@abstractmethod
|
21
|
-
async def
|
22
|
-
|
44
|
+
async def delete(self, id: str) -> MyEntity:
|
45
|
+
"""Delete a my entity"""
|
23
46
|
|
24
47
|
@abstractmethod
|
25
|
-
async def
|
26
|
-
|
27
|
-
) -> MyEntity:
|
28
|
-
pass
|
48
|
+
async def delete_bulk(self, id_list: list[str]) -> list[MyEntity]:
|
49
|
+
"""Delete some my entities"""
|
29
50
|
|
30
51
|
@abstractmethod
|
31
|
-
async def
|
32
|
-
|
52
|
+
async def update(self, id: str, data: MyEntityUpdateWithAudit) -> MyEntity:
|
53
|
+
"""Update a my entity"""
|
33
54
|
|
34
55
|
@abstractmethod
|
35
|
-
async def
|
36
|
-
self,
|
37
|
-
) -> list[
|
38
|
-
|
56
|
+
async def update_bulk(
|
57
|
+
self, id_list: list[str], data: MyEntityUpdateWithAudit
|
58
|
+
) -> list[MyEntity]:
|
59
|
+
"""Update some my entities"""
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from my_app_name.common.
|
1
|
+
from my_app_name.common.db_engine_factory import db_engine
|
2
2
|
from my_app_name.config import APP_REPOSITORY_TYPE
|
3
3
|
from my_app_name.module.my_module.service.my_entity.repository.my_entity_db_repository import (
|
4
4
|
MyEntityDBRepository,
|
@@ -8,6 +8,6 @@ from my_app_name.module.my_module.service.my_entity.repository.my_entity_reposit
|
|
8
8
|
)
|
9
9
|
|
10
10
|
if APP_REPOSITORY_TYPE == "db":
|
11
|
-
my_entity_repository: MyEntityRepository = MyEntityDBRepository(
|
11
|
+
my_entity_repository: MyEntityRepository = MyEntityDBRepository(db_engine)
|
12
12
|
else:
|
13
13
|
my_entity_repository: MyEntityRepository = None
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import datetime
|
2
2
|
|
3
3
|
import ulid
|
4
|
+
from pydantic import BaseModel
|
4
5
|
from sqlmodel import Field, SQLModel
|
5
6
|
|
6
7
|
|
@@ -9,7 +10,8 @@ class MyEntityBase(SQLModel):
|
|
9
10
|
|
10
11
|
|
11
12
|
class MyEntityCreate(MyEntityBase):
|
12
|
-
|
13
|
+
def with_audit(self, created_by: str) -> "MyEntityCreateWithAudit":
|
14
|
+
return MyEntityCreateWithAudit(**self.model_dump(), created_by=created_by)
|
13
15
|
|
14
16
|
|
15
17
|
class MyEntityCreateWithAudit(MyEntityCreate):
|
@@ -19,6 +21,9 @@ class MyEntityCreateWithAudit(MyEntityCreate):
|
|
19
21
|
class MyEntityUpdate(SQLModel):
|
20
22
|
my_column: str | None = None
|
21
23
|
|
24
|
+
def with_audit(self, updated_by: str) -> "MyEntityUpdateWithAudit":
|
25
|
+
return MyEntityUpdateWithAudit(**self.model_dump(), updated_by=updated_by)
|
26
|
+
|
22
27
|
|
23
28
|
class MyEntityUpdateWithAudit(MyEntityUpdate):
|
24
29
|
updated_by: str
|
@@ -28,10 +33,15 @@ class MyEntityResponse(MyEntityBase):
|
|
28
33
|
id: str
|
29
34
|
|
30
35
|
|
36
|
+
class MultipleMyEntityResponse(BaseModel):
|
37
|
+
data: list[MyEntityResponse]
|
38
|
+
count: int
|
39
|
+
|
40
|
+
|
31
41
|
class MyEntity(SQLModel, table=True):
|
32
42
|
id: str = Field(default_factory=lambda: ulid.new().str, primary_key=True)
|
33
|
-
created_at: datetime.datetime
|
34
|
-
created_by: str
|
35
|
-
updated_at: datetime.datetime
|
36
|
-
updated_by: str
|
37
|
-
my_column: str
|
43
|
+
created_at: datetime.datetime = Field(index=True)
|
44
|
+
created_by: str = Field(index=True)
|
45
|
+
updated_at: datetime.datetime | None = Field(index=True)
|
46
|
+
updated_by: str | None = Field(index=True)
|
47
|
+
my_column: str = Field(index=True)
|
zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/client_method.py
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# MyEntity related methods
|
2
|
+
|
3
|
+
|
4
|
+
@abstractmethod
|
5
|
+
async def get_my_entity_by_id(self, my_entity_id: str) -> MyEntityResponse:
|
6
|
+
"""Get my entity by id"""
|
7
|
+
|
8
|
+
|
9
|
+
@abstractmethod
|
10
|
+
async def get_my_entities(
|
11
|
+
self,
|
12
|
+
page: int = 1,
|
13
|
+
page_size: int = 10,
|
14
|
+
sort: str | None = None,
|
15
|
+
filter: str | None = None,
|
16
|
+
) -> MultipleMyEntityResponse:
|
17
|
+
"""Get my entities by filter and sort"""
|
18
|
+
|
19
|
+
|
20
|
+
@abstractmethod
|
21
|
+
async def create_my_entity(self, data: MyEntityCreateWithAudit) -> MyEntityResponse:
|
22
|
+
"""Create a new my entities"""
|
23
|
+
|
24
|
+
|
25
|
+
@abstractmethod
|
26
|
+
async def create_my_entity(
|
27
|
+
self, data: list[MyEntityCreateWithAudit]
|
28
|
+
) -> list[MyEntityResponse]:
|
29
|
+
"""Create new my entities"""
|
30
|
+
|
31
|
+
|
32
|
+
@abstractmethod
|
33
|
+
async def update_my_entity_bulk(
|
34
|
+
self, my_entity_ids: list[str], data: MyEntityUpdateWithAudit
|
35
|
+
) -> MyEntityResponse:
|
36
|
+
"""Update some my entities"""
|
37
|
+
|
38
|
+
|
39
|
+
@abstractmethod
|
40
|
+
async def update_my_entity(
|
41
|
+
self, my_entity_id: str, data: MyEntityUpdateWithAudit
|
42
|
+
) -> MyEntityResponse:
|
43
|
+
"""Update a my entity"""
|
44
|
+
|
45
|
+
|
46
|
+
@abstractmethod
|
47
|
+
async def delete_my_entity_bulk(
|
48
|
+
self, my_entity_ids: str, deleted_by: str
|
49
|
+
) -> MyEntityResponse:
|
50
|
+
"""Delete some my entities"""
|
51
|
+
|
52
|
+
|
53
|
+
@abstractmethod
|
54
|
+
async def delete_my_entity(
|
55
|
+
self, my_entity_id: str, deleted_by: str
|
56
|
+
) -> MyEntityResponse:
|
57
|
+
"""Delete a my entity"""
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# MyEntity routes
|
2
|
+
|
3
|
+
|
4
|
+
@app.get("/api/v1/my-entities", response_model=MultipleMyEntityResponse)
|
5
|
+
async def get_my_entities(
|
6
|
+
page: int = 1,
|
7
|
+
page_size: int = 10,
|
8
|
+
sort: str | None = None,
|
9
|
+
filter: str | None = None,
|
10
|
+
) -> MultipleMyEntityResponse:
|
11
|
+
return await my_module_client.get_my_entities(
|
12
|
+
page=page, page_size=page_size, sort=sort, filter=filter
|
13
|
+
)
|
14
|
+
|
15
|
+
|
16
|
+
@app.get("/api/v1/my-entities/{my_entity_id}", response_model=MyEntityResponse)
|
17
|
+
async def get_my_entity_by_id(my_entity_id: str) -> MyEntityResponse:
|
18
|
+
return await my_module_client.get_my_entity_by_id(my_entity_id)
|
19
|
+
|
20
|
+
|
21
|
+
@app.post(
|
22
|
+
"/api/v1/my-entities/bulk",
|
23
|
+
response_model=list[MyEntityResponse],
|
24
|
+
)
|
25
|
+
async def create_my_entity_bulk(data: list[MyEntityCreate]):
|
26
|
+
return await my_module_client.create_my_entity_bulk(
|
27
|
+
[row.with_audit(created_by="system") for row in data]
|
28
|
+
)
|
29
|
+
|
30
|
+
|
31
|
+
@app.post(
|
32
|
+
"/api/v1/my-entities",
|
33
|
+
response_model=MyEntityResponse,
|
34
|
+
)
|
35
|
+
async def create_my_entity(data: MyEntityCreate):
|
36
|
+
return await my_module_client.create_my_entity(data.with_audit(created_by="system"))
|
37
|
+
|
38
|
+
|
39
|
+
@app.put(
|
40
|
+
"/api/v1/my-entities/bulk",
|
41
|
+
response_model=list[MyEntityResponse],
|
42
|
+
)
|
43
|
+
async def update_my_entity_bulk(my_entity_ids: list[str], data: MyEntityUpdate):
|
44
|
+
return await my_module_client.update_my_entity_bulk(
|
45
|
+
my_entity_ids, data.with_audit(updated_by="system")
|
46
|
+
)
|
47
|
+
|
48
|
+
|
49
|
+
@app.put(
|
50
|
+
"/api/v1/my-entities/{my_entity_id}",
|
51
|
+
response_model=MyEntityResponse,
|
52
|
+
)
|
53
|
+
async def update_my_entity(my_entity_id: str, data: MyEntityUpdate):
|
54
|
+
return await my_module_client.update_my_entity(data.with_audit(updated_by="system"))
|
55
|
+
|
56
|
+
|
57
|
+
@app.delete(
|
58
|
+
"/api/v1/my-entities/bulk",
|
59
|
+
response_model=list[MyEntityResponse],
|
60
|
+
)
|
61
|
+
async def delete_my_entity_bulk(my_entity_ids: list[str]):
|
62
|
+
return await my_module_client.delete_my_entity_bulk(
|
63
|
+
my_entity_ids, deleted_by="system"
|
64
|
+
)
|
65
|
+
|
66
|
+
|
67
|
+
@app.delete(
|
68
|
+
"/api/v1/my-entities/{my_entity_id}",
|
69
|
+
response_model=MyEntityResponse,
|
70
|
+
)
|
71
|
+
async def delete_my_entity(my_entity_id: str):
|
72
|
+
return await my_module_client.delete_my_entity(my_entity_id, deleted_by="system")
|
@@ -6,7 +6,7 @@ from zrb.task.cmd_task import CmdTask
|
|
6
6
|
format_my_app_name_code = app_group.add_task(
|
7
7
|
CmdTask(
|
8
8
|
name="format-my-app-name-code",
|
9
|
-
description="
|
9
|
+
description="✨ Format Python code",
|
10
10
|
cmd=[
|
11
11
|
"isort . --profile black --force-grid-wrap 0",
|
12
12
|
"black .",
|
@@ -38,3 +38,16 @@ new_entity_column_input = StrInput(
|
|
38
38
|
prompt="New entity's column name",
|
39
39
|
default_str="name",
|
40
40
|
)
|
41
|
+
|
42
|
+
new_column_input = StrInput(
|
43
|
+
name="column",
|
44
|
+
description="Column name",
|
45
|
+
prompt="New column name",
|
46
|
+
)
|
47
|
+
|
48
|
+
new_column_type_input = OptionInput(
|
49
|
+
name="type",
|
50
|
+
description="Column type",
|
51
|
+
prompt="Column type",
|
52
|
+
options=["str", "int", "float", "bool", "datetime", "date"],
|
53
|
+
)
|
@@ -9,11 +9,14 @@ from my_app_name._zrb.module.add_module_util import (
|
|
9
9
|
is_app_main_file,
|
10
10
|
is_app_zrb_config_file,
|
11
11
|
is_app_zrb_task_file,
|
12
|
+
is_gateway_module_subroute_file,
|
13
|
+
is_gateway_route_file,
|
12
14
|
is_in_module_dir,
|
13
15
|
update_app_config_file,
|
14
16
|
update_app_main_file,
|
15
17
|
update_app_zrb_config_file,
|
16
18
|
update_app_zrb_task_file,
|
19
|
+
update_gateway_route_file,
|
17
20
|
)
|
18
21
|
from my_app_name._zrb.util import get_existing_module_names
|
19
22
|
|
@@ -42,32 +45,52 @@ scaffold_my_app_name_module = Scaffolder(
|
|
42
45
|
transform_content=[
|
43
46
|
# Common transformation (my_app_name/module/snake_module_name)
|
44
47
|
ContentTransformer(
|
48
|
+
name="transform-module-dir",
|
45
49
|
match=is_in_module_dir,
|
46
50
|
transform={
|
47
51
|
"MY_MODULE": "{to_snake_case(ctx.input.module).upper()}",
|
48
52
|
"my_module": "{to_snake_case(ctx.input.module)}",
|
53
|
+
"MyModule": "{to_pascal_case(ctx.input.module)}",
|
54
|
+
},
|
55
|
+
),
|
56
|
+
# Gateway's module subroute (my_app_name/module/gateway/subroute/snake_module_name.py)
|
57
|
+
ContentTransformer(
|
58
|
+
name="transform-gateway-subroute",
|
59
|
+
match=is_gateway_module_subroute_file,
|
60
|
+
transform={
|
61
|
+
"my_module": "{to_snake_case(ctx.input.module)}",
|
49
62
|
},
|
50
63
|
),
|
51
64
|
# Register module config to my_app_name/config.py
|
52
65
|
ContentTransformer(
|
66
|
+
name="transform-app-config",
|
53
67
|
match=is_app_config_file,
|
54
68
|
transform=update_app_config_file,
|
55
69
|
),
|
56
70
|
# Register module route to my_app_name/main.py
|
57
71
|
ContentTransformer(
|
72
|
+
name="transform-app-main",
|
58
73
|
match=is_app_main_file,
|
59
74
|
transform=update_app_main_file,
|
60
75
|
),
|
61
76
|
# Register module's tasks to my_app_name/_zrb/task.py
|
62
77
|
ContentTransformer(
|
78
|
+
name="transform-zrb-task",
|
63
79
|
match=is_app_zrb_task_file,
|
64
80
|
transform=update_app_zrb_task_file,
|
65
81
|
),
|
66
82
|
# Register module's base url to my_app_name/_zrb/config.py
|
67
83
|
ContentTransformer(
|
84
|
+
name="transform-zrb-config",
|
68
85
|
match=is_app_zrb_config_file,
|
69
86
|
transform=update_app_zrb_config_file,
|
70
87
|
),
|
88
|
+
# Register module's subroute to my_app_name/gateway/route.py
|
89
|
+
ContentTransformer(
|
90
|
+
name="transform-gateway-route",
|
91
|
+
match=is_gateway_route_file,
|
92
|
+
transform=update_gateway_route_file,
|
93
|
+
),
|
71
94
|
],
|
72
95
|
retries=0,
|
73
96
|
upstream=validate_create_my_app_name_module,
|
@@ -4,6 +4,7 @@ from my_app_name._zrb.config import APP_DIR
|
|
4
4
|
from my_app_name._zrb.util import get_existing_module_names
|
5
5
|
|
6
6
|
from zrb.context.any_context import AnyContext
|
7
|
+
from zrb.util.codemod.append_code_to_function import append_code_to_function
|
7
8
|
from zrb.util.codemod.append_key_to_dict import append_key_to_dict
|
8
9
|
from zrb.util.file import read_file, write_file
|
9
10
|
from zrb.util.string.conversion import to_kebab_case, to_pascal_case, to_snake_case
|
@@ -17,6 +18,10 @@ def is_app_main_file(ctx: AnyContext, file_path: str) -> bool:
|
|
17
18
|
return file_path == os.path.join(APP_DIR, "main.py")
|
18
19
|
|
19
20
|
|
21
|
+
def is_gateway_route_file(ctx: AnyContext, file_path: str) -> bool:
|
22
|
+
return file_path == os.path.join(APP_DIR, "module", "gateway", "route.py")
|
23
|
+
|
24
|
+
|
20
25
|
def is_app_zrb_task_file(ctx: AnyContext, file_path: str) -> bool:
|
21
26
|
return file_path == os.path.join(APP_DIR, "_zrb", "task.py")
|
22
27
|
|
@@ -31,6 +36,13 @@ def is_in_module_dir(ctx: AnyContext, file_path: str) -> bool:
|
|
31
36
|
)
|
32
37
|
|
33
38
|
|
39
|
+
def is_gateway_module_subroute_file(ctx: AnyContext, file_path: str) -> bool:
|
40
|
+
module_subroute_file_name = f"{to_snake_case(ctx.input.module)}.py"
|
41
|
+
return file_path == os.path.join(
|
42
|
+
APP_DIR, "module", "gateway", "subroute", module_subroute_file_name
|
43
|
+
)
|
44
|
+
|
45
|
+
|
34
46
|
def update_app_zrb_config_file(ctx: AnyContext, zrb_config_file_path: str):
|
35
47
|
existing_zrb_config_code = read_file(zrb_config_file_path)
|
36
48
|
module_name = ctx.input.module
|
@@ -152,3 +164,33 @@ def _get_new_module_config_code(existing_code: str, module_name: str) -> str | N
|
|
152
164
|
if config_code in existing_code:
|
153
165
|
return None
|
154
166
|
return config_code
|
167
|
+
|
168
|
+
|
169
|
+
def update_gateway_route_file(ctx: AnyContext, gateway_route_file_path: str):
|
170
|
+
existing_gateway_route_code = read_file(gateway_route_file_path)
|
171
|
+
snake_module_name = to_snake_case(ctx.input.module)
|
172
|
+
write_file(
|
173
|
+
file_path=gateway_route_file_path,
|
174
|
+
content=[
|
175
|
+
_get_module_subroute_import(existing_gateway_route_code, ctx.input.module),
|
176
|
+
append_code_to_function(
|
177
|
+
original_code=existing_gateway_route_code,
|
178
|
+
function_name="serve_route",
|
179
|
+
new_code="\n".join(
|
180
|
+
[
|
181
|
+
f"# Serve {snake_module_name} route",
|
182
|
+
f"serve_{snake_module_name}_route(app)",
|
183
|
+
]
|
184
|
+
),
|
185
|
+
),
|
186
|
+
],
|
187
|
+
)
|
188
|
+
|
189
|
+
|
190
|
+
def _get_module_subroute_import(existing_code: str, module_name: str) -> str | None:
|
191
|
+
snake_module_name = to_snake_case(module_name)
|
192
|
+
import_module_path = f"my_app_name.module.gateway.subroute.{snake_module_name}"
|
193
|
+
import_code = f"from {import_module_path} import serve_{snake_module_name}_route"
|
194
|
+
if import_code in existing_code:
|
195
|
+
return None
|
196
|
+
return import_code
|
@@ -0,0 +1,11 @@
|
|
1
|
+
from my_app_name.config import APP_COMMUNICATION
|
2
|
+
from my_app_name.module.my_module.client.my_module_api_client import MyModuleAPIClient
|
3
|
+
from my_app_name.module.my_module.client.my_module_client import MyModuleClient
|
4
|
+
from my_app_name.module.my_module.client.my_module_direct_client import (
|
5
|
+
MyModuleDirectClient,
|
6
|
+
)
|
7
|
+
|
8
|
+
if APP_COMMUNICATION == "direct":
|
9
|
+
my_module_client: MyModuleClient = MyModuleDirectClient()
|
10
|
+
elif APP_COMMUNICATION == "api":
|
11
|
+
my_module_client: MyModuleClient = MyModuleAPIClient()
|
@@ -1,10 +1,18 @@
|
|
1
1
|
from fastapi import FastAPI
|
2
|
-
from my_app_name.common.
|
2
|
+
from my_app_name.common.app_factory import app
|
3
3
|
from my_app_name.common.schema import BasicResponse
|
4
4
|
from my_app_name.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
|
5
5
|
|
6
6
|
|
7
|
-
def
|
7
|
+
def serve_route(app: FastAPI):
|
8
|
+
if APP_MODE != "microservices" or "my_module" not in APP_MODULES:
|
9
|
+
return
|
10
|
+
if APP_MAIN_MODULE == "my_module":
|
11
|
+
_serve_health_check(app)
|
12
|
+
_serve_readiness_check(app)
|
13
|
+
|
14
|
+
|
15
|
+
def _serve_health_check(app: FastAPI):
|
8
16
|
@app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
|
9
17
|
async def health():
|
10
18
|
"""
|
@@ -13,7 +21,7 @@ def serve_health_check(app: FastAPI):
|
|
13
21
|
return BasicResponse(message="ok")
|
14
22
|
|
15
23
|
|
16
|
-
def
|
24
|
+
def _serve_readiness_check(app: FastAPI):
|
17
25
|
@app.api_route("/readiness", methods=["GET", "HEAD"], response_model=BasicResponse)
|
18
26
|
async def readiness():
|
19
27
|
"""
|
@@ -22,12 +30,4 @@ def serve_readiness_check(app: FastAPI):
|
|
22
30
|
return BasicResponse(message="ok")
|
23
31
|
|
24
32
|
|
25
|
-
def serve_route(app: FastAPI):
|
26
|
-
if APP_MODE != "microservices" or "my_module" not in APP_MODULES:
|
27
|
-
return
|
28
|
-
if APP_MAIN_MODULE == "my_module":
|
29
|
-
serve_health_check(app)
|
30
|
-
serve_readiness_check(app)
|
31
|
-
|
32
|
-
|
33
33
|
serve_route(app)
|