fix: add missing book API methods and types (searchBooks, getBook, getGenres, getAuthors)

This commit is contained in:
Marko (Hermes Implementer)
2026-05-29 00:08:32 +00:00
parent 332b539880
commit 670101b61e
3 changed files with 60 additions and 3 deletions
+31 -1
View File
@@ -1,5 +1,15 @@
import api from "./client";
import type { ContentResponse, EBookDetail, EBookListItem, ReadingProgress, ReadingSettings, TocResponse } from "../types/book";
import type {
BookDetail,
BookListItem,
BookSearchParams,
ContentResponse,
EBookDetail,
EBookListItem,
ReadingProgress,
ReadingSettings,
TocResponse,
} from "../types/book";
export const booksApi = {
async getEBooks(): Promise<EBookListItem[]> {
@@ -12,6 +22,26 @@ export const booksApi = {
return data;
},
async searchBooks(params: BookSearchParams = {}): Promise<{ count: number; results: BookListItem[] }> {
const { data } = await api.get<{ count: number; results: BookListItem[] }>("/books/", { params });
return data;
},
async getBook(id: number): Promise<BookDetail> {
const { data } = await api.get<BookDetail>(`/books/${id}/`);
return data;
},
async getGenres(): Promise<string[]> {
const { data } = await api.get<string[]>("/books/genres/");
return data;
},
async getAuthors(): Promise<string[]> {
const { data } = await api.get<string[]>("/books/authors/");
return data;
},
async uploadEBook(
file: File,
title: string,
+19 -1
View File
@@ -81,4 +81,22 @@ export interface ContentResponse {
content: string;
chapter_title: string;
format: string;
}
}
export interface BookSearchParams {
q?: string;
genre?: string;
author?: string;
reading_status?: string;
ordering?: string;
page?: number;
page_size?: number;
}
export const READING_STATUS_OPTIONS: { value: string; label: string }[] = [
{ value: "", label: "All Statuses" },
{ value: "want_to_read", label: "Want to Read" },
{ value: "reading", label: "Reading" },
{ value: "finished", label: "Finished" },
{ value: "dnf", label: "Did Not Finish" },
];