generated from nhcarrigan/template
feat: add manga and shows collections
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user