adds trail share

This commit is contained in:
Christian Beutel
2024-09-13 20:06:46 +02:00
parent 421191ec77
commit c38d415460
34 changed files with 1144 additions and 104 deletions

View File

@@ -0,0 +1,36 @@
import type { ListShare } from '$lib/models/list_share';
import type { User } from '$lib/models/user';
import { pb } from '$lib/pocketbase';
import { error, json, type RequestEvent } from '@sveltejs/kit';
export async function GET(event: RequestEvent) {
const sort = event.url.searchParams.get('sort') ?? ""
const filter = event.url.searchParams.get("filter") ?? "";
try {
const r: ListShare[] = await pb.collection('list_share').getFullList<ListShare>({
sort: sort,
filter: filter
})
for (const share of r) {
const anonymous_user = await pb.collection('users_anonymous').getOne<User>(share.user)
share.expand = {
user: anonymous_user
}
}
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('list_share').create<ListShare>(data)
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}

View File

@@ -0,0 +1,33 @@
import type { ListShare } from "$lib/models/list_share";
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('list_share')
.getOne<ListShare>(event.params.id as string)
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('list_share').update<ListShare>(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('list_share').delete(event.params.id as string)
return json({ 'acknowledged': r });
} catch (e: any) {
throw error(e.status, e)
}
}

View File

@@ -6,7 +6,7 @@ export async function GET(event: RequestEvent) {
const sort = event.url.searchParams.get('sort') ?? ""
try {
const r: List[] = await pb.collection('lists').getFullList<List>({
expand: "trails,trails.waypoints,trails.category",
expand: "trails,trails.waypoints,trails.category,list_share_via_list",
sort: sort,
})
return json(r)

View File

@@ -5,7 +5,7 @@ import { error, json, type RequestEvent } from "@sveltejs/kit";
export async function GET(event: RequestEvent) {
try {
const r = await pb.collection('lists')
.getOne<List>(event.params.id as string, { expand: "trails,trails.waypoints,trails.category" })
.getOne<List>(event.params.id as string, { expand: "trails,trails.waypoints,trails.category,list_share_via_list" })
return json(r)
} catch (e: any) {
throw error(e.status, e);