model Inquiry {
id Int @id @default(autoincrement())
name String
email String
content String
created_at DateTime @default(now()) @db.Timestamptz(6)
is_mailing Boolean?
}
import { PrismaClient } from "@prisma/client";
export const db = new PrismaClient();
"use client"
export default function Inquiry() {
const name = "이일삼";
const email = "twooneth@naver.com";
const content = "안녕하세요";
const handleCreate = async () => {
const inquiry = await createInquiry({ name, email, content });
console.log(inquiry);
};
return (
<DefaultLayout>
<div className="container grid gap-12 py-10">
<button onClick={handleCreate}> test button</button>
</div>
</DefaultLayout>
);
}
"use server"
import { inquiryService } from "@/services/inquiry.service";
interface ICreateInquiryDto {
name: string;
email: string;
content: string;
}
export const createInquiry = async ({ name, email, content }: ICreateInquiryDto) => {
console.log("action",name, email, content)
const createdInquiry = await inquiryService.createInquiry({
name,
email,
content,
});
return createdInquiry;
};
import { Prisma } from "@prisma/client";
import { db } from "@/utils/db";
class InquiryService {
async createInquiry(dto: Prisma.InquiryCreateInput) {
console.log("service", dto);
try {
const inquiry = await db.inquiry.create({
data: dto,
});
return inquiry;
}catch (e){
console.log(e);
}
}
}
export const inquiryService = new InquiryService();