adds svelte API
This commit is contained in:
13
web/src/routes/api/v1/auth/login/+server.ts
Normal file
13
web/src/routes/api/v1/auth/login/+server.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
const data = await event.request.json()
|
||||
try {
|
||||
const r = await pb.collection('users').authWithPassword(data.email ?? data.username!, data.password);
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e);
|
||||
}
|
||||
|
||||
}
|
||||
28
web/src/routes/api/v1/list/+server.ts
Normal file
28
web/src/routes/api/v1/list/+server.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { List } from '$lib/models/list';
|
||||
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') ?? ""
|
||||
try {
|
||||
const r: List[] = await pb.collection('lists').getFullList<List>({
|
||||
expand: "trails",
|
||||
sort: sort,
|
||||
})
|
||||
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('lists').create<List>(data)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
23
web/src/routes/api/v1/list/[id]/+server.ts
Normal file
23
web/src/routes/api/v1/list/[id]/+server.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
import type { List } from "postcss/lib/list";
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
const data = await event.request.json()
|
||||
|
||||
try {
|
||||
const r = await pb.collection('lists').update<List>(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('lists').delete(event.params.id as string)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
13
web/src/routes/api/v1/list/[id]/file/+server.ts
Normal file
13
web/src/routes/api/v1/list/[id]/file/+server.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
import type { List } from "postcss/lib/list";
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
const data = await event.request.formData()
|
||||
try {
|
||||
const r = await pb.collection("lists").update<List>(event.params.id as string, data,);
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
14
web/src/routes/api/v1/summit-log/+server.ts
Normal file
14
web/src/routes/api/v1/summit-log/+server.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { SummitLog } from '$lib/models/summit_log';
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function PUT(event: RequestEvent) {
|
||||
const data = await event.request.json();
|
||||
|
||||
try {
|
||||
const r = await pb.collection('summit_logs').create<SummitLog>(data)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
23
web/src/routes/api/v1/summit-log/[id]/+server.ts
Normal file
23
web/src/routes/api/v1/summit-log/[id]/+server.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { SummitLog } from "$lib/models/summit_log";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
const data = await event.request.json()
|
||||
try {
|
||||
const r = await await pb.collection("summit_logs").update<SummitLog>(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('summit_logs').delete(event.params.id as string)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
30
web/src/routes/api/v1/trail/+server.ts
Normal file
30
web/src/routes/api/v1/trail/+server.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { Trail } from '$lib/models/trail';
|
||||
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") ?? "5";
|
||||
const expand = event.url.searchParams.get("expand") ?? ""
|
||||
const sort = event.url.searchParams.get("sort") ?? ""
|
||||
const filter = event.url.searchParams.get("filter") ?? "";
|
||||
|
||||
try {
|
||||
const r = await pb.collection('trails')
|
||||
.getList<Trail>(parseInt(page), parseInt(perPage), { expand: expand ?? "", 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 {
|
||||
const r = await pb.collection('trails').create<Trail>(data)
|
||||
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
35
web/src/routes/api/v1/trail/[id]/+server.ts
Normal file
35
web/src/routes/api/v1/trail/[id]/+server.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { Trail } from "$lib/models/trail";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
const expand = event.url.searchParams.get("expand") ?? ""
|
||||
|
||||
try {
|
||||
const r = await pb.collection('trails')
|
||||
.getOne<Trail>(event.params.id as string, { expand: expand ?? "" })
|
||||
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("trails").update<Trail>(event.params.id as string, data, { expand: "category,waypoints,summit_logs" });
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(event: RequestEvent) {
|
||||
try {
|
||||
const r = await pb.collection('trails').delete(event.params.id as string)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
13
web/src/routes/api/v1/trail/[id]/file/+server.ts
Normal file
13
web/src/routes/api/v1/trail/[id]/file/+server.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { Trail } from "$lib/models/trail";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
const data = await event.request.formData()
|
||||
try {
|
||||
const r = await pb.collection("trails").update<Trail>(event.params.id as string, data,);
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
33
web/src/routes/api/v1/user/+server.ts
Normal file
33
web/src/routes/api/v1/user/+server.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import type { User } from '$lib/stores/user_store';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit'
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
const data = await event.request.json()
|
||||
try {
|
||||
const r = await pb.collection('lists').update<User>(data.id, data.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('users').create<User>(data)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(event: RequestEvent) {
|
||||
const data = await event.request.json()
|
||||
try {
|
||||
const r = await pb.collection('users').delete(data.id)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
14
web/src/routes/api/v1/waypoint/+server.ts
Normal file
14
web/src/routes/api/v1/waypoint/+server.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import type { Waypoint } from '$lib/models/waypoint';
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function PUT(event: RequestEvent) {
|
||||
const data = await event.request.json();
|
||||
|
||||
try {
|
||||
const r = await pb.collection('waypoints').create<Waypoint>(data)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
23
web/src/routes/api/v1/waypoint/[id]/+server.ts
Normal file
23
web/src/routes/api/v1/waypoint/[id]/+server.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { Waypoint } from "$lib/models/waypoint";
|
||||
import { pb } from "$lib/pocketbase";
|
||||
import { error, json, type RequestEvent } from "@sveltejs/kit";
|
||||
|
||||
|
||||
export async function POST(event: RequestEvent){
|
||||
const data = await event.request.json()
|
||||
try {
|
||||
const r = await await pb.collection("waypoints").update<Waypoint>(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('waypoints').delete(event.params.id as string)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw error(e.status, e)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user