diff --git a/.env b/.env
new file mode 100644
index 00000000..50ab0d74
--- /dev/null
+++ b/.env
@@ -0,0 +1,12 @@
+# Environment variables declared in this file are automatically made available to Prisma.
+# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
+
+# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
+# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
+
+# DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
+# DATABASE_URL="mongodb://yoo32767:GuCtswjLGqUaNL0G@cluster0.vsdtcnb.mongodb.net/sample_mflix?retryWrites=true&w=majority"
+#DATABASE_URL = "mongodb%2Bsrv%3A%2F%2Fyoo32767%3AGuCtswjLGqUaNL0G%40cluster0.vsdtcnb.mongodb.net%2F%3FretryWrites%3Dtrue%26w%3Dmajority%26appName%3DCluster0"
+# DATABASE_URL = "mongodb+srv://yoo32767:GuCtswjLGqUaNL0G@cluster0.vsdtcnb.mongodb.net/Cluster0?retryWrites=true&w=majority"
+# DATABASE_URL="mongodb://yoo32767:GuCtswjLGqUaNL0G@cluster0.vsdtcnb.mongodb.net/sample_mflix?retryWrites=true&w=majority"
+DATABASE_URL="mongodb+srv://yoo32767:GuCtswjLGqUaNL0G@cluster0.vsdtcnb.mongodb.net/mytest"
\ No newline at end of file
diff --git a/package.json b/package.json
index f7fa513c..9c745fdf 100644
--- a/package.json
+++ b/package.json
@@ -10,9 +10,11 @@
},
"dependencies": {
"@nextui-org/react": "^2.4.2",
+ "@prisma/client": "^5.17.0",
"fabric": "^5.3.0",
"framer-motion": "^11.2.13",
"mathjs": "^13.0.2",
+ "mongodb": "^6.8.0",
"next": "14.2.3",
"react": "^18",
"react-dom": "^18",
@@ -21,6 +23,7 @@
},
"devDependencies": {
"postcss": "^8",
+ "prisma": "^5.17.0",
"tailwindcss": "^3.4.1"
}
}
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
new file mode 100644
index 00000000..327b757a
--- /dev/null
+++ b/prisma/schema.prisma
@@ -0,0 +1,19 @@
+generator client {
+ provider = "prisma-client-js"
+}
+
+datasource db {
+ provider = "mongodb"
+ url = env("DATABASE_URL")
+}
+
+model test {
+ id String @id @default(auto()) @map("_id") @db.ObjectId
+ content String
+}
+
+model canvas {
+ id String @id @default(auto()) @map("_id") @db.ObjectId
+ loginId String
+ canvas Json
+}
\ No newline at end of file
diff --git a/src/components/Roof2.jsx b/src/components/Roof2.jsx
index de9873b0..f46a6baa 100644
--- a/src/components/Roof2.jsx
+++ b/src/components/Roof2.jsx
@@ -7,8 +7,9 @@ import QPolygon from '@/components/fabric/QPolygon'
import RangeSlider from './ui/RangeSlider'
import { useRecoilState, useRecoilValue } from 'recoil'
-import { canvasListState, canvasSizeState, fontSizeState, sortedPolygonArray } from '@/store/canvasAtom'
+import { canvasAtom, canvasSizeState, fontSizeState, sortedPolygonArray } from '@/store/canvasAtom'
import { QLine } from '@/components/fabric/QLine'
+import { getTests, getCanvasState, insertCanvasState } from '@/lib/canvas'
export default function Roof2() {
const { canvas, handleRedo, handleUndo, setCanvasBackgroundWithDots, saveImage, addCanvas, changeCanvas } = useCanvas('canvas')
@@ -35,6 +36,8 @@ export default function Roof2() {
const { mode, changeMode, handleClear, fillCellInPolygon, zoomIn, zoomOut, zoom, togglePolygonLine, handleOuterlinesTest2, applyTemplateB } =
useMode()
+ // const [canvasState, setCanvasState] = useRecoilState(canvasAtom)
+
useEffect(() => {
if (!canvas) {
return
@@ -242,6 +245,36 @@ export default function Roof2() {
const lines = togglePolygonLine(polygon)
}
+ /**
+ * canvas 내용 저장하기
+ */
+ const handleSaveCanvas = async () => {
+ // const jsonStr = JSON.stringify(canvas?.toDatalessJSON(['type', 'fontSize']))
+ const jsonObj = JSON.stringify(canvas?.toDatalessJSON(['type', 'fontSize', 'lines']))
+ console.log(jsonObj)
+
+ const param = {
+ loginId: 'test',
+ canvas: jsonObj,
+ }
+ console.log(param)
+
+ await insertCanvasState(param)
+ handleClear()
+ }
+
+ /**
+ * canvas 내용 불러오기
+ */
+ const handleLoadCanvas = async () => {
+ const canvasStates = await getCanvasState()
+ console.log(JSON.parse(canvasStates.canvas))
+ canvas?.loadFromJSON(JSON.parse(canvasStates.canvas))
+ }
+
+ /**
+ * 컨트롤러 보이기/숨기기
+ */
const handleShowController = () => {
setShowControl(!showControl)
}
@@ -345,11 +378,11 @@ export default function Roof2() {
-