feat: Reader working, some work still need to be done
This commit is contained in:
parent
33f5a5568a
commit
668702b1fb
@@ -1,5 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import { Manga, MangaCollection } from '../../domain/manga';
|
||||
import { Manga, MangaCollection, MangaDetail } from '../../domain/manga';
|
||||
import { Chapter } from '../../domain/chapter';
|
||||
|
||||
export class ApiMangaRepository {
|
||||
constructor() {
|
||||
@@ -38,4 +39,62 @@ export class ApiMangaRepository {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async searchMangas(query) {
|
||||
try {
|
||||
const response = await this.api.get(`/mangas-search?title=${encodeURIComponent(query)}`);
|
||||
const data = response.data;
|
||||
|
||||
return data.items.map(item => new Manga(
|
||||
item.externalId,
|
||||
item.title,
|
||||
item.slug,
|
||||
item.imageUrl,
|
||||
item.author,
|
||||
item.publicationYear,
|
||||
item.genres,
|
||||
item.status,
|
||||
item.rating,
|
||||
item.description
|
||||
));
|
||||
} catch (error) {
|
||||
console.error('Error searching mangas:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getMangaBySlug(slug) {
|
||||
try {
|
||||
const mangaResponse = await this.api.get(`/mangas/by-slug/${slug}`);
|
||||
const mangaData = mangaResponse.data;
|
||||
|
||||
const chaptersResponse = await this.api.get(`/mangas/${mangaData.id}/chapters?page=1&limit=1000&sortOrder=desc`);
|
||||
const chaptersData = chaptersResponse.data;
|
||||
|
||||
const chapters = chaptersData.items.map(item => new Chapter(
|
||||
item.id,
|
||||
parseFloat(item.number),
|
||||
item.title,
|
||||
item.volume,
|
||||
item.isVisible,
|
||||
item.createdAt
|
||||
));
|
||||
|
||||
return new MangaDetail({
|
||||
id: mangaData.id,
|
||||
title: mangaData.title,
|
||||
slug: mangaData.slug,
|
||||
imageUrl: mangaData.imageUrl,
|
||||
author: mangaData.author,
|
||||
publicationYear: mangaData.publicationYear,
|
||||
genres: mangaData.genres,
|
||||
status: mangaData.status,
|
||||
rating: mangaData.rating,
|
||||
description: mangaData.description
|
||||
}, chapters);
|
||||
} catch (error) {
|
||||
console.error('Error fetching manga details:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user