diff --git a/server/daily-recipe.ts b/server/daily-recipe.ts index 4b87e7d..c4629c6 100644 --- a/server/daily-recipe.ts +++ b/server/daily-recipe.ts @@ -1,6 +1,6 @@ import { db } from "./db"; import { dailyRecipes } from "@shared/schema"; -import { eq } from "drizzle-orm"; +import { eq, desc } from "drizzle-orm"; function todayStr(): string { const d = new Date(); @@ -37,3 +37,7 @@ export async function upsertRecipe(data: { const [row] = await db.insert(dailyRecipes).values(values).returning(); return row; } + +export async function listRecipes(limit = 200): Promise { + return await db.select().from(dailyRecipes).orderBy(desc(dailyRecipes.dateStr)).limit(limit); +} diff --git a/server/routes.ts b/server/routes.ts index 0578556..118a261 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -4,7 +4,7 @@ import { storage } from "./storage"; import { insertArticleSchema } from "@shared/schema"; import { seedDatabase } from "./seed"; import { generateDailyHoroscopes, getHoroscopesForToday, getOrGenerateHoroscope, setHoroscopeImages } from "./horoscope-generator"; -import { getRecipeForToday, upsertRecipe } from "./daily-recipe"; +import { getRecipeForToday, upsertRecipe, listRecipes } from "./daily-recipe"; import { startDailyScheduler } from "./scheduler"; import { analyzeAllArticleImages, getCachedFocalPoints } from "./focal-point"; import { optimizeImage } from "./image-optimizer"; @@ -755,6 +755,14 @@ export async function registerRoutes( } }); + app.get("/api/recipes", async (_req, res) => { + try { + res.json(await listRecipes()); + } catch (err: any) { + res.status(500).json({ message: err.message }); + } + }); + app.get("/api/recipes/today", async (_req, res) => { try { const recipe = await getRecipeForToday();