Mobile API
Forum add: - mobile/forum/[id]/comment - mobile/forum/[id]/report-comment - mobile/forum/[id]/report-commentar - mobile/forum/[id]/report-postin - mobile/master/forum-report Fix: - mobile/forum/[id]/route - mobile/forum/route ### No isssue
This commit is contained in:
149
src/app/api/mobile/forum/[id]/comment/route.ts
Normal file
149
src/app/api/mobile/forum/[id]/comment/route.ts
Normal file
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user