Skip to content

Commit 7e5e3a8

Browse files
committed
Fixed the Delete
1 parent b2fce37 commit 7e5e3a8

File tree

6 files changed

+54
-15
lines changed

6 files changed

+54
-15
lines changed

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"type": "chrome",
10+
"request": "launch",
11+
"name": "Launch Chrome against localhost",
12+
"url": "http://localhost:8080",
13+
"webRoot": "${workspaceFolder}"
14+
}
15+
]
16+
}

apps/X/app/(pages)/post/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use client"
2+
function page() {
3+
return <div>This is the Post page</div>
4+
}
5+
export default page

apps/X/app/api/post/route.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ export const POST = async (req: NextRequest) => {
7575
};
7676

7777
export async function DELETE(req: NextRequest) {
78-
try {
78+
try {
7979
const session = await getServerSession(authOptions);
80+
8081
if (!session?.user?.id) {
8182
return NextResponse.json(
8283
{ error: "Unauthorized - User not authenticated" },
@@ -91,17 +92,27 @@ export async function DELETE(req: NextRequest) {
9192
{ status: 400 }
9293
);
9394
}
95+
const tweet = await prisma.tweet.findUnique({
96+
where: { id: Number(id) },
97+
});
98+
if (!tweet) {
99+
return NextResponse.json(
100+
{ message: "Tweet not found" },
101+
{ status: 404 }
102+
);
103+
}
104+
if (tweet.userID !== Number(userDel)) {
105+
return NextResponse.json({message:"Unauthorized"})
106+
}
94107
const tweetId = Number(id);
95108
const deleteTweet = await prisma.tweet.update({
96-
where: { id: tweetId, userID: userDel },
109+
where: { id: tweetId},
97110
data: {
98111
IsDelete: true,
99112
},
100113
});
101-
if (!deleteTweet) {
102-
return NextResponse.json({ message: "Tweet not found" }, { status: 404 });
103-
}
104-
114+
console.log("This is the response", deleteTweet);
115+
105116
return NextResponse.json({ message: "Done with delete" }, { status: 200 });
106117
} catch (error) {
107118
console.log("Getting error in Delete", error);

apps/X/src/components/ui/TweetComp.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
PopoverTrigger,
77
} from "@/components/ui/popover";
88
import axios from "axios";
9-
import { NextResponse } from "next/server";
109
import { BiRepost } from "react-icons/bi";
1110
import { FaRegBookmark, FaRegComment } from "react-icons/fa6";
1211
import { FiHeart } from "react-icons/fi";
@@ -29,7 +28,7 @@ export const TweetComp = ({ tweet }: TweetProps) => {
2928
try {
3029
const response = await axios.delete(`/api/post?id=${tweet.id}`);
3130
console.log("Tweet Deleted", response);
32-
return NextResponse.json({ status: 200 });
31+
return response.data;
3332
} catch (error) {
3433
console.log("Error while Deleting Tweet", error);
3534
}

apps/X/src/components/ui/home/HomeComp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CenterComp, HomeLeft, HomeRight } from "@/components/ui";
33
export const HomeComp = () => {
44
return (
55
<div className="flex h-screen overflow-y-auto">
6-
<div className="custom:w-96 w-10 custom:ml-24 ml-24 h-screen sticky top-0 flex-shrink-0 mr-7 custom:mr-10">
6+
<div className="custom:w-96 w-10 custom:ml-24 ml-2 h-screen sticky top-0 flex-shrink-0 mr-7 custom:mr-10">
77
<HomeLeft />
88
</div>
99
<div className="flex flex-grow">

apps/X/src/components/ui/home/HomeLeft.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
"use client";
22

3+
import { getSession } from "next-auth/react";
4+
import Link from "next/link";
5+
import { useRouter } from "next/navigation";
36
import { AiOutlineThunderbolt } from "react-icons/ai";
47
import { CgMoreO } from "react-icons/cg";
58
import { FaRegBookmark } from "react-icons/fa";
69
import { FaRegUser } from "react-icons/fa6";
710
import { GoHome } from "react-icons/go";
811
import { IoMdSearch } from "react-icons/io";
9-
import { TbOctagonPlus } from "react-icons/tb";
1012
import { MdOutlineMail } from "react-icons/md";
1113
import { RiGroupLine, RiNotification2Line } from "react-icons/ri";
14+
import { TbOctagonPlus } from "react-icons/tb";
1215
import { Button, UserAvatar, X_logo } from "..";
1316
import GrokIcon from "../Grok";
1417
import X_Icon from "../X_Icon";
15-
import Link from "next/link";
16-
import { useState } from "react";
18+
1719
export const HomeLeft = () => {
18-
const [isOpen, setIsOpen] = useState(false);
20+
const router = useRouter();
21+
const session = getSession();
1922

2023
const onPostClick = () => {
2124
console.log("Click");
22-
setIsOpen(!isOpen);
25+
router.push("/post");
26+
console.log(session, "This is the session");
2327
};
2428
return (
2529
<div>
@@ -138,8 +142,12 @@ export const HomeLeft = () => {
138142
</div>
139143
</div>
140144
<div className="mt-28">
141-
<div>
145+
<div className="flex gap-2">
142146
<UserAvatar />
147+
<div>
148+
<p className="font-bold">mscode</p>
149+
<p className="text-slate-600 font-semibold">@mscode07</p>
150+
</div>
143151
</div>
144152
</div>
145153
</div>

0 commit comments

Comments
 (0)