78 lines
1.7 KiB
JavaScript
78 lines
1.7 KiB
JavaScript
import { Chapter } from './chapter.js';
|
|
|
|
export class Manga {
|
|
constructor(
|
|
id,
|
|
title,
|
|
slug,
|
|
imageUrl,
|
|
author,
|
|
publicationYear,
|
|
genres,
|
|
status,
|
|
rating,
|
|
description = '',
|
|
createdAt = null
|
|
) {
|
|
this.id = id;
|
|
this.title = title;
|
|
this.slug = slug;
|
|
this.imageUrl = imageUrl;
|
|
this.author = author;
|
|
this.publicationYear = publicationYear;
|
|
this.genres = genres;
|
|
this.status = status;
|
|
this.rating = rating;
|
|
this.description = description;
|
|
this.createdAt = createdAt;
|
|
}
|
|
}
|
|
|
|
export class MangaCollection {
|
|
constructor(items, total, page, limit, hasNextPage, hasPreviousPage) {
|
|
this.items = items;
|
|
this.total = total;
|
|
this.page = page;
|
|
this.limit = limit;
|
|
this.hasNextPage = hasNextPage;
|
|
this.hasPreviousPage = hasPreviousPage;
|
|
}
|
|
}
|
|
|
|
export class MangaDetail extends Manga {
|
|
constructor(manga, chapters = []) {
|
|
super(
|
|
manga.id,
|
|
manga.title,
|
|
manga.slug,
|
|
manga.imageUrl,
|
|
manga.author,
|
|
manga.publicationYear,
|
|
manga.genres,
|
|
manga.status,
|
|
manga.rating,
|
|
manga.description,
|
|
manga.createdAt
|
|
);
|
|
this.chapters = this.organizeChaptersByVolume(chapters);
|
|
}
|
|
|
|
organizeChaptersByVolume(chapters) {
|
|
const volumeMap = new Map();
|
|
|
|
chapters.forEach(chapter => {
|
|
const volume = chapter.volume || 0;
|
|
if (!volumeMap.has(volume)) {
|
|
volumeMap.set(volume, []);
|
|
}
|
|
volumeMap.get(volume).push(chapter);
|
|
});
|
|
|
|
// Sort chapters within each volume
|
|
volumeMap.forEach(chapters => {
|
|
chapters.sort((a, b) => b.number - a.number);
|
|
});
|
|
|
|
return new Map([...volumeMap.entries()].sort((a, b) => b[0] - a[0]));
|
|
}
|
|
} |