Skip to content
Snippets Groups Projects
Commit 770970ec authored by Caner's avatar Caner
Browse files

gamelist

parent e355e504
No related branches found
No related tags found
1 merge request!26Game list
Pipeline #36988 failed
import { db } from "@/lib/db";
import { getCurrentUser } from "@/lib/session";
import { revalidatePath } from "next/cache";
import { NextRequest, NextResponse } from "next/server";
export async function PUT(req: NextRequest) {
const user = await getCurrentUser();
if (!user) {
return NextResponse.json({ status: 401, message: 'Unauthorized' });
}
const userId = user.id;
const content = await req.json()
console.log(content);
console.log(userId);
try {
await db.user.update({
where:{
id: userId
},
data: {
favGameList:{
push: content.gameId
}
}
})
const path = req.nextUrl.searchParams.get('path') || '/';
revalidatePath(path);
return NextResponse.json({ status: 201, message: 'Game Hinzugefügt' })
} catch (error: any) {
return NextResponse.json({ status: 500, message: error.message })
}
}
\ No newline at end of file
"use client"
import { Post, Prisma } from "@prisma/client";
import { useRouter } from "next/navigation";
import { startTransition, useEffect, useState } from "react";
export default function AddGameToList(props: { userid: string, gameId: string }) {
const router = useRouter();
const gameId = props.gameId
let formData = {gameId}
async function addGame(e: any) {
e.preventDefault()
formData.gameId = gameId;
const response = await fetch('http://localhost:3000/api/gameList', {
method: 'PUT',
body: JSON.stringify(formData)
})
startTransition(() => {
// Refresh the current route and fetch new data from the server without
// losing client-side browser or React state.
router.refresh();
});
return await response.json()
}
return (
<button type="submit" className="mt-2 bg-gray-300 text-gray-800 px-4 py-2 rounded float-right">
Post
</button>
)
}
\ No newline at end of file
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
......@@ -16,21 +13,20 @@ model Account {
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
id_token String?
session_state String?
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @map(name: "updated_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
refresh_token_expires_in Int?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map(name: "accounts")
@@map("accounts")
}
model Session {
......@@ -38,10 +34,9 @@ model Session {
sessionToken String @unique
userId String @unique
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map(name: "sessions")
@@map("sessions")
}
model User {
......@@ -52,20 +47,18 @@ model User {
emailVerified DateTime?
password String?
image String?
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @map(name: "updated_at")
accounts Account[]
sessions Session[]
Post Post[]
Comment Comment[]
Like Like[]
followers Follows[] @relation("follower")
following Follows[] @relation("following")
@@map(name: "users")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
favGameList Int[]
accounts Account?
Comment Comment[]
following Follows[] @relation("following")
followers Follows[] @relation("follower")
Like Like[]
Post Post[]
sessions Session?
@@map("users")
}
model VerificationToken {
......@@ -74,61 +67,58 @@ model VerificationToken {
expires DateTime
@@unique([identifier, token])
@@map(name: "verification_tokens")
@@map("verification_tokens")
}
model Follows {
follower User @relation("following", fields: [followerId], references: [id])
followerId String
following User @relation("follower", fields: [followingId], references: [id])
followingId String
createdAt DateTime @default(now())
follower User @relation("following", fields: [followerId], references: [id])
following User @relation("follower", fields: [followingId], references: [id])
@@id([followerId, followingId])
@@map(name: "follows")
@@map("follows")
}
model Post {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @map(name: "updated_at")
id String @id @default(cuid())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
userId String
content String
likeCount Int? @default(0)
published Boolean @default(false)
likeCount Int? @default(0)
published Boolean @default(false)
Comment Comment[]
Like Like[]
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Comment Comment[]
Like Like[]
@@map(name: "posts")
@@map("posts")
}
model Like {
id String @id @default(cuid())
id String @id @default(cuid())
postId String
commentId String?
userId String
comment Comment? @relation(fields: [commentId], references: [id], onDelete: Cascade)
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
comment Comment? @relation(fields: [commentId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map(name: "likes")
@@map("likes")
}
model Comment {
id String @id @default(cuid())
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @map(name: "updated_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @map("updated_at")
message String
likeCount Int? @default(0)
postId String
userId String
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Like Like[]
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Like Like[]
@@map(name: "comments")
@@map("comments")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment