Compare commits

..

1 Commits

Author SHA1 Message Date
912e1c46d9 add: search articles api endpoint 2025-02-05 00:06:18 +09:00
2 changed files with 23 additions and 3 deletions

6
src/app.d.ts vendored
View File

@ -1,12 +1,14 @@
// 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 {}

View File

@ -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();
};