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 { 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;