109 lines
3.3 KiB
JavaScript
109 lines
3.3 KiB
JavaScript
import { Manga, MangaCollection, MangaDetail } from '../../domain/manga.js';
|
|
import { Chapter } from '../../domain/chapter.js';
|
|
|
|
export class MockMangaRepository {
|
|
constructor() {
|
|
this.mangas = {
|
|
'one-piece': {
|
|
id: '1',
|
|
title: 'One Piece',
|
|
slug: 'one-piece',
|
|
imageUrl: 'https://images.unsplash.com/photo-1607604276583-eef5d076aa5f?auto=format&fit=crop&w=800&q=80',
|
|
author: 'Eiichiro Oda',
|
|
publicationYear: 1997,
|
|
genres: ['Action', 'Adventure', 'Comedy'],
|
|
status: 'ongoing',
|
|
rating: 4.9,
|
|
description: 'Monkey D. Luffy refuses to let anyone or anything stand in the way of his quest to become king of all pirates.'
|
|
},
|
|
'naruto': {
|
|
id: '2',
|
|
title: 'Naruto',
|
|
slug: 'naruto',
|
|
imageUrl: 'https://images.unsplash.com/photo-1618519764620-7403abdbdfe9?auto=format&fit=crop&w=800&q=80',
|
|
author: 'Masashi Kishimoto',
|
|
publicationYear: 1999,
|
|
genres: ['Action', 'Adventure', 'Fantasy'],
|
|
status: 'completed',
|
|
rating: 4.8,
|
|
description: 'Twelve years ago the Village Hidden in the Leaves was attacked by a fearsome threat.'
|
|
},
|
|
'berserk': {
|
|
id: '3',
|
|
title: 'Berserk',
|
|
slug: 'berserk',
|
|
imageUrl: 'https://images.unsplash.com/photo-1607604276583-eef5d076aa5f?auto=format&fit=crop&w=800&q=80',
|
|
author: 'Kentaro Miura',
|
|
publicationYear: 1989,
|
|
genres: ['Action', 'Dark Fantasy', 'Horror', 'Psychological'],
|
|
status: 'ongoing',
|
|
rating: 4.9,
|
|
description: 'Guts, known as the Black Swordsman, seeks sanctuary from the demonic forces.'
|
|
}
|
|
};
|
|
}
|
|
|
|
async searchMangas(query) {
|
|
if (!query) return [];
|
|
|
|
const normalizedQuery = query.toLowerCase();
|
|
return Object.values(this.mangas)
|
|
.filter(manga =>
|
|
manga.title.toLowerCase().includes(normalizedQuery) ||
|
|
manga.author.toLowerCase().includes(normalizedQuery)
|
|
)
|
|
.map(manga => new Manga(
|
|
manga.id,
|
|
manga.title,
|
|
manga.slug,
|
|
manga.imageUrl,
|
|
manga.author,
|
|
manga.publicationYear,
|
|
manga.genres,
|
|
manga.status,
|
|
manga.rating
|
|
));
|
|
}
|
|
|
|
async getMangaCollection(page = 1) {
|
|
const mangas = Object.values(this.mangas).map(manga => new Manga(
|
|
manga.id,
|
|
manga.title,
|
|
manga.slug,
|
|
manga.imageUrl,
|
|
manga.author,
|
|
manga.publicationYear,
|
|
manga.genres,
|
|
manga.status,
|
|
manga.rating
|
|
));
|
|
|
|
return new MangaCollection(
|
|
mangas,
|
|
mangas.length,
|
|
page,
|
|
10,
|
|
false,
|
|
false
|
|
);
|
|
}
|
|
|
|
async getMangaBySlug(slug) {
|
|
const manga = this.mangas[slug];
|
|
|
|
if (!manga) {
|
|
throw new Error(`Manga with slug "${slug}" not found`);
|
|
}
|
|
|
|
const chapters = [
|
|
new Chapter('1', 378, 'Un assassin invité', 42, true, '2024-02-15'),
|
|
new Chapter('2', 377, 'Snake In One\'s Bosom', 42, true, '2024-02-01'),
|
|
new Chapter('3', 376, 'La mer tremble, la guerre se profile', 42, true, '2024-01-15'),
|
|
new Chapter('4', 375, 'L\'aube suivant la nuit brumeuse', 41, true, '2024-01-01'),
|
|
new Chapter('5', 374, 'Le monstre noir va-t-il se laisser faire ?', 41, true, '2023-12-15'),
|
|
new Chapter('6', 373, 'Confrontation', 41, true, '2023-12-01'),
|
|
];
|
|
|
|
return new MangaDetail(manga, chapters);
|
|
}
|
|
} |