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:
ginnoir
2026-07-04 19:41:15 -05:00
parent 8e2ddd6b72
commit 04ae809e07
34 changed files with 1889 additions and 6 deletions
@@ -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 });
});
}
+20
View File
@@ -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);
});
}
+10
View File
@@ -0,0 +1,10 @@
import { notFound } from "next/navigation";
import { JournalEntryEditor } from "@/modules/journal/components/entry-editor";
import { getJournalEntry } from "@/modules/journal/server/queries";
export default async function JournalEntryPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const entry = await getJournalEntry(id).catch(() => null);
if (!entry) notFound();
return <JournalEntryEditor entry={entry} />;
}
+21
View File
@@ -0,0 +1,21 @@
import Link from "next/link";
import { DetailBackLink } from "@/components/detail-back-link";
import { InsightsView } from "@/modules/journal/components/insights-view";
import { listJournalEntries } from "@/modules/journal/server/queries";
export default async function JournalInsightsPage() {
const entries = await listJournalEntries({ limit: 500 });
return (
<div className="mx-auto grid w-full max-w-5xl gap-4 min-w-0">
<DetailBackLink href="/journal" label="Journal" />
<div className="flex items-center justify-between gap-3">
<h2 className="serif text-[22px] tracking-tight">Insights</h2>
<Link href="/journal/mood" className="text-[13px] text-[var(--accent)] hover:underline">
Mood charts
</Link>
</div>
<InsightsView entries={entries} />
</div>
);
}
+21
View File
@@ -0,0 +1,21 @@
import Link from "next/link";
import { DetailBackLink } from "@/components/detail-back-link";
import { MoodTrackerView } from "@/modules/journal/components/mood-tracker-view";
import { listJournalEntries } from "@/modules/journal/server/queries";
export default async function JournalMoodPage() {
const entries = await listJournalEntries({ limit: 500 });
return (
<div className="mx-auto grid w-full max-w-5xl gap-4 min-w-0">
<DetailBackLink href="/journal" label="Journal" />
<div className="flex items-center justify-between gap-3">
<h2 className="serif text-[22px] tracking-tight">Mood tracker</h2>
<Link href="/journal/insights" className="text-[13px] text-[var(--accent)] hover:underline">
View insights
</Link>
</div>
<MoodTrackerView entries={entries} />
</div>
);
}
+5
View File
@@ -0,0 +1,5 @@
import { JournalEntryEditor } from "@/modules/journal/components/entry-editor";
export default function NewJournalEntryPage() {
return <JournalEntryEditor />;
}
+9
View File
@@ -0,0 +1,9 @@
import { recordedDayKey } from "@/modules/journal/day-key";
import { JournalIndex } from "@/modules/journal/components/journal-index";
import { listJournalEntries } from "@/modules/journal/server/queries";
export default async function JournalPage() {
const entries = await listJournalEntries();
const entryDays = [...new Set(entries.map((entry) => recordedDayKey(entry.recordedAt)))];
return <JournalIndex entries={entries} entryDays={entryDays} />;
}