diff --git a/src/app/api/admin/forum/[id]/route.ts b/src/app/api/admin/forum/[id]/route.ts
new file mode 100644
index 00000000..2c1323fa
--- /dev/null
+++ b/src/app/api/admin/forum/[id]/route.ts
@@ -0,0 +1,65 @@
+import { NextResponse } from "next/server";
+import prisma from "@/lib/prisma";
+import _ from "lodash";
+
+export async function GET(
+ request: Request,
+ { params }: { params: { id: string } }
+) {
+ try {
+ const { id } = params;
+ const data = await prisma.forum_Posting.findFirst({
+ where: {
+ id: id,
+ },
+ select: {
+ id: true,
+ diskusi: true,
+ ForumMaster_StatusPosting: {
+ select: {
+ id: true,
+ status: true,
+ },
+ },
+ authorId: true,
+ Author: {
+ select: {
+ id: true,
+ username: true,
+ Profile: {
+ select: {
+ name: true,
+ },
+ },
+ },
+ },
+ Forum_Komentar: {
+ where: {
+ isActive: true,
+ },
+ },
+ },
+ });
+
+ const result = {
+ ..._.omit(data, "Forum_Komentar"),
+ Forum_Komentar: data?.Forum_Komentar.length,
+ };
+
+ return NextResponse.json({
+ success: true,
+ message: "Success get data",
+ data: result,
+ });
+ } catch (error) {
+ console.error("Error get data forum", error);
+ return NextResponse.json(
+ {
+ success: false,
+ message: "Error get data forum",
+ reason: (error as Error).message,
+ },
+ { status: 500 }
+ );
+ }
+}
diff --git a/src/app/dev/admin/forum/detail/[id]/page.tsx b/src/app/dev/admin/forum/detail/[id]/page.tsx
index 8400a30e..3466102b 100644
--- a/src/app/dev/admin/forum/detail/[id]/page.tsx
+++ b/src/app/dev/admin/forum/detail/[id]/page.tsx
@@ -1,23 +1,9 @@
import { AdminForum_LihatSemuaKomentar } from "@/app_modules/admin/forum";
-import { adminForum_getOnePostingById } from "@/app_modules/admin/forum/fun/get/get_one_posting_by_id";
-
-export default async function Page({ params }: { params: { id: string } }) {
- let postingId = params.id;
-
- // const listKomentar = await adminForum_getListKomentarById({
- // postingId: postingId,
- // page: 1,
- // });
- const dataPosting = await adminForum_getOnePostingById(postingId);
- // const countKomentar = await adminForum_countKomentarByPostingId({
- // postingId: postingId,
- // });
+export default async function Page() {
return (
<>
-
+
>
);
}
diff --git a/src/app_modules/admin/forum/detail/detail_posting.tsx b/src/app_modules/admin/forum/detail/detail_posting.tsx
index 8214f56d..ee6a6ae6 100644
--- a/src/app_modules/admin/forum/detail/detail_posting.tsx
+++ b/src/app_modules/admin/forum/detail/detail_posting.tsx
@@ -28,7 +28,7 @@ import { useDisclosure, useShallowEffect } from "@mantine/hooks";
import { IconFlag3, IconSearch, IconTrash } from "@tabler/icons-react";
import moment from "moment";
import "moment/locale/id";
-import { useRouter } from "next/navigation";
+import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
import { Admin_ComponentModal } from "../../_admin_global/_component/comp_admin_modal";
@@ -36,30 +36,63 @@ import Admin_ComponentBackButton from "../../_admin_global/back_button";
import { Admin_V3_ComponentPaginationBreakpoint } from "../../_components_v3/comp_pagination_breakpoint";
import ComponentAdminForum_ViewOneDetailPosting from "../component/detail_one_posting";
import { adminForum_funDeleteKomentarById } from "../fun/delete/fun_delete_komentar_by_id";
-import { apiAdminGetKomentarForumById } from "../lib/api_fetch_admin_forum";
+import {
+ apiAdminGetKomentarForumById,
+ apiAdminGetPostingForumById,
+} from "../lib/api_fetch_admin_forum";
import { AdminForum_CompTableSetHtmlStiker } from "../component/comp_table_set_html_stiker";
import { Admin_V3_ComponentBreakpoint } from "../../_components_v3/comp_simple_grid_breakpoint";
-export default function AdminForum_DetailPosting({
- dataPosting,
-}: {
- dataPosting: MODEL_FORUM_POSTING;
-}) {
+export default function AdminForum_DetailPosting() {
+ const { id } = useParams();
+ const [data, setData] = useState(null);
+
+ useShallowEffect(() => {
+ onLoadData();
+ }, []);
+
+ async function onLoadData() {
+ try {
+ const response = await apiAdminGetPostingForumById({ id: id as string });
+ if (response && response.success) {
+ setData(response.data);
+ }
+ } catch (error) {
+ console.error("Invalid data format received:", error);
+ setData(null);
+ }
+ }
+
return (
<>
-
-
-
-
+ {!data ? (
+
+ ) : (
+ <>
+
+
+
+
+ >
+ )}
>
);
}
-function TableKomentar({ postingId, totalComments }: { postingId: string, totalComments: number }) {
+function TableKomentar({
+ postingId,
+ totalComments,
+}: {
+ postingId: string;
+ totalComments: number;
+}) {
const router = useRouter();
const [data, setData] = useState(null);
const [nPage, setNPage] = useState(1);
diff --git a/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts b/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts
index 2a549e27..e104a1ce 100644
--- a/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts
+++ b/src/app_modules/admin/forum/lib/api_fetch_admin_forum.ts
@@ -7,6 +7,7 @@ export {
apiGetAdminForumPublish,
apiGetAdminHasilReportPosting,
apiAdminGetKomentarForumById,
+ apiAdminGetPostingForumById,
};
const apiGetAdminForumPublishCountDasboard = async () => {
@@ -212,3 +213,46 @@ const apiAdminGetKomentarForumById = async ({
throw error; // Re-throw the error to handle it in the calling function
}
};
+
+const apiAdminGetPostingForumById = async ({
+ id,
+}: {
+ id: string;
+}) => {
+ try {
+ const { token } = await fetch("/api/get-cookie").then((res) => res.json());
+ if (!token) {
+ console.error("No token found");
+ return null;
+ }
+
+ const response = await fetch(`/api/admin/forum/${id}`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ Authorization: `Bearer ${token}`,
+ },
+ });
+
+ // Check if the response is OK
+ if (!response.ok) {
+ const errorData = await response.json().catch(() => null);
+ console.error(
+ "Failed to get admin posting forum",
+ response.statusText,
+ errorData
+ );
+ throw new Error(
+ errorData?.message || "Failed to get admin posting forum"
+ );
+ }
+
+ // Return the JSON response
+ const resulst = await response.json();
+ return resulst;
+ } catch (error) {
+ console.error("Error get admin posting forum", error);
+ throw error; // Re-throw the error to handle it in the calling function
+ }
+};