python
Apply to board_new.py
from fastapi import APIRouter, Depends, Query, Form
from typing_extensions import Annotated
router = APIRouter()
python
Apply to board_new.py
# 서비스 클래스 의존성 주입
@router.get("/endpoint")
async def endpoint(
service: Annotated[ServiceClass, Depends(ServiceClass.async_init)],
# 추가 파라미터들...
):
pass
python
Apply to board_new.py
@router.get("/path")
async def get_endpoint(
service: Annotated[ServiceClass, Depends(ServiceClass.async_init)],
param1: str = Query(None),
param2: int = Query(1, alias="page")
):
# 1. 데이터 조회
data = service.get_data(param1, param2)
# 2. 컨텍스트 구성
context = {
"request": service.request,
"data": data,
# 추가 컨텍스트...
}
# 3. 템플릿 응답 반환
return templates.TemplateResponse("template.html", context)
python
Apply to board_new.py
@router.post("/path",
dependencies=[Depends(validate_token),
Depends(validate_super_admin)])
async def post_endpoint(
service: Annotated[ServiceClass, Depends(ServiceClass.async_init)],
data: list = Form(..., alias="chk_id[]")
):
# 1. 데이터 처리
service.process_data(data)
# 2. 리다이렉트 응답
url = "/redirect/path"
query_params = service.request.query_params
return RedirectResponse(set_url_query_params(url, query_params), 303)
python
Apply to board_new.py
from lib.dependency.dependencies import validate_token, validate_super_admin
@router.post("/path",
dependencies=[Depends(validate_token),
Depends(validate_super_admin)])
python
Apply to board_new.py
from core.template import UserTemplates
from lib.template_functions import get_group_select
templates = UserTemplates()
templates.env.globals["get_group_select"] = get_group_select
python
Apply to board_new.py
from lib.common import set_url_query_params
url = "/path"
query_params = service.request.query_params
return RedirectResponse(set_url_query_params(url, query_params), 303)
python
Apply to board_new.py
@router.get("/example")
async def example_list(
service: Annotated[ExampleService, Depends(ExampleService.async_init)],
category: str = Query(None),
page: int = Query(1)
):
# 데이터 조회
items = service.get_items(category, page)
total_count = service.get_total_count(category)
# 컨텍스트 구성
context = {
"request": service.request,
"items": items,
"total_count": total_count,
"current_page": page,
"paging": get_paging(service.request, page, total_count, service.page_rows)
}
return templates.TemplateResponse("example/list.html", context)
댓글목록
등록된 댓글이 없습니다.