adds trail link sharing
This commit is contained in:
26
web/src/routes/api/v1/trail-link-share/+server.ts
Normal file
26
web/src/routes/api/v1/trail-link-share/+server.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { TrailLinkShareCreateSchema } from '$lib/models/api/trail_link_share_schema';
|
||||
import type { TrailLinkShare } from '$lib/models/trail_link_share';
|
||||
import { Collection, handleError, list } from '$lib/util/api_util';
|
||||
import { json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
try {
|
||||
const r = await list<TrailLinkShare>(event, Collection.trail_link_share);
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
handleError(e)
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(event: RequestEvent) {
|
||||
try {
|
||||
const data = await event.request.json();
|
||||
const safeData = TrailLinkShareCreateSchema.parse(data);
|
||||
|
||||
const r = await event.locals.pb.collection(Collection.trail_link_share).create<TrailLinkShare>(safeData)
|
||||
|
||||
return json(r);
|
||||
} catch (e) {
|
||||
return handleError(e)
|
||||
}
|
||||
}
|
||||
31
web/src/routes/api/v1/trail-link-share/[id]/+server.ts
Normal file
31
web/src/routes/api/v1/trail-link-share/[id]/+server.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { TrailLinkShareUpdateSchema } from "$lib/models/api/trail_link_share_schema";
|
||||
import type { TrailLinkShare } from "$lib/models/trail_link_share";
|
||||
import { Collection, handleError, remove, show, update } from "$lib/util/api_util";
|
||||
import { json, type RequestEvent } from "@sveltejs/kit";
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
try {
|
||||
const r = await show<TrailLinkShare>(event, Collection.trail_link_share)
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
return handleError(e)
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
try {
|
||||
const r = await update<TrailLinkShare>(event, TrailLinkShareUpdateSchema, Collection.trail_link_share)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
return handleError(e)
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(event: RequestEvent) {
|
||||
try {
|
||||
const r = await remove(event, Collection.trail_link_share)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
return handleError(e)
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,9 @@ export async function GET(event: RequestEvent) {
|
||||
event.url.searchParams.delete("handle")
|
||||
|
||||
const safeSearchParams = RecordOptionsSchema.parse(Object.fromEntries(event.url.searchParams));
|
||||
|
||||
if (event.url.searchParams.has("share")) {
|
||||
safeSearchParams.query = { share: event.url.searchParams.get("share")! }
|
||||
}
|
||||
let origin = new URL(actor.iri).origin
|
||||
let iri = `${origin}/api/v1/trail/${event.params.id}`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user