implements trail sharing

This commit is contained in:
Christian Beutel
2024-06-06 02:02:23 +02:00
parent 5d46ad96b4
commit ad5a4e668b
44 changed files with 1257 additions and 308 deletions

View File

@@ -0,0 +1,36 @@
import type { TrailShare } from '$lib/models/trail_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: TrailShare[] = await pb.collection('trail_share').getFullList<TrailShare>({
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('trail_share').create<TrailShare>(data)
return json(r);
} catch (e: any) {
throw error(e.status, e)
}
}

View File

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

View File

@@ -4,22 +4,6 @@ import { pb } from '$lib/pocketbase';
import { error, json, type RequestEvent } from '@sveltejs/kit'
import { ClientResponseError } from 'pocketbase';
export async function GET(event: RequestEvent) {
const page = event.url.searchParams.get("page") ?? "0";
const perPage = event.url.searchParams.get("per-page") ?? "10";
const sort = event.url.searchParams.get("sort") ?? ""
const filter = event.url.searchParams.get("filter") ?? "";
try {
const r = await pb.collection('users_anonymous')
.getList<User>(parseInt(page), parseInt(perPage), { sort: sort ?? "", filter: filter ?? "" })
return json(r)
} catch (e: any) {
throw error(e.status, e);
}
}
export async function PUT(event: RequestEvent) {
const data = await event.request.json()
try {

View File

@@ -1,5 +1,5 @@
import type { User } from '$lib/models/user';
import { pb } from '$lib/pocketbase';
import type { User } from '$lib/stores/user_store';
import { error, json, type RequestEvent } from '@sveltejs/kit'
export async function GET(event: RequestEvent) {

View File

@@ -0,0 +1,19 @@
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 page = event.url.searchParams.get("page") ?? "0";
const perPage = event.url.searchParams.get("per-page") ?? "10";
const sort = event.url.searchParams.get("sort") ?? ""
const filter = event.url.searchParams.get("filter") ?? "";
try {
const r = await pb.collection('users_anonymous')
.getList<User>(parseInt(page), parseInt(perPage), { sort: sort ?? "", filter: filter ?? "" })
return json(r)
} catch (e: any) {
throw error(e.status, e);
}
}

View File

@@ -0,0 +1,13 @@
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) {
try {
const r = await pb.collection('users_anonymous')
.getOne<User>(event.params.id as string)
return json(r)
} catch (e: any) {
throw error(e.status, e);
}
}