The recipes.blue monorepo recipes.blue
recipes appview atproto
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: read endpoints for recipes

+45 -1
+45 -1
apps/api/src/recipes/index.ts
··· 1 1 import { Hono } from "hono"; 2 2 import { db } from "../db/index.js"; 3 + import { and, eq, sql } from "drizzle-orm"; 4 + import { recipeTable } from "../db/schema.js"; 5 + import { parseDid } from "../util/did.js"; 6 + import { apiLogger } from "../logger.js"; 7 + import { RecipeCollection } from "@cookware/lexicons"; 3 8 4 9 export const recipeApp = new Hono(); 5 10 6 11 recipeApp.get('/', async ctx => { 7 - const recipes = await db.query.recipeTable.findMany(); 12 + const recipes = await db.query.recipeTable.findMany({ 13 + columns: { 14 + rkey: true, 15 + title: true, 16 + description: true, 17 + authorDid: true, 18 + createdAt: true, 19 + }, 20 + extras: { 21 + uri: sql`concat(${recipeTable.authorDid}, "/", ${recipeTable.rkey})`.as('uri'), 22 + } 23 + }); 8 24 return ctx.json({ recipes }); 9 25 }); 26 + 27 + recipeApp.get('/:authorDid/:rkey', async ctx => { 28 + const { authorDid, rkey } = ctx.req.param(); 29 + const did = parseDid(authorDid); 30 + if (!did) { 31 + return ctx.json({ 32 + error: 'invalid_did', 33 + message: 'The author DID you passed was invalid.', 34 + }, 400); 35 + } 36 + 37 + const recipe = await db.query.recipeTable.findFirst({ 38 + where: and( 39 + eq(recipeTable.rkey, rkey), 40 + eq(recipeTable.authorDid, did) 41 + ), 42 + columns: { id: false }, 43 + }); 44 + 45 + if (!recipe) { 46 + return ctx.json({ 47 + error: 'recipe_not_found', 48 + message: 'That recipe was not found.', 49 + }, 404); 50 + } 51 + 52 + return ctx.json({ recipe }); 53 + });