-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea001eb
commit 9376dce
Showing
35 changed files
with
470 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ity/template/app_template/module/my_module/service/my_entity/my_entity_service_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from my_app_name.common.logger_factory import logger | ||
from my_app_name.module.my_module.service.my_entity.my_entity_service import ( | ||
MyEntityService, | ||
) | ||
from my_app_name.module.my_module.service.my_entity.repository.my_entity_repository_factory import ( | ||
my_entity_repository, | ||
) | ||
|
||
my_entity_service = MyEntityService(my_entity_repository=my_entity_repository) | ||
my_entity_service = MyEntityService(logger, my_entity_repository=my_entity_repository) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/route.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
src/zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/app.py
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/app_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
|
||
from fastapi import FastAPI | ||
from my_app_name.common.db_engine_factory import db_engine | ||
from my_app_name.common.util.app import ( | ||
create_default_app_lifespan, | ||
get_default_app_title, | ||
serve_docs, | ||
serve_static_dir, | ||
) | ||
from my_app_name.config import ( | ||
APP_GATEWAY_FAVICON_PATH, | ||
APP_GATEWAY_TITLE, | ||
APP_GATEWAY_VIEW_PATH, | ||
APP_MODE, | ||
APP_MODULES, | ||
APP_VERSION, | ||
) | ||
|
||
app_title = get_default_app_title(APP_GATEWAY_TITLE, mode=APP_MODE, modules=APP_MODULES) | ||
app = FastAPI( | ||
title=app_title, | ||
version=APP_VERSION, | ||
lifespan=create_default_app_lifespan(db_engine), | ||
docs_url=None, | ||
) | ||
|
||
serve_static_dir(app, os.path.join(APP_GATEWAY_VIEW_PATH, "static")) | ||
serve_docs(app, app_title=app_title, favicon_url=APP_GATEWAY_FAVICON_PATH) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 0 additions & 94 deletions
94
src/zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/parser.py
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/parser_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from my_app_name.common.util.parser import ( | ||
create_default_filter_param_parser, | ||
create_default_sort_param_parser, | ||
) | ||
|
||
parse_filter_param = create_default_filter_param_parser() | ||
parse_sort_param = create_default_sort_param_parser() |
47 changes: 47 additions & 0 deletions
47
src/zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/util/app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
from contextlib import asynccontextmanager | ||
|
||
from fastapi import FastAPI, HTTPException | ||
from fastapi.openapi.docs import get_swagger_ui_html | ||
from fastapi.responses import FileResponse | ||
from fastapi.staticfiles import StaticFiles | ||
from sqlalchemy.engine import Engine | ||
from sqlmodel import SQLModel | ||
from starlette.types import Lifespan | ||
|
||
|
||
def get_default_app_title(app_title: str, mode: str, modules: list[str] = []) -> str: | ||
if mode == "monolith": | ||
return app_title | ||
return f"{app_title} - {', '.join(modules)}" | ||
|
||
|
||
def create_default_app_lifespan(db_engine: Engine) -> Lifespan: | ||
@asynccontextmanager | ||
async def default_app_lifespan(app: FastAPI): | ||
SQLModel.metadata.create_all(db_engine) | ||
yield | ||
|
||
return default_app_lifespan | ||
|
||
|
||
def serve_static_dir(app: FastAPI, static_dir: str): | ||
app.mount("/static", StaticFiles(directory=static_dir), name="static") | ||
|
||
# Serve static files | ||
@app.get("/static/{file_path:path}", include_in_schema=False) | ||
async def static_files(file_path: str): | ||
full_path = os.path.join(static_dir, file_path) | ||
if os.path.isfile(full_path): | ||
return FileResponse(full_path) | ||
raise HTTPException(status_code=404, detail="File not found") | ||
|
||
|
||
def serve_docs(app: FastAPI, app_title: str, favicon_url: str): | ||
@app.get("/docs", include_in_schema=False) | ||
async def swagger_ui_html(): | ||
return get_swagger_ui_html( | ||
openapi_url="/openapi.json", | ||
title=app_title, | ||
swagger_favicon_url=favicon_url, | ||
) |
Oops, something went wrong.