feat: Ajout de React pour le front, début de refonte du front
This commit is contained in:
parent
73774f84ff
commit
666636e5bf
41
assets/react/app/infrastructure/api/apiMangaRepository.js
Normal file
41
assets/react/app/infrastructure/api/apiMangaRepository.js
Normal file
@@ -0,0 +1,41 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user