Merge pull request #316 from bipproduction/bagas/17-feb-25

fix api forum
This commit is contained in:
Bagasbanuna02
2025-02-17 22:25:30 +08:00
committed by GitHub
23 changed files with 793 additions and 408 deletions

View File

@@ -0,0 +1,54 @@
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export { GET };
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
const { id } = params;
const data = await prisma.forum_Posting.findUnique({
where: {
id: id,
},
select: {
id: true,
diskusi: true,
isActive: true,
createdAt: true,
authorId: true,
Author: {
select: {
id: true,
username: true,
Profile: true,
},
},
_count: {
select: {
Forum_Komentar: true,
},
},
ForumMaster_StatusPosting: true,
forumMaster_StatusPostingId: true,
},
});
return NextResponse.json({
success: true,
message: "Success get data",
data: data,
});
} catch (error) {
backendLogger.error("Error get data forum", error);
return NextResponse.json(
{
success: false,
message: "Error get data forum",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,122 @@
import { NextResponse } from "next/server";
export { GET };
async function GET(request: Request, { params }: { params: { id: string } }) {
try {
let fixData;
const { id } = params;
const { searchParams } = new URL(request.url);
const page = searchParams.get("page");
const takeData = 5;
const skipData = Number(page) * takeData - takeData;
console.log("id", id)
console.log("page >", page)
if (!page) {
fixData = await prisma.forum_Posting.findMany({
orderBy: {
createdAt: "desc",
},
where: {
authorId: id,
isActive: true,
},
select: {
id: true,
diskusi: true,
createdAt: true,
isActive: true,
authorId: true,
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
Forum_Komentar: {
where: {
isActive: true,
},
},
ForumMaster_StatusPosting: {
select: {
id: true,
status: true,
},
},
forumMaster_StatusPostingId: true,
},
});
} else {
fixData = await prisma.forum_Posting.findMany({
take: takeData,
skip: skipData,
orderBy: {
createdAt: "desc",
},
where: {
authorId: id,
isActive: true,
},
select: {
id: true,
diskusi: true,
createdAt: true,
isActive: true,
authorId: true,
Author: {
select: {
id: true,
username: true,
Profile: {
select: {
id: true,
name: true,
imageId: true,
},
},
},
},
Forum_Komentar: {
where: {
isActive: true,
},
},
ForumMaster_StatusPosting: {
select: {
id: true,
status: true,
},
},
forumMaster_StatusPostingId: true,
},
});
}
return NextResponse.json({
success: true,
message: "Berhasil mendapatkan data",
data: fixData,
});
} catch (error) {
return NextResponse.json(
{
success: false,
message: "Gagal mendapatkan data",
error: (error as Error).message,
},
{
status: 500,
}
);
}
}

View File

@@ -9,9 +9,10 @@ export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const page = searchParams.get("page");
const search = searchParams.get("search");
const takeData = 4
const takeData = 5;
const skipData = Number(page) * takeData - takeData;
if (!page) {
fixData = await prisma.forum_Posting.findMany({
orderBy: {

View File

@@ -1,13 +1,10 @@
import { Forum_EditPosting } from "@/app_modules/forum";
import { forum_getOnePostingById } from "@/app_modules/forum/fun/get/get_one_posting_by_id";
export default async function Page({ params }: { params: { id: string } }) {
let postingId = params.id;
const dataPosting = await forum_getOnePostingById(postingId)
export default async function Page() {
return (
<>
<Forum_EditPosting dataPosting={dataPosting as any} />
<Forum_EditPosting />
</>
);
}

View File

@@ -1,22 +1,14 @@
import { LayoutForum_Forumku } from "@/app_modules/forum";
import { user_getOneByUserId } from "@/app_modules/home/fun/get/get_one_user_by_id";
import React from "react";
export default async function Layout({
children,
params,
}: {
children: React.ReactNode;
params: { id: string };
}) {
const authorId = params.id;
const dataAuthor = await user_getOneByUserId(authorId);
return (
<>
<LayoutForum_Forumku username={dataAuthor?.username as any}>
{children}
</LayoutForum_Forumku>
<LayoutForum_Forumku>{children}</LayoutForum_Forumku>
</>
);
}

View File

@@ -34,8 +34,6 @@ export default async function Page({ params }: { params: { id: string } }) {
return (
<>
<Forum_Forumku
auhtorSelectedData={auhtorSelectedData as any}
dataPosting={dataPosting as any}
totalPosting={totalPosting}
userLoginId={userLoginId as any}
/>

View File

@@ -6,7 +6,7 @@ import {
UIGlobal_LayoutTamplate,
} from "@/app_modules/_global/ui";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { Button, Grid, Skeleton, Stack } from "@mantine/core";
import { Button, Center, Grid, Group, Skeleton, Stack } from "@mantine/core";
import Link from "next/link";
export default function Voting_ComponentSkeletonViewPuh() {
@@ -15,13 +15,34 @@ export default function Voting_ComponentSkeletonViewPuh() {
<UIGlobal_LayoutTamplate
header={<UIGlobal_LayoutHeaderTamplate title="Skeleton Maker" />}
>
<Stack spacing={"xl"} p={"sm"}>
<Stack>
<Center>
<CustomSkeleton height={100} width={100} circle />
</Center>
<Grid grow>
<Grid.Col span={6}>
<Stack spacing={"xs"}>
<CustomSkeleton height={20} width={"80%"} />
<CustomSkeleton height={20} width={"80%"} />
</Stack>
</Grid.Col>
<Grid.Col span={6}>
<Group position="right">
<CustomSkeleton height={50} width={"80%"} radius={"xl"} />
</Group>
</Grid.Col>
</Grid>
</Stack>
{/* <Stack spacing={"xl"} p={"sm"}>
{Array.from({ length: 4 }).map((_, i) => (
<CustomSkeleton key={i} height={50} width={"100%"} />
))}
<CustomSkeleton height={100} width={"100%"} />
<CustomSkeleton radius="xl" height={50} width={"100%"} />
</Stack>
</Stack> */}
</UIGlobal_LayoutTamplate>
</>
);