adds trail recommendation
This commit is contained in:
@@ -2,7 +2,7 @@ import { TrailCreateSchema } from '$lib/models/api/trail_schema';
|
||||
import type { Trail } from '$lib/models/trail';
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import { Collection, create, handleError, list } from '$lib/util/api_util';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
import { json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
try {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type TrailBoundingBox, type TrailFilterValues } from '$lib/models/trail';
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import { handleError } from '$lib/util/api_util';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
@@ -15,6 +16,6 @@ export async function GET(event: RequestEvent) {
|
||||
const r = await pb.collection('trails_bounding_box').getOne<TrailBoundingBox>(pb.authStore.model!.id)
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw error(e.status || 500, e);
|
||||
throw handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type TrailFilterValues } from '$lib/models/trail';
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import { handleError } from '$lib/util/api_util';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
@@ -15,6 +16,6 @@ export async function GET(event: RequestEvent) {
|
||||
const r = await pb.collection('trails_filter').getOne<TrailFilterValues>(pb.authStore.model!.id)
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw error(e.status || 500, e);
|
||||
throw handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
32
web/src/routes/api/v1/trail/recommend/+server.ts
Normal file
32
web/src/routes/api/v1/trail/recommend/+server.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { TrailRecommendSchema } from '$lib/models/api/trail_schema';
|
||||
import type { Trail } from '$lib/models/trail';
|
||||
import { pb } from '$lib/pocketbase';
|
||||
import { handleError } from '$lib/util/api_util';
|
||||
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||
|
||||
export async function GET(event: RequestEvent) {
|
||||
try {
|
||||
const searchParams = Object.fromEntries(event.url.searchParams);
|
||||
const safeSearchParams = TrailRecommendSchema.parse(searchParams);
|
||||
|
||||
const r = await event.fetch(pb.buildUrl("/trail/recommend?" + new URLSearchParams({
|
||||
size: safeSearchParams.size?.toString() ?? ""
|
||||
})));
|
||||
|
||||
const result: Trail[] = await r.json();
|
||||
|
||||
for (const t of result) {
|
||||
if (!t.author || !pb.authStore.model) {
|
||||
continue;
|
||||
}
|
||||
if (!t.expand) {
|
||||
t.expand = {} as any
|
||||
}
|
||||
t.expand!.author = await pb.collection("users_anonymous").getOne(t.author);
|
||||
}
|
||||
|
||||
return json(result)
|
||||
} catch (e: any) {
|
||||
throw handleError(e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user