Skip to content
Snippets Groups Projects
Commit 787c7cfa authored by Serdar D's avatar Serdar D
Browse files

Following model, following button und following user

parent b617cbcc
No related branches found
No related tags found
2 merge requests!15Following,!14Following
Pipeline #35438 failed
"use client"
import { Prisma } from "@prisma/client";
import { useRouter } from "next/navigation";
import { startTransition } from "react";
import { Icons } from "./icons";
import { Button } from "./ui/button";
type likeType = Prisma.LikeUncheckedCreateInput
export default function FollowButton(props: { data: likeType }) {
const router = useRouter();
async function postFollow(e: any) {
e.preventDefault()
const msgLikeData = props.data;
const likeData = {} as likeType
likeData.userId = msgLikeData.userId
likeData.postId = msgLikeData.postId
const response = await fetch('http://localhost:3000/api/follows', {
method: 'PUT',
body: JSON.stringify(likeData)
})
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 (
<div>
<form onSubmit={postFollow}>
<Button type="submit" variant="ghost" size="lg" className="float-right" >
<Icons.heart className="h-3 w-3" />
</Button>
</form>
</div>
)
}
\ No newline at end of file
......@@ -22,6 +22,8 @@ model User {
Post Post[]
Comment Comment[]
Like Like[]
followers User[] @relation("Followers", references: [id])
following User[] @relation("Following", references: [id])
}
model Post {
......@@ -57,3 +59,11 @@ model Comment {
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model Follower {
id Int @id @default(autoincrement())
follower User @relation("Followers", fields: [followerId], references: [id])
followerId Int
following User @relation("Following", fields: [followingId], references: [id])
followingId Int
}
\ No newline at end of file
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