diff --git a/apps/api/src/routes/listBottles.ts b/apps/api/src/routes/listBottles.ts index a98efaf1..64078d86 100644 --- a/apps/api/src/routes/listBottles.ts +++ b/apps/api/src/routes/listBottles.ts @@ -5,7 +5,7 @@ import { IncomingMessage, Server, ServerResponse } from "http"; import { z } from "zod"; import zodToJsonSchema from "zod-to-json-schema"; import { db } from "../db"; -import { bottles, bottlesToDistillers, entities } from "../db/schema"; +import { Category, bottles, bottlesToDistillers, entities } from "../db/schema"; import { buildPageLink } from "../lib/paging"; import { serialize } from "../lib/serializers"; import { BottleSerializer } from "../lib/serializers/bottle"; @@ -23,6 +23,18 @@ export default { brand: { type: "number" }, distiller: { type: "number" }, entity: { type: "number" }, + category: { + type: "string", + enum: [ + "blend", + "bourbon", + "rye", + "single_grain", + "single_malt", + "spirit", + ], + }, + age: { type: "number" }, }, }, response: { @@ -78,6 +90,12 @@ export default { ), ); } + if (req.query.category) { + where.push(eq(bottles.category, req.query.category)); + } + if (req.query.age) { + where.push(eq(bottles.statedAge, req.query.age)); + } let orderBy: SQL; switch (req.query.sort) { @@ -127,6 +145,8 @@ export default { brand?: number; distiller?: number; entity?: number; + category?: Category; + age?: number; sort?: "name"; }; } diff --git a/apps/web/src/components/bottleTable.tsx b/apps/web/src/components/bottleTable.tsx index ce5988b1..90cf9d34 100644 --- a/apps/web/src/components/bottleTable.tsx +++ b/apps/web/src/components/bottleTable.tsx @@ -93,10 +93,22 @@ export default ({ )} - {formatCategoryName(bottle.category)} + {!!bottle.category && ( + + {formatCategoryName(bottle.category)} + + )} - {bottle.statedAge && `${bottle.statedAge} years`} + {bottle.statedAge && ( + {`${bottle.statedAge} years`} + )} , ]; diff --git a/apps/web/src/routes/bottles.tsx b/apps/web/src/routes/bottles.tsx index 43270c85..a75c2808 100644 --- a/apps/web/src/routes/bottles.tsx +++ b/apps/web/src/routes/bottles.tsx @@ -17,6 +17,7 @@ export default function BottleList() { queryFn: (): Promise> => api.get("/bottles", { query: { + ...Object.fromEntries(qs.entries()), page, sort: "name", },