feat: personal library — filter by read/saved books, add save button
Some checks failed
Deploy / Deploy Production (push) Has been skipped
Deploy / Deploy Preview (push) Failing after 1s
Deploy / Cleanup Preview (push) Has been skipped
CI / Scraper / Lint (pull_request) Successful in 13s
CI / Scraper / Test (pull_request) Successful in 19s
CI / UI / Build (pull_request) Successful in 20s
CI / Scraper / Build (pull_request) Successful in 18s
Some checks failed
Deploy / Deploy Production (push) Has been skipped
Deploy / Deploy Preview (push) Failing after 1s
Deploy / Cleanup Preview (push) Has been skipped
CI / Scraper / Lint (pull_request) Successful in 13s
CI / Scraper / Test (pull_request) Successful in 19s
CI / UI / Build (pull_request) Successful in 20s
CI / Scraper / Build (pull_request) Successful in 18s
This commit is contained in:
34
ui/src/routes/api/library/[slug]/+server.ts
Normal file
34
ui/src/routes/api/library/[slug]/+server.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { saveBook, unsaveBook } from '$lib/server/pocketbase';
|
||||
import { log } from '$lib/server/logger';
|
||||
|
||||
/**
|
||||
* POST /api/library/[slug]
|
||||
* Save a book to the user's personal library.
|
||||
*/
|
||||
export const POST: RequestHandler = async ({ params, locals }) => {
|
||||
const { slug } = params;
|
||||
try {
|
||||
await saveBook(locals.sessionId, slug, locals.user?.id);
|
||||
} catch (e) {
|
||||
log.error('library', 'saveBook failed', { slug, err: String(e) });
|
||||
error(500, 'Failed to save book');
|
||||
}
|
||||
return json({ ok: true });
|
||||
};
|
||||
|
||||
/**
|
||||
* DELETE /api/library/[slug]
|
||||
* Remove a book from the user's personal library.
|
||||
*/
|
||||
export const DELETE: RequestHandler = async ({ params, locals }) => {
|
||||
const { slug } = params;
|
||||
try {
|
||||
await unsaveBook(locals.sessionId, slug, locals.user?.id);
|
||||
} catch (e) {
|
||||
log.error('library', 'unsaveBook failed', { slug, err: String(e) });
|
||||
error(500, 'Failed to remove book');
|
||||
}
|
||||
return json({ ok: true });
|
||||
};
|
||||
Reference in New Issue
Block a user