# Forum Created

## feat
- CRUD Forum
- CRD Koment
- Tampilan forum profile
### No issue
This commit is contained in:
2024-03-15 10:27:06 +08:00
parent 7baceafa80
commit a77d728a5f
40 changed files with 1999 additions and 512 deletions

View File

@@ -0,0 +1,15 @@
"use server";
import prisma from "@/app/lib/prisma";
import { revalidatePath } from "next/cache";
export async function forum_countOneTotalKomentarById(postingId: any) {
const data = await prisma.forum_Komentar.count({
where: {
forum_PostingId: postingId,
isActive: true,
},
});
return data
}

View File

@@ -0,0 +1,17 @@
"use server";
import prisma from "@/app/lib/prisma";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
export async function forum_countPostingByAuthorId(authorId: string) {
const data = await prisma.forum_Posting.count({
where: {
authorId: authorId,
isActive: true
},
});
return data
}

View File

@@ -0,0 +1,32 @@
"use server";
import prisma from "@/app/lib/prisma";
// PERCOBAAN
export async function forum_countTotalKomenById(postingId: any[]) {
// console.log(postingId)
const data = postingId.map(async (e) => {
const get = await prisma.forum_Komentar.count({
where: {
forum_PostingId: e,
isActive: true,
},
select: {
forum_PostingId: true,
},
});
console.log(get);
});
// const data = await prisma.forum_Komentar.count({
// where: {
// forum_PostingId: postingId,
// isActive: true,
// },
// });
// return data;
}

View File

@@ -0,0 +1,20 @@
"use server";
import prisma from "@/app/lib/prisma";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
import { revalidatePath } from "next/cache";
export async function forum_funCreate(value: string) {
const AuthorId = await User_getUserId();
const create = await prisma.forum_Posting.create({
data: {
diskusi: value,
authorId: AuthorId,
},
});
if (!create) return { status: 400, message: "Gagal menambahkan postingan" };
revalidatePath("/dev/forum/main");
return { status: 201, message: "Berhasil menambahkan postingan" };
}

View File

@@ -0,0 +1,24 @@
"use server";
import prisma from "@/app/lib/prisma";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
import { revalidatePath } from "next/cache";
export async function forum_funCreateKomentar(
postingId: string,
komentar: string
) {
const authorId = await User_getUserId();
const create = await prisma.forum_Komentar.create({
data: {
komentar: komentar,
forum_PostingId: postingId,
authorId: authorId,
},
});
if (!create) return { status: 400, message: "Gagal menambahkan komentar" };
revalidatePath("/dev/forum/detail");
return { status: 201, message: "Berhasil menambahkan komentar" };
}

View File

@@ -0,0 +1,19 @@
"use server";
import prisma from "@/app/lib/prisma";
import { revalidatePath } from "next/cache";
export async function forum_funDeleteKomentarById(komentarId: string) {
const del = await prisma.forum_Komentar.update({
where: {
id: komentarId,
},
data: {
isActive: false,
},
});
if (!del) return { status: 400, message: "Gagal Dihapus" };
revalidatePath("/dev/forum/detail");
return { status: 200, message: "Berhasil Dihapus" };
}

View File

@@ -0,0 +1,19 @@
"use server";
import prisma from "@/app/lib/prisma";
import { revalidatePath } from "next/cache";
export async function forum_funDeletePostingById(forumId: string) {
const del = await prisma.forum_Posting.update({
where: {
id: forumId,
},
data: {
isActive: false,
},
});
if (!del) return { status: 400, message: "Gagal dihapus" };
revalidatePath("/dev/forum/main");
return { status: 200, message: "Berhasil dihapus" };
}

View File

@@ -0,0 +1,22 @@
"use server";
import prisma from "@/app/lib/prisma";
import { revalidatePath } from "next/cache";
export async function forum_funEditPostingById(
postingId: string,
diskusi: string
) {
const updt = await prisma.forum_Posting.update({
where: {
id: postingId,
},
data: {
diskusi: diskusi,
},
});
if (!updt) return { status: 400, message: "Gagal update" };
revalidatePath("/dev/forum/main");
return { status: 200, message: "Berhasil update" };
}

View File

@@ -0,0 +1,35 @@
"use server";
import prisma from "@/app/lib/prisma";
export async function forum_getKomentarById(postingId: string) {
const data = await prisma.forum_Komentar.findMany({
orderBy: {
createdAt: "desc",
},
where: {
forum_PostingId: postingId,
isActive: true,
},
select: {
id: true,
isActive: true,
komentar: true,
createdAt: true,
Author: {
select: {
id: true,
Profile: {
select: {
name: true,
imagesId: true,
},
},
},
},
authorId: true,
},
});
return data;
}

View File

@@ -0,0 +1,54 @@
"use server";
import _ from "lodash";
import prisma from "@/app/lib/prisma";
import { forum_countOneTotalKomentarById } from "../count/count_one_total_komentar_by_id";
import { forum_countTotalKomenById } from "../count/count_total_komentar_by_id";
export async function forum_getListAllPosting() {
const get = await prisma.forum_Posting.findMany({
orderBy: {
createdAt: "desc",
},
where: {
isActive: true,
},
select: {
id: true,
diskusi: true,
createdAt: true,
isActive: true,
authorId: true,
Author: {
select: {
id: true,
Profile: true,
},
},
Forum_Komentar: {
where: {
isActive: true,
},
},
// _count: {
// select: {
// Forum_Komentar: true,
// },
// },
},
});
// const data = get.map((v) => ({
// ..._.omit(v, ['Forum_Komentar']),
// total_coment: v.Forum_Komentar.filter((v) => v.isActive).length,
// }));
const data = get.map((val) => ({
..._.omit(val, ["Forum_Komentar"]),
_count: val.Forum_Komentar.length,
}));
// console.log(JSON.stringify(data, null, 2));
return data;
}

View File

@@ -0,0 +1,42 @@
"use server";
import prisma from "@/app/lib/prisma";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
import _ from "lodash";
export async function forum_getListPostingByAuhtorId(authorId: string) {
const get = await prisma.forum_Posting.findMany({
orderBy: {
createdAt: "desc",
},
where: {
authorId: authorId,
isActive: true,
},
select: {
id: true,
diskusi: true,
createdAt: true,
isActive: true,
authorId: true,
Author: {
select: {
id: true,
Profile: true,
},
},
Forum_Komentar: {
where: {
isActive: true,
},
},
},
});
const data = get.map((val) => ({
..._.omit(val, ["Forum_Komentar"]),
_count: val.Forum_Komentar.length,
}));
return data;
}

View File

@@ -0,0 +1,32 @@
"use server";
import prisma from "@/app/lib/prisma";
export async function forum_getOnePostingById(postingId: string) {
const data = await prisma.forum_Posting.findFirst({
where: {
id: postingId,
},
select: {
id: true,
diskusi: true,
isActive: true,
createdAt: true,
authorId: true,
Author: {
select: {
id: true,
username: true,
Profile: true,
},
},
_count: {
select: {
Forum_Komentar: true,
},
},
},
});
return data;
}