From 9009ffe8ef661c922591f6a21ea94067f199e7d9 Mon Sep 17 00:00:00 2001 From: log101 Date: Sat, 27 Jan 2024 19:46:19 +0300 Subject: [PATCH] feat: add author field to creation form --- src/lib/db.ts | 1 + src/pages/[id].astro | 2 +- src/pages/api/content.ts | 4 ++- src/pages/index.astro | 31 ++++++++++++++------- src/scripts/initSelectionMap.js | 48 +++++++++++++++++---------------- 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/src/lib/db.ts b/src/lib/db.ts index c1e7bc9..5e4738a 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -9,5 +9,6 @@ export interface ContentTable { url: string blob_url: string loc: string + author: string description: string } diff --git a/src/pages/[id].astro b/src/pages/[id].astro index cbffa52..2ecfab6 100644 --- a/src/pages/[id].astro +++ b/src/pages/[id].astro @@ -45,7 +45,7 @@ const data: Content | null = res.status === 200 ? await res.json() : null; - Abdurrahman + {data?.author}

{data?.description}

diff --git a/src/pages/api/content.ts b/src/pages/api/content.ts index 1f947b4..2030c51 100644 --- a/src/pages/api/content.ts +++ b/src/pages/api/content.ts @@ -9,6 +9,7 @@ export const POST: APIRoute = async ({ request }) => { const data = await request.formData() const image = data.get("selected-photo") as File + const author = data.get("author") const description = data.get("description") const geolocation = data.get("geolocation") @@ -41,6 +42,7 @@ export const POST: APIRoute = async ({ request }) => { .values({ url: `${newUrl.slice(0, 3)}-${newUrl.slice(3, 7)}-${newUrl.slice(7)}`, blob_url: blob.url, + author: author?.toString() ?? "", description: description?.toString() ?? "", loc: `SRID=4326;POINT(${pos[0]} ${pos[1]})` }) @@ -76,7 +78,7 @@ export const GET: APIRoute = async ({ request }) => { try { const content = await db .selectFrom("contents") - .select(({ fn }) => ["blob_url", fn("ST_AsGeoJSON", ["loc"]).as("loc"), "description"]) + .select(({ fn }) => ["blob_url", fn("ST_AsGeoJSON", ["loc"]).as("loc"), "description", "author"]) .where("url", "=", contentId) .executeTakeFirst() diff --git a/src/pages/index.astro b/src/pages/index.astro index 6069599..5f092bb 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -9,6 +9,7 @@ import '../styles/locked-page.css'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { ReloadIcon } from '@radix-ui/react-icons'; +import { Label } from '@/components/ui/label'; --- @@ -84,15 +85,27 @@ import { ReloadIcon } from '@radix-ui/react-icons'; > 3. Fotoğraf Açıklaması -
-