fix forum
deskripsi: - fix forumku , server action to API
This commit is contained in:
122
src/app/api/forum/forumku/[id]/route.ts
Normal file
122
src/app/api/forum/forumku/[id]/route.ts
Normal 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,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
|
||||
@@ -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>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user