import { BaseApiService } from "./base-api.service"; import { KomgaBook, KomgaSeries } from "@/types/komga"; import { LibraryResponse } from "@/types/library"; import { getServerCacheService } from "./server-cache.service"; import { ERROR_CODES } from "../../constants/errorCodes"; import { AppError } from "../../utils/errors"; interface HomeData { ongoing: KomgaSeries[]; ongoingBooks: KomgaBook[]; // Nouveau champ recentlyRead: KomgaBook[]; onDeck: KomgaBook[]; latestSeries: KomgaSeries[]; } export class HomeService extends BaseApiService { static async getHomeData(): Promise { try { const [ongoing, ongoingBooks, recentlyRead, onDeck, latestSeries] = await Promise.all([ this.fetchWithCache>( "home-ongoing", async () => this.fetchFromApi>({ path: "series", params: { read_status: "IN_PROGRESS", sort: "readDate,desc", page: "0", size: "10", media_status: "READY", }, }), "HOME" ), this.fetchWithCache>( "home-ongoing-books", async () => this.fetchFromApi>({ path: "books", params: { read_status: "IN_PROGRESS", sort: "readProgress.readDate,desc", page: "0", size: "10", media_status: "READY", }, }), "HOME" ), this.fetchWithCache>( "home-recently-read", async () => this.fetchFromApi>({ path: "books/latest", params: { page: "0", size: "10", media_status: "READY", }, }), "HOME" ), this.fetchWithCache>( "home-on-deck", async () => this.fetchFromApi>({ path: "books/ondeck", params: { page: "0", size: "10", media_status: "READY", }, }), "HOME" ), this.fetchWithCache>( "home-latest-series", async () => this.fetchFromApi>({ path: "series/latest", params: { page: "0", size: "10", media_status: "READY", }, }), "HOME" ), ]); return { ongoing: ongoing.content || [], ongoingBooks: ongoingBooks.content || [], // Nouveau champ recentlyRead: recentlyRead.content || [], onDeck: onDeck.content || [], latestSeries: latestSeries.content || [], }; } catch (error) { throw new AppError(ERROR_CODES.HOME.FETCH_ERROR, {}, error); } } static async invalidateHomeCache(): Promise { try { const cacheService = await getServerCacheService(); await cacheService.delete("home-ongoing"); await cacheService.delete("home-ongoing-books"); // Nouvelle clé de cache await cacheService.delete("home-recently-read"); await cacheService.delete("home-on-deck"); await cacheService.delete("home-latest-series"); } catch (error) { throw new AppError(ERROR_CODES.CACHE.DELETE_ERROR, {}, error); } } }