Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

確定注文ページのUI改変、データベースクエリとループ内条件分岐のメモ化 #63

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/routers/ordered_products.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from fastapi import APIRouter, Request

from ..store import SortOrderedProductsBy as SortBy
from ..store import select_ordered_products
from ..store import load_ordered_products

# from .. import templates

router = APIRouter()


@router.get("/ordered-products")
async def get_ordered_products(_: Request, sort_by: SortBy = SortBy.PRODUCT_ID):
ordered_products = await select_ordered_products(sort_by, False, False)
ordered_products = await load_ordered_products(sort_by)
# NOTE: Actually, we might not need this template and instead modify and use templates.placements.
# templates.ordered_products(request, ordered_products)
return ordered_products
54 changes: 30 additions & 24 deletions app/routers/placements.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
from typing import Annotated
# from typing import Annotated

from fastapi import APIRouter, Header, Request
# from fastapi import APIRouter, Header, Request
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse

from .. import templates
from ..store import PlacementTable, select_placements
from ..store import (
PlacementTable,
load_canceled_placements,
load_completed_placements,
load_incoming_placements,
)

router = APIRouter()


@router.get("/placements", response_class=HTMLResponse)
async def get_placements(
request: Request,
canceled: bool = False,
completed: bool = False,
hx_request: Annotated[str | None, Header()] = None,
):
placements = await select_placements(canceled, completed)
macro = (
templates.components.placements
if hx_request == "true"
else templates.placements
)
return HTMLResponse(macro(request, placements, canceled, completed))
@router.get("/incoming-placements", response_class=HTMLResponse)
async def get_incoming_placements(request: Request):
placements = await load_incoming_placements()
return HTMLResponse(templates.incoming_placements(request, placements))


# @router.get("/placements/{placement_id}")
# async def get_placement(request: Request, placement_id: int):
# if (placement := await PlacementTable.by_placement_id(placement_id)) is None:
# raise HTTPException(404, f"Placement {placement_id} not found")
# return templates.components.placement(request, placement)
@router.get("/canceled-placements", response_class=HTMLResponse)
async def get_canceled_placements(request: Request):
placements = await load_canceled_placements()
return HTMLResponse(templates.canceled_placements(request, placements))


@router.post("/placements/{placement_id}")
@router.get("/completed-placements", response_class=HTMLResponse)
async def get_completed_placements(request: Request):
placements = await load_completed_placements()
return HTMLResponse(templates.completed_placements(request, placements))


@router.post("/incoming-placements/{placement_id}")
async def reset_placement(placement_id: int):
await PlacementTable.reset(placement_id)


@router.post("/completed-placements/{placement_id}")
async def complete_placement(placement_id: int):
await PlacementTable.complete(placement_id)


@router.delete("/placements/{placement_id}")
@router.post("/canceled-placements/{placement_id}")
async def cancel_placement(placement_id: int):
await PlacementTable.cancel(placement_id)
Loading