media-detail #31
@ -1,19 +1,16 @@
|
|||||||
import { Context } from "elysia";
|
import { Context, Static } from "elysia";
|
||||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||||
import { getAllMediaService } from "../services/http/getAllMedia.service";
|
import { getAllMediaService } from "../services/http/getAllMedia.service";
|
||||||
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
||||||
|
import { getAllMediaSchema } from "../schemas/getAllMedia.schema";
|
||||||
|
|
||||||
export const getAllMediaController = async (
|
export const getAllMediaController = async (ctx: {
|
||||||
ctx: Context & { query: { page: string } },
|
set: Context["set"];
|
||||||
) => {
|
query: Static<typeof getAllMediaSchema.query>;
|
||||||
|
}) => {
|
||||||
try {
|
try {
|
||||||
const mediaData = await getAllMediaService(ctx.query.page);
|
const mediaData = await getAllMediaService(ctx.query.page);
|
||||||
return returnReadResponse(
|
return returnReadResponse(ctx.set, 200, "Media fetched successfully", mediaData);
|
||||||
ctx.set,
|
|
||||||
200,
|
|
||||||
"Media fetched successfully",
|
|
||||||
mediaData,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return mainErrorHandler(ctx.set, error);
|
return mainErrorHandler(ctx.set, error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,8 @@ import Elysia from "elysia";
|
|||||||
import { getAllMediaController } from "./controllers/getAllMedia.controller";
|
import { getAllMediaController } from "./controllers/getAllMedia.controller";
|
||||||
import { getMediaBySlugController } from "./controllers/getMediaBySlug.controller";
|
import { getMediaBySlugController } from "./controllers/getMediaBySlug.controller";
|
||||||
import { getMediaBySlugSchema } from "./schemas/getMediaBySlug.schema";
|
import { getMediaBySlugSchema } from "./schemas/getMediaBySlug.schema";
|
||||||
|
import { getAllMediaSchema } from "./schemas/getAllMedia.schema";
|
||||||
|
|
||||||
export const mediaModule = new Elysia({ prefix: "/media" })
|
export const mediaModule = new Elysia({ prefix: "/media", tags: ["Media"] })
|
||||||
.get("/", getAllMediaController)
|
.get("/", getAllMediaController, getAllMediaSchema)
|
||||||
.get("/:slug", getMediaBySlugController, getMediaBySlugSchema);
|
.get("/:slug", getMediaBySlugController, getMediaBySlugSchema);
|
||||||
|
|||||||
58
src/modules/media/schemas/getAllMedia.schema.ts
Normal file
58
src/modules/media/schemas/getAllMedia.schema.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import { t } from "elysia";
|
||||||
|
import { AppRouteSchema } from "../../../helpers/types/AppRouteSchema";
|
||||||
|
|
||||||
|
export const getAllMediaSchema = {
|
||||||
|
query: t.Object({
|
||||||
|
page: t.String({ description: "The page number for pagination", default: "1" }),
|
||||||
|
}),
|
||||||
|
detail: {
|
||||||
|
summary: "Fetch all media items with pagination",
|
||||||
|
description:
|
||||||
|
"Fetch a paginated list of all media items. The 'page' query parameter can be used to specify the page number for pagination.",
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: "Media items fetched successfully",
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
success: { type: "boolean", example: true },
|
||||||
|
status: { type: "number", example: 200 },
|
||||||
|
message: { type: "string", example: "Media fetched successfully" },
|
||||||
|
data: {
|
||||||
|
type: "array",
|
||||||
|
items: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
status: { type: "string", example: "Finished Airing" },
|
||||||
|
id: { type: "string", example: "12345" },
|
||||||
|
title: { type: "string", example: "Example Media Title" },
|
||||||
|
slug: { type: "string", example: "example-media-title" },
|
||||||
|
malId: { type: "number", example: 67890 },
|
||||||
|
pictureMedium: { type: "string", example: "https://example.com/medium.jpg" },
|
||||||
|
pictureLarge: { type: "string", example: "https://example.com/large.jpg" },
|
||||||
|
country: { type: "string", example: "JP" },
|
||||||
|
score: { type: "number", example: 8.5 },
|
||||||
|
startAiring: { type: "string", format: "date-time", example: "2023-01-01T00:00:00Z" },
|
||||||
|
endAiring: { type: "string", format: "date-time", example: "2023-12-31T23:59:59Z" },
|
||||||
|
synopsis: { type: "string", example: "This is an example synopsis of the media item." },
|
||||||
|
ageRating: { type: "string", example: "PG-13" },
|
||||||
|
mediaType: { type: "string", example: "Anime" },
|
||||||
|
source: { type: "string", example: "Manga" },
|
||||||
|
onDraft: { type: "boolean", example: false },
|
||||||
|
uploadedBy: { type: "string", example: "admin" },
|
||||||
|
deletedAt: { type: "string", format: "date-time", nullable: true, example: null },
|
||||||
|
createdAt: { type: "string", format: "date-time", example: "2023-01-01T00:00:00Z" },
|
||||||
|
updatedAt: { type: "string", format: "date-time", example: "2023-01-02T00:00:00Z" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} satisfies AppRouteSchema;
|
||||||
Reference in New Issue
Block a user