adds tags
This commit is contained in:
23
web/src/routes/api/v1/tag/+server.ts
Normal file
23
web/src/routes/api/v1/tag/+server.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { TagCreateSchema } from '$lib/models/api/tag_schema';
|
||||
import type { Tag } from '$lib/models/tag';
|
||||
import { Collection, create, 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<Tag>(event, Collection.tags);
|
||||
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(event: RequestEvent) {
|
||||
try {
|
||||
const r = await create<Tag>(event, TagCreateSchema, Collection.tags)
|
||||
return json(r);
|
||||
} catch (e) {
|
||||
throw handleError(e)
|
||||
}
|
||||
}
|
||||
31
web/src/routes/api/v1/tag/[id]/+server.ts
Normal file
31
web/src/routes/api/v1/tag/[id]/+server.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { TagUpdateSchema } from "$lib/models/api/tag_schema";
|
||||
import type { Tag } from "$lib/models/tag";
|
||||
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<Tag>(event, Collection.tags)
|
||||
return json(r)
|
||||
} catch (e: any) {
|
||||
throw handleError(e)
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(event: RequestEvent) {
|
||||
try {
|
||||
const r = await update<Tag>(event, TagUpdateSchema, Collection.tags)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw handleError(e)
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(event: RequestEvent) {
|
||||
try {
|
||||
const r = await remove(event, Collection.tags)
|
||||
return json(r);
|
||||
} catch (e: any) {
|
||||
throw handleError(e)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user