adds comments

This commit is contained in:
Christian Beutel
2024-04-03 22:28:34 +02:00
parent 8af1efaf20
commit 76522c808a
23 changed files with 714 additions and 46 deletions

View File

@@ -0,0 +1,26 @@
import type { Comment } from '$lib/models/comment';
import { pb } from '$lib/pocketbase';
import { error, json, type RequestEvent } from '@sveltejs/kit';
export async function GET(event: RequestEvent) {
try {
const r: Comment[] = await pb.collection('comments').getFullList<Comment>({
expand: "author",
sort: "-created",
})
return json(r)
} catch (e: any) {
throw error(e.status, e);
}
}
export async function PUT(event: RequestEvent) {
const data = await event.request.json();
try {
const r = await pb.collection('comments').create<Comment>(data)
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}

View File

@@ -0,0 +1,33 @@
import type { Comment } from "$lib/models/comment";
import { pb } from "$lib/pocketbase";
import { error, json, type RequestEvent } from "@sveltejs/kit";
export async function GET(event: RequestEvent) {
try {
const r = await pb.collection('comments')
.getOne<Comment>(event.params.id as string, { expand: "author" })
return json(r)
} catch (e: any) {
throw error(e.status, e);
}
}
export async function POST(event: RequestEvent) {
const data = await event.request.json()
try {
const r = await pb.collection('comments').update<Comment>(event.params.id as string, data)
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}
export async function DELETE(event: RequestEvent) {
try {
const r = await pb.collection('comments').delete(event.params.id as string)
return json({ 'acknowledged': r });
} catch (e: any) {
throw error(e.status, e)
}
}

View File

@@ -1,6 +1,6 @@
import type { List } from "$lib/models/list";
import { pb } from "$lib/pocketbase";
import { error, json, type RequestEvent } from "@sveltejs/kit";
import type { List } from "postcss/lib/list";
export async function GET(event: RequestEvent) {
try {