feat(journal): add per-user mood journal module (task 86)
Ship journal entries with mood tracking, insights, and Recharts charts. Adds v1 API endpoints per ADR 0005 and migration 0020_journal_entries.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
||||
import {
|
||||
deleteJournalEntryForScope,
|
||||
updateJournalEntryForScope,
|
||||
} from "@/modules/journal/server/actions";
|
||||
import { updateJournalEntryInput } from "@/modules/journal/server/schemas";
|
||||
import { getJournalEntryForScope } from "@/modules/journal/server/queries";
|
||||
|
||||
export async function GET(request: Request, context: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await context.params;
|
||||
return withApiHandler(request, async (scope) => {
|
||||
const entry = await getJournalEntryForScope(scope, id);
|
||||
return apiJson(entry);
|
||||
});
|
||||
}
|
||||
|
||||
export async function PATCH(request: Request, context: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await context.params;
|
||||
return withApiHandler(request, async (scope, req) => {
|
||||
const body: unknown = await req.json();
|
||||
const parsed = updateJournalEntryInput.parse({ ...(body as object), id });
|
||||
const entry = await updateJournalEntryForScope(scope, parsed);
|
||||
return apiJson(entry);
|
||||
});
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request, context: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await context.params;
|
||||
return withApiHandler(request, async (scope) => {
|
||||
await deleteJournalEntryForScope(scope, { id });
|
||||
return apiJson({ ok: true });
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { apiJson, withApiHandler } from "@/lib/api-handler";
|
||||
import { createJournalEntryForScope } from "@/modules/journal/server/actions";
|
||||
import { journalEntryInput } from "@/modules/journal/server/schemas";
|
||||
import { listJournalEntriesForScope } from "@/modules/journal/server/queries";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
return withApiHandler(request, async (scope) => {
|
||||
const entries = await listJournalEntriesForScope(scope);
|
||||
return apiJson(entries);
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
return withApiHandler(request, async (scope, req) => {
|
||||
const body: unknown = await req.json();
|
||||
const parsed = journalEntryInput.parse(body);
|
||||
const entry = await createJournalEntryForScope(scope, parsed);
|
||||
return apiJson(entry, 201);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user