feat: add manga and shows collections

This commit is contained in:
2026-02-04 15:41:23 -08:00
parent e5b15e02de
commit 11be34cd21
21 changed files with 2518 additions and 24 deletions
+99
View File
@@ -0,0 +1,99 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { FastifyPluginAsync } from "fastify";
import { Manga, CreateMangaDto, UpdateMangaDto, Comment, CreateCommentDto } from "@library/shared-types";
import { MangaService } from "../../services/manga.service";
import { CommentService } from "../../services/comment.service";
import { adminGuard } from "../../middleware/admin-guard";
const mangaRoutes: FastifyPluginAsync = async (app) => {
const mangaService = new MangaService();
const commentService = new CommentService();
app.get<{ Reply: Manga[] }>("/", async () => {
return mangaService.getAllManga();
});
app.get<{ Params: { id: string }; Reply: Manga | null }>(
"/:id",
async (request) => {
const { id } = request.params;
return mangaService.getMangaById(id);
}
);
app.post<{ Body: CreateMangaDto; Reply: Manga }>(
"/",
{
preValidation: [app.authenticate, adminGuard],
},
async (request) => {
return mangaService.createManga(request.body);
}
);
app.put<{
Params: { id: string };
Body: UpdateMangaDto;
Reply: Manga | null;
}>(
"/:id",
{
preValidation: [app.authenticate, adminGuard],
},
async (request) => {
const { id } = request.params;
return mangaService.updateManga(id, request.body);
}
);
app.delete<{ Params: { id: string }; Reply: { success: boolean } }>(
"/:id",
{
preValidation: [app.authenticate, adminGuard],
},
async (request) => {
const { id } = request.params;
await mangaService.deleteManga(id);
return { success: true };
}
);
app.get<{ Params: { id: string }; Reply: Comment[] }>(
"/:id/comments",
async (request) => {
const { id } = request.params;
return commentService.getCommentsForManga(id);
}
);
app.post<{ Params: { id: string }; Body: CreateCommentDto; Reply: Comment }>(
"/:id/comments",
{
preValidation: [app.authenticate],
},
async (request) => {
const { id } = request.params;
const userId = request.user.id;
return commentService.createCommentForManga(id, userId, request.body);
}
);
app.delete<{ Params: { id: string; commentId: string }; Reply: { success: boolean } }>(
"/:id/comments/:commentId",
{
preValidation: [app.authenticate, adminGuard],
},
async (request) => {
const { commentId } = request.params;
await commentService.deleteComment(commentId);
return { success: true };
}
);
};
export default mangaRoutes;
+99
View File
@@ -0,0 +1,99 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { FastifyPluginAsync } from "fastify";
import { Show, CreateShowDto, UpdateShowDto, Comment, CreateCommentDto } from "@library/shared-types";
import { ShowService } from "../../services/show.service";
import { CommentService } from "../../services/comment.service";
import { adminGuard } from "../../middleware/admin-guard";
const showsRoutes: FastifyPluginAsync = async (app) => {
const showService = new ShowService();
const commentService = new CommentService();
app.get<{ Reply: Show[] }>("/", async () => {
return showService.getAllShows();
});
app.get<{ Params: { id: string }; Reply: Show | null }>(
"/:id",
async (request) => {
const { id } = request.params;
return showService.getShowById(id);
}
);
app.post<{ Body: CreateShowDto; Reply: Show }>(
"/",
{
preValidation: [app.authenticate, adminGuard],
},
async (request) => {
return showService.createShow(request.body);
}
);
app.put<{
Params: { id: string };
Body: UpdateShowDto;
Reply: Show | null;
}>(
"/:id",
{
preValidation: [app.authenticate, adminGuard],
},
async (request) => {
const { id } = request.params;
return showService.updateShow(id, request.body);
}
);
app.delete<{ Params: { id: string }; Reply: { success: boolean } }>(
"/:id",
{
preValidation: [app.authenticate, adminGuard],
},
async (request) => {
const { id } = request.params;
await showService.deleteShow(id);
return { success: true };
}
);
app.get<{ Params: { id: string }; Reply: Comment[] }>(
"/:id/comments",
async (request) => {
const { id } = request.params;
return commentService.getCommentsForShow(id);
}
);
app.post<{ Params: { id: string }; Body: CreateCommentDto; Reply: Comment }>(
"/:id/comments",
{
preValidation: [app.authenticate],
},
async (request) => {
const { id } = request.params;
const userId = request.user.id;
return commentService.createCommentForShow(id, userId, request.body);
}
);
app.delete<{ Params: { id: string; commentId: string }; Reply: { success: boolean } }>(
"/:id/comments/:commentId",
{
preValidation: [app.authenticate, adminGuard],
},
async (request) => {
const { commentId } = request.params;
await commentService.deleteComment(commentId);
return { success: true };
}
);
};
export default showsRoutes;
+54
View File
@@ -64,6 +64,8 @@ export class CommentService {
bookId: comment.bookId || undefined,
musicId: comment.musicId || undefined,
artId: comment.artId || undefined,
showId: comment.showId || undefined,
mangaId: comment.mangaId || undefined,
createdAt: comment.createdAt,
updatedAt: comment.updatedAt,
};
@@ -173,6 +175,58 @@ export class CommentService {
return this.mapComment(comment);
}
async getCommentsForShow(showId: string): Promise<Comment[]> {
const comments = await this.prisma.comment.findMany({
where: { showId },
include: { user: true },
orderBy: { createdAt: "desc" },
});
return comments.map((c) => this.mapComment(c));
}
async createCommentForShow(
showId: string,
userId: string,
data: CreateCommentDto
): Promise<Comment> {
const sanitizedContent = this.sanitizeMarkdown(data.content);
const comment = await this.prisma.comment.create({
data: {
content: sanitizedContent,
userId,
showId,
},
include: { user: true },
});
return this.mapComment(comment);
}
async getCommentsForManga(mangaId: string): Promise<Comment[]> {
const comments = await this.prisma.comment.findMany({
where: { mangaId },
include: { user: true },
orderBy: { createdAt: "desc" },
});
return comments.map((c) => this.mapComment(c));
}
async createCommentForManga(
mangaId: string,
userId: string,
data: CreateCommentDto
): Promise<Comment> {
const sanitizedContent = this.sanitizeMarkdown(data.content);
const comment = await this.prisma.comment.create({
data: {
content: sanitizedContent,
userId,
mangaId,
},
include: { user: true },
});
return this.mapComment(comment);
}
async deleteComment(commentId: string): Promise<void> {
await this.prisma.comment.delete({
where: { id: commentId },
+3 -1
View File
@@ -7,4 +7,6 @@
export { AuthService } from "./auth.service";
export { GameService } from "./game.service";
export { BookService } from "./book.service";
export { MusicService } from "./music.service";
export { MusicService } from "./music.service";
export { ShowService } from "./show.service";
export { MangaService } from "./manga.service";
+91
View File
@@ -0,0 +1,91 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Manga, MangaStatus, CreateMangaDto, UpdateMangaDto } from "@library/shared-types";
import { prisma } from "../lib/prisma";
export class MangaService {
private prisma = prisma;
constructor() {}
async getAllManga(): Promise<Manga[]> {
const manga = await this.prisma.manga.findMany({
orderBy: { updatedAt: "desc" },
});
return manga.map((m) => ({
...m,
status: m.status as unknown as MangaStatus,
dateAdded: m.dateAdded,
dateCompleted: m.dateCompleted || undefined,
createdAt: m.createdAt,
updatedAt: m.updatedAt,
}));
}
async getMangaById(id: string): Promise<Manga | null> {
const manga = await this.prisma.manga.findUnique({
where: { id },
});
if (!manga) return null;
return {
...manga,
status: manga.status as unknown as MangaStatus,
dateAdded: manga.dateAdded,
dateCompleted: manga.dateCompleted || undefined,
createdAt: manga.createdAt,
updatedAt: manga.updatedAt,
};
}
async createManga(data: CreateMangaDto): Promise<Manga> {
const manga = await this.prisma.manga.create({
data: {
...data,
status: data.status.toUpperCase() as any,
},
});
return {
...manga,
status: manga.status as unknown as MangaStatus,
dateAdded: manga.dateAdded,
dateCompleted: manga.dateCompleted || undefined,
createdAt: manga.createdAt,
updatedAt: manga.updatedAt,
};
}
async updateManga(id: string, data: UpdateMangaDto): Promise<Manga> {
const updateData = { ...data };
if (updateData.status) {
updateData.status = updateData.status.toUpperCase() as any;
}
const manga = await this.prisma.manga.update({
where: { id },
data: updateData,
});
return {
...manga,
status: manga.status as unknown as MangaStatus,
dateAdded: manga.dateAdded,
dateCompleted: manga.dateCompleted || undefined,
createdAt: manga.createdAt,
updatedAt: manga.updatedAt,
};
}
async deleteManga(id: string): Promise<void> {
await this.prisma.manga.delete({
where: { id },
});
}
}
+99
View File
@@ -0,0 +1,99 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto } from "@library/shared-types";
import { prisma } from "../lib/prisma";
export class ShowService {
private prisma = prisma;
constructor() {}
async getAllShows(): Promise<Show[]> {
const shows = await this.prisma.show.findMany({
orderBy: { updatedAt: "desc" },
});
return shows.map((show) => ({
...show,
type: show.type as unknown as ShowType,
status: show.status as unknown as ShowStatus,
dateAdded: show.dateAdded,
dateCompleted: show.dateCompleted || undefined,
createdAt: show.createdAt,
updatedAt: show.updatedAt,
}));
}
async getShowById(id: string): Promise<Show | null> {
const show = await this.prisma.show.findUnique({
where: { id },
});
if (!show) return null;
return {
...show,
type: show.type as unknown as ShowType,
status: show.status as unknown as ShowStatus,
dateAdded: show.dateAdded,
dateCompleted: show.dateCompleted || undefined,
createdAt: show.createdAt,
updatedAt: show.updatedAt,
};
}
async createShow(data: CreateShowDto): Promise<Show> {
const show = await this.prisma.show.create({
data: {
...data,
type: data.type.toUpperCase() as any,
status: data.status.toUpperCase() as any,
},
});
return {
...show,
type: show.type as unknown as ShowType,
status: show.status as unknown as ShowStatus,
dateAdded: show.dateAdded,
dateCompleted: show.dateCompleted || undefined,
createdAt: show.createdAt,
updatedAt: show.updatedAt,
};
}
async updateShow(id: string, data: UpdateShowDto): Promise<Show> {
const updateData = { ...data };
if (updateData.type) {
updateData.type = updateData.type.toUpperCase() as any;
}
if (updateData.status) {
updateData.status = updateData.status.toUpperCase() as any;
}
const show = await this.prisma.show.update({
where: { id },
data: updateData,
});
return {
...show,
type: show.type as unknown as ShowType,
status: show.status as unknown as ShowStatus,
dateAdded: show.dateAdded,
dateCompleted: show.dateCompleted || undefined,
createdAt: show.createdAt,
updatedAt: show.updatedAt,
};
}
async deleteShow(id: string): Promise<void> {
await this.prisma.show.delete({
where: { id },
});
}
}