41 lines
910 B
JavaScript
41 lines
910 B
JavaScript
import axios from 'axios';
|
|
import { Manga, MangaCollection } from '../../domain/manga';
|
|
|
|
export class ApiMangaRepository {
|
|
constructor() {
|
|
this.api = axios.create({
|
|
baseURL: '/api'
|
|
});
|
|
}
|
|
|
|
async getMangaCollection(page = 1) {
|
|
try {
|
|
const response = await this.api.get(`/mangas?page=${page}`);
|
|
const data = response.data;
|
|
|
|
const mangas = data.items.map(item => new Manga(
|
|
item.id,
|
|
item.title,
|
|
item.slug,
|
|
item.imageUrl,
|
|
item.author,
|
|
item.publicationYear,
|
|
item.genres,
|
|
item.status,
|
|
item.rating
|
|
));
|
|
|
|
return new MangaCollection(
|
|
mangas,
|
|
data.total,
|
|
data.page,
|
|
data.limit,
|
|
data.hasNextPage,
|
|
data.hasPreviousPage
|
|
);
|
|
} catch (error) {
|
|
console.error('Error fetching manga collection:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
} |