diff --git a/src/app.d.ts b/src/app.d.ts index ee8bd52..fc58322 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,13 +1,15 @@ // See https://kit.svelte.dev/docs/types#app // for information about these interfaces -import { Database } from 'pg'; +import { Pool } from "pg"; +import type { SimpleGit } from "simple-git"; declare global { namespace App { // interface Error {} interface Locals { - db: any; - } + db: Pool; + git: SimpleGit; + } // interface PageData {} // interface PageState {} // interface Platform {} diff --git a/src/routes/api/search/+server.ts b/src/routes/api/search/+server.ts new file mode 100644 index 0000000..8c73bc3 --- /dev/null +++ b/src/routes/api/search/+server.ts @@ -0,0 +1,18 @@ +import { json } from '@sveltejs/kit'; +import { error } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; + +export const GET: RequestHandler = async ({ url, locals }) => { + const category = String(url.searchParams.get('category')); + + if (!category) { + error(400, 'Bad request'); + } + + const db = await locals.db; + const article = await db.query( + 'SELECT * FROM article WHERE category = $1', + [category] + ); + return new Response(); +}; \ No newline at end of file