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,57 @@
import type { TrailShare } from "$lib/models/trail_share";
import { ClientResponseError } from "pocketbase";
import { writable, type Writable } from "svelte/store";
export const shares: Writable<TrailShare[]> = writable([])
export async function trail_share_index(trail: string, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
const r = await f('/api/v1/trail-share?' + new URLSearchParams({
filter: `trail='${trail}'`,
}), {
method: 'GET',
})
if (!r.ok) {
throw new ClientResponseError(await r.json())
}
const response: TrailShare[] = await r.json();
shares.set(response);
return shares;
}
export async function trail_share_create(share: TrailShare) {
let r = await fetch('/api/v1/trail-share', {
method: 'PUT',
body: JSON.stringify(share),
})
if (!r.ok) {
throw new ClientResponseError(await r.json())
}
}
export async function trail_share_update(share: TrailShare) {
let r = await fetch('/api/v1/trail-share/' + share.id, {
method: 'POST',
body: JSON.stringify(share),
})
if (!r.ok) {
throw new ClientResponseError(await r.json())
}
}
export async function trail_share_delete(share: TrailShare) {
const r = await fetch('/api/v1/trail-share/' + share.id, {
method: 'DELETE',
})
if (!r.ok) {
throw new ClientResponseError(await r.json())
}
}

View File

@@ -55,7 +55,7 @@ export async function trails_search_filter(filter: TrailFilter, page: number = 1
}
r = await f('/api/v1/trail?' + new URLSearchParams({
expand: "category,waypoints,summit_logs",
expand: "category,waypoints,summit_logs,trail_share_via_trail",
filter: trailIds.map((id: Record<string, any>) => `id="${id}"`).join('||'),
sort: `${filter.sortOrder}${filter.sort}`
}), {
@@ -131,7 +131,7 @@ export async function trails_search_bounding_box(northEast: LatLng, southWest: L
export async function trails_show(id: string, loadGPX?: boolean, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
const r = await f(`/api/v1/trail/${id}?` + new URLSearchParams({
expand: "category,waypoints,summit_logs,comments_via_trail.author",
expand: "category,waypoints,summit_logs,comments_via_trail.author,trail_share_via_trail",
}), {
method: 'GET',
})

View File

@@ -24,8 +24,8 @@ export async function users_create(user: User) {
}
export async function users_search(q: string) {
let r = await fetch('/api/v1/user?' + new URLSearchParams({
"filter": `username~"${q}"`,
let r = await fetch('/api/v1/user/anonymous?' + new URLSearchParams({
"filter": `username~"${q}"&&id!="${pb.authStore.model?.id}"`,
}), {
method: 'GET',
})
@@ -38,6 +38,19 @@ export async function users_search(q: string) {
}
}
export async function users_show(id: string) {
let r = await fetch(`/api/v1/user/anonymous/${id}`, {
method: 'GET',
})
const response = await r.json()
if (r.ok) {
return response;
} else {
throw new ClientResponseError(response)
}
}
export async function users_auth_methods(f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch): Promise<AuthMethodsList> {
const r = await f('/api/v1/auth/oauth', {
method: 'GET',