Skip to content
Snippets Groups Projects
Commit 8638e65a authored by Yusuf Akgül's avatar Yusuf Akgül :hatching_chick:
Browse files

Merge branch 'fixTweeting' into 'main'

Fix tweeting

See merge request !17
parents be03ac01 a4c7be77
No related branches found
No related tags found
1 merge request!17Fix tweeting
Pipeline #35638 failed
......@@ -2,6 +2,7 @@ import LikeButton from "@/components/like-button";
import PostMessageForm from "@/components/post-messages";
import { prisma } from "@/lib/db";
import { Prisma } from "@prisma/client";
/* export const revalidate = 5; */ // revalidate this page every 60 seconds
type messageType = Prisma.PostUncheckedCreateInput
type messageItemProps = {
......
import { prisma } from "@/lib/db"
import { NextRequest, NextResponse } from "next/server"
import { getServerSession } from "next-auth/next"
import { authOptions } from "../auth/[...nextauth]/route";
import { Prisma } from "@prisma/client";
import { revalidatePath, revalidateTag } from "next/cache";
type post = Prisma.PostUncheckedCreateInput
export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ status: 401 });
}
const userId = session.user.id
const data = await req.json()
console.log("router data: " + data, "status:")
console.log(data)
console.log("router data: " + data.content, "status:")
try {
await prisma.post.create({
data: data
/* data: data */
data:{
content: data.content,
userId: parseInt(userId),
published: true
}
})
console.log("created")
const path = req.nextUrl.searchParams.get('path') || '/';
revalidatePath(path);
return NextResponse.json({ status: 201, message: 'Message Created' })
// res.status(200).json({message: 'Message Created'})
// res.status(200).json({message: 'Message Created'})
} catch (error) {
console.log("fail" + error);
// res.status(400)
}
console.log("post")
}
export async function GET(req: NextRequest, res: NextResponse) {
const data = await req.json()
console.log("router data: " + data, "status:")
try {
const data = await req.json()
console.log("router data: " + data, "status:")
} catch (error) {
}
console.log(data)
try {
const messages = await prisma.post.findMany({
orderBy: {
......
......@@ -2,25 +2,24 @@
import { Post, Prisma } from "@prisma/client";
import { useRouter } from "next/navigation";
import { startTransition, useState } from "react";
import { startTransition, useEffect, useState } from "react";
type messageType = Prisma.PostUncheckedCreateInput
export default function PostMessageForm(props: { data: Post[] | null }) {
const [formData, setFormData] = useState<messageType>({ content: "" } as messageType);
// const [messagesState, setMessages] = useState(props.data)
const router = useRouter();
async function postMessage(e: any) {
e.preventDefault()
// setMessages([...messagesState, formData])
console.log(formData)
formData.userId = 1
const response = await fetch('http://localhost:3000/api/messages', {
method: 'POST',
body: JSON.stringify(formData)
body: JSON.stringify(formData),
next: { tags: ['collection'] }
})
startTransition(() => {
// Refresh the current route and fetch new data from the server without
// losing client-side browser or React state.
......@@ -30,7 +29,7 @@ export default function PostMessageForm(props: { data: Post[] | null }) {
}
const characterCount = formData.content.length;
const isOverLimit = characterCount > 1000;
const isOverLimit = characterCount >= 1000;
const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
const { value } = e.target;
......
......@@ -3,7 +3,7 @@ import 'next-auth';
declare module 'next-auth' {
interface Session {
user: {
id: number;
id: string;
name?: string | null;
email?: string | null;
image?: string | null;
......
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