import { FreshContext, Handlers, PageProps } from "$fresh/server.ts"; import AuthorCard from "../../components/AuthorCard.tsx"; import { Post } from "../../components/PostCard.tsx"; import { PostCarousel } from "../../components/PostCarousel.tsx"; export const handler: Handlers = { async GET(_req: Request, ctx: FreshContext) { try { const [authorResponse, authorPostResponse] = await Promise.all([ fetch(`${Deno.env.get("BASE_URI_API")}/authors/${ctx.params.id}`), fetch(`${Deno.env.get("BASE_URI_API")}/authors/${ctx.params.id}/posts`), ]); const [authorData, authorPostData] = await Promise.all([ authorResponse.json(), authorPostResponse.json(), ]); return ctx.render({ authorData, authorPostData, }); } catch (error) { return ctx.render({ error: error.message, authorData: null, authorPostData: [], }); } }, }; export default function AuthorIdentifier({ data }: PageProps) { const { authorData, authorPostData, error } = data; if (error) { return (

Error Loading Author Information

{error}

); } if (!authorData) { return
No author found
; } return ( <>
); } interface PageData { error?: string; authorData: AuthorResponse; authorPostData: Array; } export type AuthorResponse = { author_id: number; first_name: string; last_name: string; bio: string; image?: string; };