👔 feat: implement database repository for get media by slug
All checks were successful
Integration Tests / integration-tests (pull_request) Successful in 1m51s

This commit is contained in:
2026-04-02 09:48:31 +07:00
parent 59228f7d1e
commit 72f8e9e4eb
3 changed files with 20 additions and 3 deletions

View File

@ -9,7 +9,7 @@ export const getMediaBySlugController = async (ctx: {
params: Static<typeof getMediaBySlugSchema.params>; params: Static<typeof getMediaBySlugSchema.params>;
}) => { }) => {
try { try {
const mediaData = getMediaBySlugService(ctx.params.slug); const mediaData = await getMediaBySlugService(ctx.params.slug);
return returnReadResponse(ctx.set, 200, "Media fetched successfully", mediaData); return returnReadResponse(ctx.set, 200, "Media fetched successfully", mediaData);
} catch (error) { } catch (error) {
return mainErrorHandler(ctx.set, error); return mainErrorHandler(ctx.set, error);

View File

@ -0,0 +1,12 @@
import { AppError } from "../../../../helpers/error/instances/app";
import { prisma } from "../../../../utils/databases/prisma/connection";
export const selectMediaBySlugRepository = async (slug: string) => {
try {
return await prisma.media.findUnique({
where: { slug },
});
} catch (error) {
throw new AppError(500, "Failed to fetch media by slug", error);
}
};

View File

@ -1,8 +1,13 @@
import { AppError } from "../../../../helpers/error/instances/app";
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder"; import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
import { selectMediaBySlugRepository } from "../../repositories/SELECT/selectMediaBySlug.repository";
export const getMediaBySlugService = (slug: string) => { export const getMediaBySlugService = async (slug: string) => {
try { try {
return `Mengambil media dengan slug '${slug}'`; const mediaData = await selectMediaBySlugRepository(slug);
if (!mediaData) throw new AppError(404, "Media not found with the provided slug.");
return mediaData;
} catch (error) { } catch (error) {
ErrorForwarder(error); ErrorForwarder(error);
} }