diff --git a/src/allmende_payment_system/api/shop.py b/src/allmende_payment_system/api/shop.py index 71be710..9a7d868 100644 --- a/src/allmende_payment_system/api/shop.py +++ b/src/allmende_payment_system/api/shop.py @@ -18,3 +18,13 @@ async def get_shop(request: Request, session: SessionDep): "shop.html.jinja", context={"request": request, "areas": areas}, ) + + +@shop_router.get("/shop/area/{area_id}") +async def get_shop(request: Request, session: SessionDep, area_id: int): + query = select(Area).where(Area.id == area_id) + area = session.scalars(query).one() + return templates.TemplateResponse( + "area.html.jinja", + context={"request": request, "area": area}, + ) diff --git a/src/allmende_payment_system/app.py b/src/allmende_payment_system/app.py index c51e0bf..d7ae837 100644 --- a/src/allmende_payment_system/app.py +++ b/src/allmende_payment_system/app.py @@ -1,3 +1,5 @@ +import locale + from fastapi import Depends, FastAPI from fastapi.staticfiles import StaticFiles @@ -5,6 +7,7 @@ from allmende_payment_system.api import root_router from allmende_payment_system.api.dependencies import get_user from allmende_payment_system.api.shop import shop_router +locale.setlocale(locale.LC_ALL, "de_DE.UTF-8") app = FastAPI(dependencies=[Depends(get_user)]) diff --git a/src/allmende_payment_system/models.py b/src/allmende_payment_system/models.py index b9bff74..9400be1 100644 --- a/src/allmende_payment_system/models.py +++ b/src/allmende_payment_system/models.py @@ -55,6 +55,15 @@ class Area(Base): description: Mapped[str] = mapped_column(nullable=True) image_path: Mapped[str] = mapped_column(nullable=True) + products: Mapped[list["Product"]] = relationship("Product") + + +UnitsOfMeasure = typing.Literal[ + "g", + "kg", + "piece", +] + class Product(Base): __tablename__ = TABLE_PREFIX + "product" @@ -62,11 +71,14 @@ class Product(Base): name: Mapped[str] = mapped_column(nullable=False, unique=True) price: Mapped[decimal.Decimal] = mapped_column(Numeric(10, 2)) + unit_of_measure: Mapped[UnitsOfMeasure] = mapped_column(nullable=False) # TODO: limit this to actually used vat rates? vat_rate: Mapped[decimal.Decimal] = mapped_column(Numeric(10, 2)) area_id: Mapped[int] = mapped_column(ForeignKey(TABLE_PREFIX + "area.id")) - area: Mapped["Area"] = relationship("Area") + area: Mapped["Area"] = relationship("Area", back_populates="products") + + image_path: Mapped[str] = mapped_column(nullable=True) TransactionTypes = typing.Literal[ diff --git a/src/allmende_payment_system/static/img/placeholder.jpg b/src/allmende_payment_system/static/img/placeholder.jpg new file mode 100644 index 0000000..9602b3d Binary files /dev/null and b/src/allmende_payment_system/static/img/placeholder.jpg differ diff --git a/src/allmende_payment_system/templates/area.html.jinja b/src/allmende_payment_system/templates/area.html.jinja new file mode 100644 index 0000000..b7ec129 --- /dev/null +++ b/src/allmende_payment_system/templates/area.html.jinja @@ -0,0 +1,36 @@ +{% extends "base.html.jinja" %} +{% block content %} + +
{{ area.description or ''}}
+