feat: pantry notes/categories, ingredient-alias matching, cook-log edit/delete, fork-list popover (v0.83.0)
Pantry: notes + category fields (collapsible grouping like the shopping list), a "Merge duplicates" cleanup action, and fixed quantity display precision (was showing raw decimal(10,4) strings like "0.3333 kg" everywhere — pantry, shopping list, print views, Markdown exports). Ingredient-alias matching: the ingredients table (canonical name + aliases) existed but was never populated or used. Seeded ~10 bilingual EN/FR staples and wired resolution into pantry add/edit, can-cook scoring, auto-deduct-on-cook, and shopping-list pantry-awareness, so "sel"/"sel fin"/"table salt" are recognized as the same ingredient. Cook log: entries from "Mark cooked" can now be edited and deleted (previously log-only, no fix-a-mistake path). The "Cooked N times" text is a hover tooltip listing every date and opens a full manage sheet on click. Also: the "Forked by N others" backlink is now a click-to-open popover instead of an always-inline list. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,28 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { db, recipes, cookingHistory, pantryItems, recipeIngredients, recipeBatchDishes, eq, and } from "@epicure/db";
|
||||
import { db, recipes, cookingHistory, pantryItems, recipeIngredients, recipeBatchDishes, eq, and, desc, isNull } from "@epicure/db";
|
||||
import { requireSessionOrApiKey } from "@/lib/api-auth";
|
||||
import { loadIngredientAliasIndex, resolveIngredientKey } from "@/lib/ingredient-match";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
// Plain (non-batch) cook log entries only — batch-cook dishes have their
|
||||
// own per-dish "cooked" indicator (dishCookedAtMap in the recipe page) and
|
||||
// aren't meant to be edited/removed one at a time here.
|
||||
export async function GET(req: NextRequest, { params }: Params) {
|
||||
const { session, response } = await requireSessionOrApiKey(req);
|
||||
if (response) return response;
|
||||
const { id } = await params;
|
||||
|
||||
const logs = await db.query.cookingHistory.findMany({
|
||||
where: and(eq(cookingHistory.recipeId, id), eq(cookingHistory.userId, session!.user.id), isNull(cookingHistory.batchDishId)),
|
||||
orderBy: desc(cookingHistory.cookedAt),
|
||||
columns: { id: true, cookedAt: true, servings: true, notes: true },
|
||||
});
|
||||
|
||||
return NextResponse.json({ data: logs });
|
||||
}
|
||||
|
||||
const Schema = z.object({
|
||||
servings: z.number().int().min(1).max(1000).optional(),
|
||||
notes: z.string().max(2000).optional(),
|
||||
@@ -48,9 +66,10 @@ export async function POST(req: NextRequest, { params }: Params) {
|
||||
}
|
||||
|
||||
const cookedAt = data.cookedAt ? new Date(data.cookedAt) : new Date();
|
||||
const logId = crypto.randomUUID();
|
||||
|
||||
await db.insert(cookingHistory).values({
|
||||
id: crypto.randomUUID(),
|
||||
id: logId,
|
||||
userId,
|
||||
recipeId: id,
|
||||
batchDishId: data.batchDishId,
|
||||
@@ -70,11 +89,12 @@ export async function POST(req: NextRequest, { params }: Params) {
|
||||
const userPantry = await db.query.pantryItems.findMany({
|
||||
where: eq(pantryItems.userId, userId),
|
||||
});
|
||||
const aliasIndex = await loadIngredientAliasIndex();
|
||||
|
||||
for (const ing of ings) {
|
||||
const key = ing.rawName.toLowerCase();
|
||||
const key = resolveIngredientKey(ing.rawName, aliasIndex);
|
||||
const pantryItem = userPantry.find(
|
||||
(p) => p.rawName.toLowerCase() === key && (p.unit ?? "") === (ing.unit ?? "")
|
||||
(p) => resolveIngredientKey(p.rawName, aliasIndex) === key && (p.unit ?? "") === (ing.unit ?? "")
|
||||
);
|
||||
if (!pantryItem) continue;
|
||||
|
||||
@@ -97,5 +117,5 @@ export async function POST(req: NextRequest, { params }: Params) {
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({ logged: true }, { status: 201 });
|
||||
return NextResponse.json({ logged: true, id: logId }, { status: 201 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user