aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-07-25 18:43:13 +0700
committerFactiven <[email protected]>2023-07-25 18:43:13 +0700
commit95393d7c8ba5cf6cd17f2038fc421c0d6d06f2e6 (patch)
tree97154270ec3ad400e63a683e194ea56eca0b9b0b
parentadded .env disqus shortname (diff)
downloadmoopa-95393d7c8ba5cf6cd17f2038fc421c0d6d06f2e6.tar.xz
moopa-95393d7c8ba5cf6cd17f2038fc421c0d6d06f2e6.zip
Update_v3.6.7-beta-v1.4v.3.6.7-beta-v1.4
>Implementing database
-rw-r--r--package-lock.json50
-rw-r--r--package.json2
-rw-r--r--pages/api/user.js18
-rw-r--r--pages/en/db-test.js79
-rw-r--r--prisma/schema.prisma34
-rw-r--r--prisma/user.js37
6 files changed, 220 insertions, 0 deletions
diff --git a/package-lock.json b/package-lock.json
index 2b68db9..d0d3981 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -12,6 +12,7 @@
"@headlessui/react": "^1.7.15",
"@heroicons/react": "^2.0.17",
"@next/font": "13.0.7",
+ "@prisma/client": "^5.0.0",
"@vercel/og": "^0.5.4",
"artplayer": "^5.0.9",
"artplayer-plugin-hls-quality": "^2.0.0",
@@ -41,6 +42,7 @@
"eslint-config-next": "12.1.6",
"postcss": "^8.4.20",
"prettier": "^2.8.3",
+ "prisma": "^5.0.0",
"tailwind-scrollbar": "^2.1.0",
"tailwindcss": "^3.3.1"
}
@@ -2302,6 +2304,38 @@
"url": "https://github.com/sponsors/panva"
}
},
+ "node_modules/@prisma/client": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.0.0.tgz",
+ "integrity": "sha512-XlO5ELNAQ7rV4cXIDJUNBEgdLwX3pjtt9Q/RHqDpGf43szpNJx2hJnggfFs7TKNx0cOFsl6KJCSfqr5duEU/bQ==",
+ "hasInstallScript": true,
+ "dependencies": {
+ "@prisma/engines-version": "4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584"
+ },
+ "engines": {
+ "node": ">=16.13"
+ },
+ "peerDependencies": {
+ "prisma": "*"
+ },
+ "peerDependenciesMeta": {
+ "prisma": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@prisma/engines": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.0.0.tgz",
+ "integrity": "sha512-kyT/8fd0OpWmhAU5YnY7eP31brW1q1YrTGoblWrhQJDiN/1K+Z8S1kylcmtjqx5wsUGcP1HBWutayA/jtyt+sg==",
+ "devOptional": true,
+ "hasInstallScript": true
+ },
+ "node_modules/@prisma/engines-version": {
+ "version": "4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584",
+ "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.17.0-26.6b0aef69b7cdfc787f822ecd7cdc76d5f1991584.tgz",
+ "integrity": "sha512-HHiUF6NixsldsP3JROq07TYBLEjXFKr6PdH8H4gK/XAoTmIplOJBCgrIUMrsRAnEuGyRoRLXKXWUb943+PFoKQ=="
+ },
"node_modules/@resvg/resvg-wasm": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/@resvg/resvg-wasm/-/resvg-wasm-2.4.1.tgz",
@@ -6474,6 +6508,22 @@
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz",
"integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew=="
},
+ "node_modules/prisma": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.0.0.tgz",
+ "integrity": "sha512-KYWk83Fhi1FH59jSpavAYTt2eoMVW9YKgu8ci0kuUnt6Dup5Qy47pcB4/TLmiPAbhGrxxSz7gsSnJcCmkyPANA==",
+ "devOptional": true,
+ "hasInstallScript": true,
+ "dependencies": {
+ "@prisma/engines": "5.0.0"
+ },
+ "bin": {
+ "prisma": "build/index.js"
+ },
+ "engines": {
+ "node": ">=16.13"
+ }
+ },
"node_modules/prop-types": {
"version": "15.8.1",
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz",
diff --git a/package.json b/package.json
index c34d31b..4e725ce 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
"@headlessui/react": "^1.7.15",
"@heroicons/react": "^2.0.17",
"@next/font": "13.0.7",
+ "@prisma/client": "^5.0.0",
"@vercel/og": "^0.5.4",
"artplayer": "^5.0.9",
"artplayer-plugin-hls-quality": "^2.0.0",
@@ -44,6 +45,7 @@
"eslint-config-next": "12.1.6",
"postcss": "^8.4.20",
"prettier": "^2.8.3",
+ "prisma": "^5.0.0",
"tailwind-scrollbar": "^2.1.0",
"tailwindcss": "^3.3.1"
}
diff --git a/pages/api/user.js b/pages/api/user.js
new file mode 100644
index 0000000..1d286e7
--- /dev/null
+++ b/pages/api/user.js
@@ -0,0 +1,18 @@
+import { createUser, getUser } from "../../prisma/user";
+
+export default async function handler(req, res) {
+ try {
+ switch (req.method) {
+ case "POST": {
+ const { name, setting, animeWatched } = JSON.parse(req.body);
+ const new_user = await createUser(name, setting);
+ return res.status(201).json(new_user);
+ }
+ case "GET": {
+ const { name } = req.query;
+ const user = await getUser(name);
+ return res.status(200).json(user);
+ }
+ }
+ } catch (error) {}
+}
diff --git a/pages/en/db-test.js b/pages/en/db-test.js
new file mode 100644
index 0000000..f2dccd3
--- /dev/null
+++ b/pages/en/db-test.js
@@ -0,0 +1,79 @@
+import { PrismaClient } from "@prisma/client";
+import { useState } from "react";
+const prisma = new PrismaClient();
+
+export async function getServerSideProps() {
+ const user = await prisma.user.findMany({
+ where: {
+ setting: {
+ path: ["language"],
+ equals: "id",
+ },
+ },
+ });
+ return {
+ props: {
+ user,
+ },
+ };
+}
+
+const settings = {
+ isAdult: false,
+ theme: "dark",
+ language: "en",
+};
+
+export default function DbTest({ user }) {
+ const [add, setUser] = useState();
+
+ console.log(user);
+
+ async function handleCreate(e) {
+ e.preventDefault();
+ const res = await fetch("/api/user", {
+ method: "POST",
+ body: JSON.stringify({ name: add, setting: settings }),
+ });
+ const json = await res.json();
+ console.log(json);
+ }
+ // console.log(add);
+ return (
+ <div>
+ <form onSubmit={handleCreate}>
+ <input type="text" onChange={(e) => setUser(e.target.value)} />
+ <button type="submit">Submit</button>
+ </form>
+ <h1>hello gaes</h1>
+ </div>
+ );
+}
+
+const user = [
+ {
+ id: String,
+ name: String,
+ setting: {
+ isAdult: Boolean,
+ theme: String,
+ language: String,
+ },
+ watchList: [
+ {
+ id: String,
+ title: String,
+ episodes: [
+ {
+ id: String,
+ title: String,
+ episode: Number,
+ url: String,
+ timeWatched: Number,
+ duration: Number,
+ },
+ ],
+ },
+ ],
+ },
+];
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
new file mode 100644
index 0000000..adf0fa1
--- /dev/null
+++ b/prisma/schema.prisma
@@ -0,0 +1,34 @@
+datasource db {
+ provider = "postgresql"
+ url = env("DATABASE_URL")
+}
+
+generator client {
+ provider = "prisma-client-js"
+}
+
+model WatchListEpisode {
+ id String @id @default(cuid())
+ title String
+ episode Int
+ url String
+ timeWatched Int
+ duration Int
+ watchListItem WatchListItem @relation(fields: [watchListItemId], references: [id])
+ watchListItemId String
+}
+
+model WatchListItem {
+ id String @id @default(cuid())
+ title String
+ episodes WatchListEpisode[]
+ userProfile UserProfile? @relation(fields: [userProfileId], references: [id])
+ userProfileId String?
+}
+
+model UserProfile {
+ id String @id @default(cuid())
+ name String
+ setting Json
+ watchList WatchListItem[]
+}
diff --git a/prisma/user.js b/prisma/user.js
new file mode 100644
index 0000000..d58c1a9
--- /dev/null
+++ b/prisma/user.js
@@ -0,0 +1,37 @@
+import { PrismaClient } from "@prisma/client";
+const prisma = new PrismaClient();
+
+export const createUser = async (name, setting, animeWatched) => {
+ const user = await prisma.user.create({
+ data: {
+ name,
+ setting,
+ animeWatched,
+ },
+ });
+
+ return user;
+};
+
+export const updateUser = async (name, setting, animeWatched) => {
+ const user = await prisma.user.update({
+ where: {
+ name: name,
+ },
+ data: {
+ setting,
+ animeWatched,
+ },
+ });
+
+ return user;
+};
+
+export const getUser = async (name) => {
+ const user = await prisma.user.findUnique({
+ where: {
+ name: name,
+ },
+ });
+ return user;
+};