2022-09-30 15:14:57 -05:00
|
|
|
import { Handlers, PageProps } from "$fresh/server.ts";
|
2022-10-07 14:13:45 -05:00
|
|
|
import { query } from "@/db/mod.ts";
|
|
|
|
import { Page } from "@/components/Page.tsx";
|
2022-09-30 15:14:57 -05:00
|
|
|
|
|
|
|
interface Note {
|
|
|
|
id: string;
|
|
|
|
created_at: Date;
|
|
|
|
content: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const handler: Handlers<Note> = {
|
|
|
|
async GET(request, context) {
|
|
|
|
console.debug({ request, context });
|
|
|
|
const result = await query(
|
|
|
|
"select * from note where id = $1 order by created_at desc",
|
|
|
|
[context.params["id"]],
|
|
|
|
);
|
|
|
|
if (result == null) throw "unable to fetch from database";
|
|
|
|
const [note] = result.rows as Note[];
|
|
|
|
return await context.render(note);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function NotesPage(
|
|
|
|
{ data: { id, created_at, content } }: PageProps<Note>,
|
|
|
|
) {
|
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<h1>Note {id} created at {created_at.toLocaleString()}</h1>
|
|
|
|
<div class="my-4" key={id}>
|
|
|
|
<blockquote class="mt-2 pl-4 border-l(solid 4)">
|
|
|
|
<pre>{content}</pre>
|
|
|
|
</blockquote>
|
|
|
|
</div>
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|