- `GET /v1/authors/:id` returns `AuthorWithCount` (id, name, manga_count). - `GET /v1/authors/:id/mangas` paged works by that author. - `GET /v1/authors?search=` autocomplete (already used by Phase 1 forms; now formally exposed). - New `/authors/:id` page on the frontend; author chips on the manga detail page (added in Phase 1) now link to a real page. - Extracts `lib/components/MangaCard.svelte` — already used by the home page, ready for the collection page in Phase 3. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import { request, type Page } from './client';
|
|
import type { Manga } from './client';
|
|
|
|
export type Author = {
|
|
id: string;
|
|
name: string;
|
|
created_at: string;
|
|
};
|
|
|
|
/** Returned by `GET /v1/authors/:id` — adds the count of attached mangas. */
|
|
export type AuthorWithCount = Author & {
|
|
manga_count: number;
|
|
};
|
|
|
|
export type AuthorMangasPage = {
|
|
items: Manga[];
|
|
page: Page;
|
|
};
|
|
|
|
export type ListAuthorsOptions = {
|
|
search?: string;
|
|
limit?: number;
|
|
offset?: number;
|
|
};
|
|
|
|
export type ListAuthorMangasOptions = {
|
|
limit?: number;
|
|
offset?: number;
|
|
};
|
|
|
|
/** Autocomplete for author pickers. Server sorts by trigram similarity. */
|
|
export async function listAuthors(opts: ListAuthorsOptions = {}): Promise<Author[]> {
|
|
const params = new URLSearchParams();
|
|
if (opts.search) params.set('search', opts.search);
|
|
if (opts.limit != null) params.set('limit', String(opts.limit));
|
|
if (opts.offset != null) params.set('offset', String(opts.offset));
|
|
const qs = params.toString();
|
|
return request<Author[]>(`/v1/authors${qs ? `?${qs}` : ''}`);
|
|
}
|
|
|
|
export async function getAuthor(id: string): Promise<AuthorWithCount> {
|
|
return request<AuthorWithCount>(`/v1/authors/${encodeURIComponent(id)}`);
|
|
}
|
|
|
|
export async function listAuthorMangas(
|
|
id: string,
|
|
opts: ListAuthorMangasOptions = {}
|
|
): Promise<AuthorMangasPage> {
|
|
const params = new URLSearchParams();
|
|
if (opts.limit != null) params.set('limit', String(opts.limit));
|
|
if (opts.offset != null) params.set('offset', String(opts.offset));
|
|
const qs = params.toString();
|
|
return request<AuthorMangasPage>(
|
|
`/v1/authors/${encodeURIComponent(id)}/mangas${qs ? `?${qs}` : ''}`
|
|
);
|
|
}
|