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;