Compare commits

...

2 Commits

Author SHA1 Message Date
d6fa5efaff Merge pull request ' feat: add get all media endpoint' (#8) from feat/get-all-media into main
All checks were successful
Sync to GitHub / sync (push) Successful in 8s
Reviewed-on: #8
2026-02-03 15:26:14 +07:00
4b9ade64c3 feat: add get all media endpoint
All checks were successful
Integration Tests / integration-tests (pull_request) Successful in 56s
2026-02-03 15:25:15 +07:00
4 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,20 @@
import { Context } from "elysia";
import { mainErrorHandler } from "../../../helpers/error/handler";
import { getAllMediaService } from "../services/http/getAllMedia.service";
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
export const getAllMediaController = async (
ctx: Context & { query: { page: string } },
) => {
try {
const mediaData = await getAllMediaService(ctx.query.page);
return returnReadResponse(
ctx.set,
200,
"Media fetched successfully",
mediaData,
);
} catch (error) {
return mainErrorHandler(ctx.set, error);
}
};

View File

@ -1,6 +1,7 @@
import Elysia from "elysia"; import Elysia from "elysia";
import { getAllMediaController } from "./controllers/getAllMedia.controller";
export const mediaModule = new Elysia({ prefix: "/media" }).get( export const mediaModule = new Elysia({ prefix: "/media" }).get(
"/", "/",
() => "Media Module", getAllMediaController,
); );

View File

@ -0,0 +1,17 @@
import { AppError } from "../../../../helpers/error/instances/app";
import { mediaModel } from "../../model";
export const getAllMediaRepository = async (page: number) => {
try {
const limit = 10;
return await mediaModel.findMany({
take: limit,
skip: (page - 1) * limit,
where: {
deletedAt: null,
},
});
} catch (error) {
throw new AppError(500, "Failed to get all media from repository", error);
}
};

View File

@ -0,0 +1,15 @@
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
import { getAllMediaRepository } from "../../repositories/GET/getAllMedia.repository";
export const getAllMediaService = async (pagination: string) => {
try {
const page =
/^\d+$/.test(pagination) && Number(pagination) > 0
? Number(pagination)
: 1;
return getAllMediaRepository(page);
} catch (error) {
ErrorForwarder(error);
}
};