import { FastifyInstance } from 'fastify'; import * as svc from '../services/note.service.js'; export async function noteRoutes(app: FastifyInstance) { app.get('/api/recipes/:id/notes', async (request) => { const { id } = request.params as { id: string }; return svc.listNotes(id); }); app.post('/api/recipes/:id/notes', async (request, reply) => { const { id } = request.params as { id: string }; const { content } = request.body as { content: string }; if (!content) return reply.status(400).send({ error: 'content required' }); const note = svc.createNote(id, content); if (!note) return reply.status(404).send({ error: 'Recipe not found' }); return reply.status(201).send(note); }); app.put('/api/notes/:id', async (request, reply) => { const { id } = request.params as { id: string }; const { content } = request.body as { content: string }; if (!content) return reply.status(400).send({ error: 'content required' }); const note = svc.updateNote(id, content); if (!note) return reply.status(404).send({ error: 'Not found' }); return note; }); app.delete('/api/notes/:id', async (request, reply) => { const { id } = request.params as { id: string }; const ok = svc.deleteNote(id); if (!ok) return reply.status(404).send({ error: 'Not found' }); return { ok: true }; }); }