Skip to content

Commit

Permalink
Redesign the placements page
Browse files Browse the repository at this point in the history
  • Loading branch information
exflikt committed Oct 2, 2024
1 parent 0e294f4 commit 46cc2e2
Show file tree
Hide file tree
Showing 14 changed files with 562 additions and 289 deletions.
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

0 comments on commit 46cc2e2

Please sign in to comment.