-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
14 changed files
with
562 additions
and
289 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
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 |
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,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) |
Oops, something went wrong.