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);
|
||||
});
|
||||
}
|
||||
@@ -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} />;
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { JournalEntryEditor } from "@/modules/journal/components/entry-editor";
|
||||
|
||||
export default function NewJournalEntryPage() {
|
||||
return <JournalEntryEditor />;
|
||||
}
|
||||
@@ -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} />;
|
||||
}
|
||||
Reference in New Issue
Block a user