diff --git a/src/app/api/mobile/forum/[id]/comment/route.ts b/src/app/api/mobile/forum/[id]/comment/route.ts new file mode 100644 index 00000000..6c2aa898 --- /dev/null +++ b/src/app/api/mobile/forum/[id]/comment/route.ts @@ -0,0 +1,149 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { POST, GET, DELETE }; + +async function POST(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + console.log("[ID COMMENT]", id); + console.log("[DATA COMMENT]", data); + + try { + const createComment = await prisma.forum_Komentar.create({ + data: { + forum_PostingId: id, + komentar: data.comment, + authorId: data.authorId, + }, + select: { + id: true, + isActive: true, + komentar: true, + createdAt: true, + authorId: true, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + imageId: true, + }, + }, + }, + }, + }, + }); + + if (!createComment) { + return NextResponse.json({ + status: 400, + success: false, + message: "Gagal update data", + }); + } + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil update data", + data: createComment, + }); + + } catch (error) { + console.log("[ERROR COMMENT]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Gagal update data", + reason: (error as Error).message || error, + }); + } +} + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + + try { + const data = await prisma.forum_Komentar.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + forum_PostingId: id, + isActive: true, + }, + select: { + id: true, + isActive: true, + komentar: true, + createdAt: true, + authorId: true, + Author: { + select: { + id: true, + username: true, + Profile: { + select: { + id: true, + imageId: true, + }, + }, + }, + }, + }, + }); + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil mendapatkan data", + data: data, + }); + } catch (error) { + console.log("[ERROR COMMENT]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Gagal mendapatkan data", + reason: (error as Error).message || error, + }); + } +} + +async function DELETE(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + + try { + const deleteComment = await prisma.forum_Komentar.delete({ + where: { + id: id, + }, + }); + + if (!deleteComment) { + return NextResponse.json({ + status: 400, + success: false, + message: "Gagal hapus komentar", + }); + } + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil hapus komentar", + }); + } catch (error) { + console.log("[ERROR COMMENT]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Gagal hapus komentar", + reason: (error as Error).message || error, + }); + } +} \ No newline at end of file diff --git a/src/app/api/mobile/forum/[id]/report-comment/route.ts b/src/app/api/mobile/forum/[id]/report-comment/route.ts new file mode 100644 index 00000000..cce2680e --- /dev/null +++ b/src/app/api/mobile/forum/[id]/report-comment/route.ts @@ -0,0 +1,61 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { POST }; + +async function POST(request: Request, { params }: { params: { id: string } }) { + let fixData; + const { id } = params; + const { data } = await request.json(); + console.log("[DATA]", data); + console.log("[ID]", id); + + try { + fixData = await prisma.forum_ReportKomentar.create({ + data: { + forum_KomentarId: id, + userId: data.authorId, + forumMaster_KategoriReportId: data.categoryId as any, + }, + }); + // if (data.categoryId) { + // fixData = await prisma.forum_ReportKomentar.create({ + // data: { + // forum_KomentarId: id, + // userId: data.authorId, + // forumMaster_KategoriReportId: data.categoryId as any, + // }, + // }); + // } else { + // fixData = await prisma.forum_ReportKomentar.create({ + // data: { + // forum_KomentarId: id, + // userId: data.authorId, + // deskripsi: data.description, + // }, + // }); + // } + + // if (!fixData) { + // return NextResponse.json({ + // status: 400, + // success: false, + // message: "Gagal membuat report komentar", + // }); + // } + + return NextResponse.json({ + status: 201, + success: true, + message: "Berhasil membuat report komentar", + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Gagal membuat report komentar", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/forum/[id]/report-commentar/route.ts b/src/app/api/mobile/forum/[id]/report-commentar/route.ts new file mode 100644 index 00000000..449fc572 --- /dev/null +++ b/src/app/api/mobile/forum/[id]/report-commentar/route.ts @@ -0,0 +1,54 @@ +import { prisma } from "@/lib"; +import { NextResponse } from "next/server"; + +export { POST }; + +async function POST(request: Request, { params }: { params: { id: string } }) { + let fixData; + const { id } = params; + const { data } = await request.json(); + console.log("[DATA]", data); + console.log("[ID]", id); + + try { + if (data.categoryId) { + fixData = await prisma.forum_ReportKomentar.create({ + data: { + forum_KomentarId: id, + userId: data.authorId, + forumMaster_KategoriReportId: data.categoryId as any, + }, + }); + } else { + fixData = await prisma.forum_ReportKomentar.create({ + data: { + forum_KomentarId: id, + userId: data.authorId, + deskripsi: data.description, + }, + }); + } + + if (!fixData) { + return NextResponse.json({ + status: 400, + success: false, + message: "Gagal membuat report komentar", + }); + } + + return NextResponse.json({ + status: 201, + success: true, + message: "Berhasil membuat report komentar", + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Gagal membuat report komentar", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/forum/[id]/report-posting/route.ts b/src/app/api/mobile/forum/[id]/report-posting/route.ts new file mode 100644 index 00000000..16c9597d --- /dev/null +++ b/src/app/api/mobile/forum/[id]/report-posting/route.ts @@ -0,0 +1,54 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { POST }; + +async function POST(request: Request, { params }: { params: { id: string } }) { + let fixData; + const { id } = params; + const { data } = await request.json(); + console.log("[DATA]", data); + console.log("[ID]", id); + + try { + if (data.categoryId) { + fixData = await prisma.forum_ReportPosting.create({ + data: { + forum_PostingId: id, + userId: data.authorId, + forumMaster_KategoriReportId: data.categoryId, + }, + }); + } else { + fixData = await prisma.forum_ReportPosting.create({ + data: { + forum_PostingId: id, + userId: data.authorId, + deskripsi: data.description, + }, + }); + } + + if (!fixData) { + return NextResponse.json({ + status: 400, + success: false, + message: "Gagal membuat report posting", + }); + } + + return NextResponse.json({ + status: 201, + success: true, + message: "Berhasil membuat report posting", + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Gagal membuat report posting", + reason: (error as Error).message, + }); + } +} diff --git a/src/app/api/mobile/forum/[id]/route.ts b/src/app/api/mobile/forum/[id]/route.ts index dfb1f2f2..b700f4c9 100644 --- a/src/app/api/mobile/forum/[id]/route.ts +++ b/src/app/api/mobile/forum/[id]/route.ts @@ -1,11 +1,188 @@ -export { GET }; +import prisma from "@/lib/prisma"; +import _ from "lodash"; +import { NextResponse } from "next/server"; -async function GET(request: Request) { - try { - - - } catch (error) { - +export { GET, PUT, DELETE, POST }; + +async function GET(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + + try { + 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, + }, + }, + Forum_Komentar: { + where: { + isActive: true, + }, + }, + ForumMaster_StatusPosting: true, + forumMaster_StatusPostingId: true, + }, + }); + + const count = data?.Forum_Komentar?.length ?? 0; + + const newData = { + ..._.omit(data, ["Forum_Komentar"]), + count, + }; + + return NextResponse.json({ + success: true, + message: "Berhasil mendapatkan data", + data: newData, + }); + } catch (error) { + console.log("[ERROR FORUM]", error); + return NextResponse.json({ + success: false, + message: "Gagal mendapatkan data", + reason: (error as Error).message || error, + }); + } +} + +async function PUT(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + console.log("[DATA]", data); + + try { + const update = await prisma.forum_Posting.update({ + where: { + id: id, + }, + data: { + diskusi: data, + }, + }); + + if (!update) { + return NextResponse.json({ + status: 400, + success: false, + message: "Gagal update data", + }); } + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil update data", + }); + } catch (error) { + console.log("[ERROR FORUM]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Gagal update data", + reason: (error as Error).message || error, + }); + } +} + +async function DELETE( + request: Request, + { params }: { params: { id: string } } +) { + const { id } = params; + + try { + const dlt = await prisma.forum_Posting.delete({ + where: { + id: id, + }, + }); + + if (!dlt) { + return NextResponse.json({ + status: 400, + success: false, + message: "Gagal hapus data", + }); + } + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil hapus data", + }); + } catch (error) { + console.log("[ERROR FORUM]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Error hapus data", + reason: (error as Error).message || error, + }); + } +} + +// Update Status +async function POST(request: Request, { params }: { params: { id: string } }) { + const { id } = params; + const { data } = await request.json(); + + console.log("[DATA]", data); + + const status = await prisma.forumMaster_StatusPosting.findFirst({ + where: { + status: data, + }, + }); + + console.log("[STATUS]", status); + + try { + const update = await prisma.forum_Posting.update({ + where: { + id: id, + }, + data: { + forumMaster_StatusPostingId: status?.id, + }, + }); + + if (!update) { + return NextResponse.json({ + status: 400, + success: false, + message: "Gagal update data", + }); + } + + const fixData = status?.status; + + return NextResponse.json({ + status: 200, + success: true, + message: "Berhasil update data", + data: fixData, + }); -} \ No newline at end of file + } catch (error) { + console.log("[ERROR FORUM]", error); + return NextResponse.json({ + status: 500, + success: false, + message: "Gagal update data", + reason: (error as Error).message || error, + }); + } +} diff --git a/src/app/api/mobile/forum/route.ts b/src/app/api/mobile/forum/route.ts index cec54a6a..e27fef7a 100644 --- a/src/app/api/mobile/forum/route.ts +++ b/src/app/api/mobile/forum/route.ts @@ -1,6 +1,8 @@ +import _ from "lodash"; import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; -export { POST , GET}; +export { POST, GET }; async function POST(request: Request) { const { data } = await request.json(); @@ -31,60 +33,127 @@ async function POST(request: Request) { } async function GET(request: Request) { + let fixData; const { searchParams } = new URL(request.url); + const authorId = searchParams.get("authorId"); const search = searchParams.get("search"); - + try { - const data = await prisma.forum_Posting.findMany({ - orderBy: { - createdAt: "desc", - }, - where: { - isActive: true, - diskusi: { - mode: "insensitive", - contains: search || "", - }, - }, - 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, + if (authorId) { + const data = await prisma.forum_Posting.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + authorId: authorId, + }, + 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, }, - Forum_Komentar: { - where: { - isActive: true, + }); + + const newData = data.map((item) => { + const count = item.Forum_Komentar?.length ?? 0; + return { + ..._.omit(item, ["Forum_Komentar"]), + count, + }; + }); + + fixData = newData; + } else { + const data = await prisma.forum_Posting.findMany({ + orderBy: { + createdAt: "desc", + }, + where: { + isActive: true, + diskusi: { + mode: "insensitive", + contains: search || "", }, }, - ForumMaster_StatusPosting: { - select: { - id: true, - status: 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, }, - forumMaster_StatusPostingId: true, - }, - }); + }); + + const newData = data.map((item) => { + const count = item.Forum_Komentar?.length ?? 0; + return { + ..._.omit(item, ["Forum_Komentar"]), + count, + }; + }); + + fixData = newData; + } return NextResponse.json({ success: true, message: "Berhasil mendapatkan data", - data: data, + data: fixData, }); + } catch (error) { console.log("[ERROR]", error); return NextResponse.json({ diff --git a/src/app/api/mobile/master/forum-report/route.ts b/src/app/api/mobile/master/forum-report/route.ts new file mode 100644 index 00000000..256d1ced --- /dev/null +++ b/src/app/api/mobile/master/forum-report/route.ts @@ -0,0 +1,28 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export async function GET(request: Request) { + try { + const data = await prisma.forumMaster_KategoriReport.findMany({ + orderBy: { + createdAt: "asc", + }, + where: { + isActive: true, + }, + }); + + return NextResponse.json({ + success: true, + message: "Berhasil mendapatkan data", + data: data, + }); + } catch (error) { + console.log("[ERROR]", error); + return NextResponse.json({ + success: false, + message: "Gagal mendapatkan data", + reason: (error as Error).message, + }); + } +} diff --git a/src/app_modules/forum/component/detail_component/detail_view.tsx b/src/app_modules/forum/component/detail_component/detail_view.tsx index 10352d2a..fb55bfde 100644 --- a/src/app_modules/forum/component/detail_component/detail_view.tsx +++ b/src/app_modules/forum/component/detail_component/detail_view.tsx @@ -9,7 +9,7 @@ import { useShallowEffect } from "@mantine/hooks"; import { Comp_V3_SetInnerHTMLWithStiker } from "@/app_modules/_global/component/new/comp_V3_set_html_with_stiker"; import { MainColor } from "@/app_modules/_global/color"; -export default function ComponentForum_DetailForumView({ +export default function ComponentForum_DetailForumView({ data, totalKomentar, userLoginId,