Senin, 26 May 2025 :

Yang Sudah Di Kerjakan
* Tampilan UI Admin di menu ekonomi
* API Create, edit dan delete berita

Yang Akan Dikerjakan:
* API ProfilePPID
* Tampilan UI Admin Di Menu Inovasi
This commit is contained in:
2025-05-26 17:15:07 +08:00
parent 02738104b5
commit 3654629bde
9 changed files with 563 additions and 65 deletions

View File

@@ -0,0 +1,65 @@
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,
kategoriBerita: true,
},
});
if (!data) {
return Response.json({
success: false,
message: "Berita tidak ditemukan",
}, { status: 404 });
}
// Ensure we're returning a proper Response object
return new Response(JSON.stringify({
success: true,
message: "Success fetch berita by ID",
data,
}), {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
} catch (e) {
console.error("Find by ID error:", e);
return new Response(JSON.stringify({
success: false,
message: "Gagal mengambil berita: " + (e instanceof Error ? e.message : 'Unknown error'),
}), {
status: 500,
headers: {
'Content-Type': 'application/json',
},
});
}
}