- Update schema: add images relation list and linkVideo field - API: support multiple image upload and YouTube link in create/update - Admin create page: add gallery upload (max 10) and YouTube embed preview - Admin edit page: manage existing/new gallery images and YouTube link - Admin detail page: display gallery grid and YouTube video embed - Public detail page: show gallery images and YouTube video with responsive layout - State: add imageIds[] and linkVideo fields with proper type handling - Music player: fix seek functionality and ESLint warnings Breaking changes: - Prisma schema updated - requires migration - API create/update endpoints now expect imageIds array and linkVideo string Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import prisma from "@/lib/prisma";
|
|
|
|
export default async function handler(
|
|
request: Request
|
|
) {
|
|
// Extract the ID from the URL path
|
|
const url = new URL(request.url);
|
|
const pathSegments = url.pathname.split('/');
|
|
const id = pathSegments[pathSegments.length - 1];
|
|
|
|
if (!id) {
|
|
return Response.json({
|
|
success: false,
|
|
message: "ID tidak boleh kosong",
|
|
}, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
// Validate that the ID is a valid UUID or whatever format you're using
|
|
if (typeof id !== 'string') {
|
|
return Response.json({
|
|
success: false,
|
|
message: "ID tidak valid",
|
|
}, { status: 400 });
|
|
}
|
|
|
|
const data = await prisma.berita.findUnique({
|
|
where: { id },
|
|
include: {
|
|
image: true,
|
|
images: true,
|
|
kategoriBerita: true,
|
|
},
|
|
});
|
|
|
|
if (!data) {
|
|
return Response.json({
|
|
success: false,
|
|
message: "Berita tidak ditemukan",
|
|
}, { status: 404 });
|
|
}
|
|
|
|
// Ensure we're returning a proper Response object
|
|
return Response.json({
|
|
success: true,
|
|
message: "Success fetch berita by ID",
|
|
data,
|
|
}, {
|
|
status: 200,
|
|
});
|
|
} catch (e) {
|
|
console.error("Find by ID error:", e);
|
|
return Response.json({
|
|
success: false,
|
|
message: "Gagal mengambil berita: " + (e instanceof Error ? e.message : 'Unknown error'),
|
|
}, {
|
|
status: 500,
|
|
});
|
|
}
|
|
} |