From ee6877f8d8ae56667c5058bd1f57804a38928600 Mon Sep 17 00:00:00 2001 From: haseebzaki-07 Date: Tue, 6 Aug 2024 15:51:08 +0530 Subject: [PATCH 01/13] add_docker-compose --- docker-compose.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7b87aeb --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.8' +services: + + frontend: + build: + context: ./frontend + container_name: styleshare-frontend + ports: + - '3000:3000' + + backend: + build: + context: ./backend + container_name: styleshare-backend + depends_on: + - db + env_file: + - ./backend/.env + ports: + - '8000:8000' + + db: + image: mongo:latest + container_name: styleshare-db + restart: always + ports: + - '27017:27017' + volumes: + - mongodb_data:/data/db + +volumes: + mongodb_data: From f2d7308749280e3f9bbc6d4f2a13a10a4f0c691f Mon Sep 17 00:00:00 2001 From: Parth Virendrakumar Shah Date: Tue, 6 Aug 2024 22:52:31 -0700 Subject: [PATCH 02/13] made minor UI improvements for posts and added placeholder for tag filter --- frontend/src/components/PostCard.tsx | 55 ++++++------- frontend/src/pages/EditPost.tsx | 2 +- frontend/src/pages/NewPost.tsx | 2 +- frontend/src/pages/Posts.tsx | 112 ++++++++++++++------------- 4 files changed, 87 insertions(+), 84 deletions(-) diff --git a/frontend/src/components/PostCard.tsx b/frontend/src/components/PostCard.tsx index b6111b4..36bbc1d 100644 --- a/frontend/src/components/PostCard.tsx +++ b/frontend/src/components/PostCard.tsx @@ -9,7 +9,7 @@ import toast from "react-hot-toast"; import { Link } from "react-router-dom"; import { FaEdit } from "react-icons/fa"; import bgHero from "../assets/bgHero.png"; -import { MdFavorite,MdFavoriteBorder } from "react-icons/md"; +import { MdFavorite, MdFavoriteBorder } from "react-icons/md"; type Props = { post: IPost; @@ -181,10 +181,10 @@ const PostCard = ({ post, onDelete, currentUser }: Props) => {
-

{post.title}

+

{post.title}

{isFavorite ? ( { className="cursor-pointer text-[#e74e4e] dark:text-white" /> )} -

+

+

{post.description.length > 100 ? `${post.description.slice(0, 100)}...` : post.description}

-

By : +

By : - + {' '} @{post.author.username}{' '} - +

- +
- {post.tags.map((tag, index) => ( - - {tag} - - ))} -
+ {post.tags.map((tag, index) => ( + + {tag} + + ))} +
{/*
)} diff --git a/frontend/src/pages/EditPost.tsx b/frontend/src/pages/EditPost.tsx index e6f0af9..f0efb0b 100644 --- a/frontend/src/pages/EditPost.tsx +++ b/frontend/src/pages/EditPost.tsx @@ -42,7 +42,7 @@ const EditPost = () => { const handleAddTag = () => { if (tagInput.length > 0 && !post.tags.includes(tagInput)) { - setPost({ ...post, tags: [...post.tags, tagInput] }); + setPost({ ...post, tags: [...post.tags, tagInput.toLowerCase()] }); setTagInput(""); } }; diff --git a/frontend/src/pages/NewPost.tsx b/frontend/src/pages/NewPost.tsx index 7ae333d..d0530d9 100644 --- a/frontend/src/pages/NewPost.tsx +++ b/frontend/src/pages/NewPost.tsx @@ -33,7 +33,7 @@ const NewPost = () => { const handleAddTag = () => { if (tagInput.length > 0 && !tags.includes(tagInput)) { - setTags([...tags, tagInput]); + setTags([...tags, tagInput.toLowerCase()]); setTagInput(""); } }; diff --git a/frontend/src/pages/Posts.tsx b/frontend/src/pages/Posts.tsx index 5a94df8..4a4bc03 100644 --- a/frontend/src/pages/Posts.tsx +++ b/frontend/src/pages/Posts.tsx @@ -23,7 +23,7 @@ const Posts = () => { removeTag: deleteTag, searchQuery, setSearchQuery, - fetchPosts, + fetchPosts, } = usePosts({ initialPage: 1, pageSize: 12, @@ -33,8 +33,11 @@ const Posts = () => { const [tagInput, setTagInput] = useState(""); const [filterTags, setFilterTags] = useState([]); const filterRef = useRef(null); - const filteredPosts = posts; + const allTags = filteredPosts.map(post => post.tags).flat(); + const uniqueTags = [...new Set(allTags)]; + const tagsToDisplay = uniqueTags.slice(0, 5); + const placeholderTags = tagsToDisplay.length > 0 ? tagsToDisplay.join(", ") : ""; useEffect(() => { const handleClickOutside = (event: MouseEvent) => { @@ -44,7 +47,7 @@ const Posts = () => { }; document.title = "Style Share | Our Posts 📃"; - + document.addEventListener("mousedown", handleClickOutside); return () => { document.removeEventListener("mousedown", handleClickOutside); @@ -93,8 +96,8 @@ const Posts = () => { return (
{ backgroundPosition: "center", }} > -

Posts

+

Posts

@@ -165,7 +168,7 @@ const Posts = () => { onChange={(e) => setSearchQuery(e.target.value)} placeholder="🔍 Search anything" className="p-2 w-full max-w-xs rounded-md text-[#000435] bg-white dark:text-white dark:bg-[#000435] border border-sky-400 focus:outline-none focus:ring-2 focus:ring-blue-500" - /> + />
{filteredPosts.length === 0 ? ( -
No Posts
+
No Posts
) : ( -
- {filteredPosts.map((post) => ( - - ))} +
+
+ {filteredPosts.map((post) => ( + + ))} +
+
+ + {Array.from({ length: totalPages }, (_, i) => ( + + ))} + +
)} -
- - {Array.from({ length: totalPages }, (_, i) => ( - - ))} - -
); From 16cbc0e45d279fa4dbcc82ec3145ef0de73a5993 Mon Sep 17 00:00:00 2001 From: Parth Virendrakumar Shah Date: Wed, 7 Aug 2024 09:07:47 -0700 Subject: [PATCH 03/13] removed the extra reactions rendered on the posts card --- frontend/src/components/PostCard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/PostCard.tsx b/frontend/src/components/PostCard.tsx index 6dd69d5..7aae143 100644 --- a/frontend/src/components/PostCard.tsx +++ b/frontend/src/components/PostCard.tsx @@ -254,7 +254,7 @@ const PostCard = ({ post, onDelete, currentUser }: Props) => { )} - {renderReactions()} + {/* {renderReactions()} */} ); From 7a5c933fe9f9f07a249f8433bc7352528d221016 Mon Sep 17 00:00:00 2001 From: Parth Virendrakumar Shah Date: Wed, 7 Aug 2024 10:07:58 -0700 Subject: [PATCH 04/13] modified the placeholder string --- frontend/src/pages/Posts.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/Posts.tsx b/frontend/src/pages/Posts.tsx index 4c14f24..82977d4 100644 --- a/frontend/src/pages/Posts.tsx +++ b/frontend/src/pages/Posts.tsx @@ -36,9 +36,9 @@ const Posts = () => { const filteredPosts = posts; const allTags = filteredPosts.map(post => post.tags).flat(); const uniqueTags = [...new Set(allTags)]; - const tagsToDisplay = uniqueTags.slice(0, 5); - const placeholderTags = tagsToDisplay.length > 0 ? tagsToDisplay.join(", ") : ""; - + const tagsToDisplay = uniqueTags.slice(0, 3); + var placeholderTags = tagsToDisplay.length > 0 ? tagsToDisplay.join(", ") : ""; + placeholderTags = placeholderTags + (uniqueTags.length > 3 ? " ..." : ""); useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (filterRef.current && !filterRef.current.contains(event.target as Node)) { From d10d034de874e9361a8ec05d9ed7d38bb321783a Mon Sep 17 00:00:00 2001 From: haseebzaki-07 Date: Wed, 7 Aug 2024 23:40:28 +0530 Subject: [PATCH 05/13] add_Dockerfiles --- admin/Dockerfile | 7 +++++++ backend/Dockerfile | 9 +++++++++ docker-compose.yml | 7 +++++++ frontend/Dockerfile | 7 +++++++ 4 files changed, 30 insertions(+) create mode 100644 admin/Dockerfile create mode 100644 backend/Dockerfile create mode 100644 frontend/Dockerfile diff --git a/admin/Dockerfile b/admin/Dockerfile new file mode 100644 index 0000000..a37017c --- /dev/null +++ b/admin/Dockerfile @@ -0,0 +1,7 @@ +FROM node:alpine +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm install +COPY . . +EXPOSE 5173 +CMD ["npm", "run" , "dev"] \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..d66abb7 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,9 @@ +FROM node:alpine +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm install +COPY . . +RUN npm run backend-build + +EXPOSE 8000 +CMD ["npm", "run" , "dev"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7b87aeb..32b19fa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,13 @@ version: '3.8' services: + admin: + build: + context: ./admin + container_name: styleshare-admin + ports: + - '5173:5173' + frontend: build: context: ./frontend diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..8093374 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,7 @@ +FROM node:alpine +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm install +COPY . . +EXPOSE 3000 +CMD ["npm", "run" , "dev"] \ No newline at end of file From 3a51d7f4e2941aaa8b6c09530e03d7c5a121b27d Mon Sep 17 00:00:00 2001 From: haseebzaki-07 Date: Thu, 8 Aug 2024 12:57:07 +0530 Subject: [PATCH 06/13] update_environment --- backend/Dockerfile | 1 + docker-compose.yml | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index d66abb7..6c5a22a 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -5,5 +5,6 @@ RUN npm install COPY . . RUN npm run backend-build + EXPOSE 8000 CMD ["npm", "run" , "dev"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 32b19fa..94b15d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,8 +21,9 @@ services: container_name: styleshare-backend depends_on: - db - env_file: - - ./backend/.env + environment: + - DATABASE_URL=${DATABASE_URL} + ports: - '8000:8000' From 8fee725cd5cdc12a7a24501d8bd5611920f174ba Mon Sep 17 00:00:00 2001 From: Utsavladia Date: Thu, 8 Aug 2024 14:21:12 +0530 Subject: [PATCH 07/13] Added skeleton for posts loading --- frontend/package-lock.json | 9 +++++ frontend/package.json | 1 + frontend/src/components/PostsSkeleton.tsx | 44 +++++++++++++++++++++++ frontend/src/pages/Posts.tsx | 3 +- 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/PostsSkeleton.tsx diff --git a/frontend/package-lock.json b/frontend/package-lock.json index eb26e80..c7d02e9 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -31,6 +31,7 @@ "react-fast-marquee": "^1.6.4", "react-hot-toast": "^2.4.1", "react-icons": "^5.2.1", + "react-loading-skeleton": "^3.4.0", "react-parallax-tilt": "^1.7.231", "react-responsive-modal": "^6.4.2", "react-router-dom": "^6.24.0", @@ -4842,6 +4843,14 @@ "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==", "license": "MIT" }, + "node_modules/react-loading-skeleton": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/react-loading-skeleton/-/react-loading-skeleton-3.4.0.tgz", + "integrity": "sha512-1oJEBc9+wn7BbkQQk7YodlYEIjgeR+GrRjD+QXkVjwZN7LGIcAFHrx4NhT7UHGBxNY1+zax3c+Fo6XQM4R7CgA==", + "peerDependencies": { + "react": ">=16.8.0" + } + }, "node_modules/react-parallax-tilt": { "version": "1.7.232", "resolved": "https://registry.npmjs.org/react-parallax-tilt/-/react-parallax-tilt-1.7.232.tgz", diff --git a/frontend/package.json b/frontend/package.json index 254593c..dc06007 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -33,6 +33,7 @@ "react-fast-marquee": "^1.6.4", "react-hot-toast": "^2.4.1", "react-icons": "^5.2.1", + "react-loading-skeleton": "^3.4.0", "react-parallax-tilt": "^1.7.231", "react-responsive-modal": "^6.4.2", "react-router-dom": "^6.24.0", diff --git a/frontend/src/components/PostsSkeleton.tsx b/frontend/src/components/PostsSkeleton.tsx new file mode 100644 index 0000000..3763a9a --- /dev/null +++ b/frontend/src/components/PostsSkeleton.tsx @@ -0,0 +1,44 @@ +import Skeleton from 'react-loading-skeleton'; +import 'react-loading-skeleton/dist/skeleton.css'; + +const PostsPageSkeleton = () => { + const skeletonArray = Array(9).fill(0); // Create an array with 9 elements for the skeleton placeholders + + return ( +
+ {skeletonArray.map((_, index) => ( +
+
+ + +
+ + + +
+ {Array(3).fill(0).map((_, idx) => ( + + ))} +
+
+
+ {Array(3).fill(0).map((_, idx) => ( + + ))} +
+
+ + +
+
+
+ ))} +
+ ); +}; + +export default PostsPageSkeleton; diff --git a/frontend/src/pages/Posts.tsx b/frontend/src/pages/Posts.tsx index d55de4a..82a1fb7 100644 --- a/frontend/src/pages/Posts.tsx +++ b/frontend/src/pages/Posts.tsx @@ -6,6 +6,7 @@ import { useRecoilValue } from "recoil"; import usePosts from "../hooks/usePosts"; import bgHero from "../assets/bgHero.png"; import { IoIosArrowDown } from "react-icons/io"; +import PostsPageSkeleton from "../components/PostsSkeleton"; const Posts = () => { const currentUser = useRecoilValue(userState); @@ -80,7 +81,7 @@ const Posts = () => { }; if (loading) { - return ; + return ; } if (error) { From e191c00b58d78b7e5235b9dbbe80b08f58712ee7 Mon Sep 17 00:00:00 2001 From: Utsavladia Date: Thu, 8 Aug 2024 14:35:29 +0530 Subject: [PATCH 08/13] Added skeleton loader for leaderboard --- .../src/components/LeaderboardSkeleton.tsx | 59 +++++++++++++++++++ frontend/src/pages/LeaderBoard.tsx | 3 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/LeaderboardSkeleton.tsx diff --git a/frontend/src/components/LeaderboardSkeleton.tsx b/frontend/src/components/LeaderboardSkeleton.tsx new file mode 100644 index 0000000..db666b7 --- /dev/null +++ b/frontend/src/components/LeaderboardSkeleton.tsx @@ -0,0 +1,59 @@ +import Skeleton from 'react-loading-skeleton'; +import 'react-loading-skeleton/dist/skeleton.css'; + +const LeaderboardSkeleton = () => { + const skeletonArray = Array(5).fill(0); // Adjust the number of skeleton rows as needed + + return ( +
+ + + + + + + + + + + + {skeletonArray.map((_, index) => ( + + + + + + + + ))} + +
+ + + + + + + + + +
+
+ +
+
+
+ +
+
+ + + + + +
+
+ ); +}; + +export default LeaderboardSkeleton; diff --git a/frontend/src/pages/LeaderBoard.tsx b/frontend/src/pages/LeaderBoard.tsx index e72b8d5..55c3d87 100644 --- a/frontend/src/pages/LeaderBoard.tsx +++ b/frontend/src/pages/LeaderBoard.tsx @@ -5,6 +5,7 @@ import { useRecoilValue } from 'recoil'; import { userState } from '../store/atoms/auth'; import useLeaderboard from '../hooks/useLeadearboard'; import bgHero from "../assets/bgHero.png"; +import LeaderboardSkeleton from '../components/LeaderboardSkeleton'; const LeaderBoard = () => { const { loading, leaderboard } = useLeaderboard(); @@ -24,7 +25,7 @@ const LeaderBoard = () => {
{loading ? (
- +
) : (
From 400a71fd44d6ec1f8c3f275a581052fb5f6fc3af Mon Sep 17 00:00:00 2001 From: Haseeb Zaki <147314463+haseebzaki-07@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:24:47 +0530 Subject: [PATCH 09/13] Update docker-compose.yml --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 94b15d7..ececd20 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.8' + services: admin: From 0c31286c5ba78af2810696f88a3f0525b94094b4 Mon Sep 17 00:00:00 2001 From: Utsavladia Date: Thu, 8 Aug 2024 18:53:03 +0530 Subject: [PATCH 10/13] Fixed build error --- frontend/src/pages/LeaderBoard.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/pages/LeaderBoard.tsx b/frontend/src/pages/LeaderBoard.tsx index 55c3d87..0da01fc 100644 --- a/frontend/src/pages/LeaderBoard.tsx +++ b/frontend/src/pages/LeaderBoard.tsx @@ -1,5 +1,4 @@ import { useNavigate } from 'react-router-dom'; -import Loader from '../components/Loader'; import { GiTrophyCup } from "react-icons/gi"; import { useRecoilValue } from 'recoil'; import { userState } from '../store/atoms/auth'; From 92511848d2276391f7b46ccd5cd6fb230d7b749f Mon Sep 17 00:00:00 2001 From: Utsavladia Date: Thu, 8 Aug 2024 19:01:34 +0530 Subject: [PATCH 11/13] Added dependency --- frontend/package-lock.json | 9 +++++++++ frontend/package.json | 1 + 2 files changed, 10 insertions(+) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index eb26e80..c7d02e9 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -31,6 +31,7 @@ "react-fast-marquee": "^1.6.4", "react-hot-toast": "^2.4.1", "react-icons": "^5.2.1", + "react-loading-skeleton": "^3.4.0", "react-parallax-tilt": "^1.7.231", "react-responsive-modal": "^6.4.2", "react-router-dom": "^6.24.0", @@ -4842,6 +4843,14 @@ "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==", "license": "MIT" }, + "node_modules/react-loading-skeleton": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/react-loading-skeleton/-/react-loading-skeleton-3.4.0.tgz", + "integrity": "sha512-1oJEBc9+wn7BbkQQk7YodlYEIjgeR+GrRjD+QXkVjwZN7LGIcAFHrx4NhT7UHGBxNY1+zax3c+Fo6XQM4R7CgA==", + "peerDependencies": { + "react": ">=16.8.0" + } + }, "node_modules/react-parallax-tilt": { "version": "1.7.232", "resolved": "https://registry.npmjs.org/react-parallax-tilt/-/react-parallax-tilt-1.7.232.tgz", diff --git a/frontend/package.json b/frontend/package.json index 254593c..dc06007 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -33,6 +33,7 @@ "react-fast-marquee": "^1.6.4", "react-hot-toast": "^2.4.1", "react-icons": "^5.2.1", + "react-loading-skeleton": "^3.4.0", "react-parallax-tilt": "^1.7.231", "react-responsive-modal": "^6.4.2", "react-router-dom": "^6.24.0", From 9c46aed50cf23fa79a529a772c19d765ac8ce337 Mon Sep 17 00:00:00 2001 From: Utsavladia Date: Thu, 8 Aug 2024 19:03:25 +0530 Subject: [PATCH 12/13] Fixed build error --- frontend/src/pages/Posts.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/pages/Posts.tsx b/frontend/src/pages/Posts.tsx index 82a1fb7..c2f4192 100644 --- a/frontend/src/pages/Posts.tsx +++ b/frontend/src/pages/Posts.tsx @@ -1,5 +1,4 @@ import { useEffect, useState, useRef } from "react"; -import Loader from "../components/Loader"; import PostCard from "../components/PostCard"; import { userState } from "../store/atoms/auth"; import { useRecoilValue } from "recoil"; From accf63f4016aca3642661a4a78925bc1ef30e2b0 Mon Sep 17 00:00:00 2001 From: meet Date: Thu, 8 Aug 2024 20:22:16 +0530 Subject: [PATCH 13/13] Added contact messages delete feature for admin --- admin/src/pages/ContactMessages.tsx | 24 +++++++++++++++++++++++- backend/src/routes/admin/controller.ts | 19 +++++++++++++++++++ backend/src/routes/admin/route.ts | 4 +++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/admin/src/pages/ContactMessages.tsx b/admin/src/pages/ContactMessages.tsx index 9c74662..d9d63a8 100644 --- a/admin/src/pages/ContactMessages.tsx +++ b/admin/src/pages/ContactMessages.tsx @@ -9,6 +9,7 @@ import '../styles/Model.css' import { ColorRing } from 'react-loader-spinner'; import { MdMessage } from "react-icons/md"; import { TbReportAnalytics } from "react-icons/tb"; +import toast from "react-hot-toast"; const ContactMessages = () => { const [contactMessages, setContactMessages] = useState([]); @@ -59,6 +60,21 @@ const ContactMessages = () => { } }; + const handleDeleteMessage = async (id: string) => { + try { + await axios.delete(`/api/v1/admin/deletecontactmessage/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + setContactMessages(contactMessages.filter((msg) => msg.id !== id)); + toast.success("Contact Message deleted successfully !") + } catch (error) { + console.error("Error deleting message:", error); + toast.error("Error in deleting message") + } + }; + const handleOpenModal = (message: IContactMessage) => { setSelectedMessage(message); setOpen(true); @@ -114,7 +130,7 @@ const ContactMessages = () => { {new Date(contactMessage.createdAt).toLocaleDateString()} {contactMessage.subject.slice(0, 10)} {contactMessage.message.slice(0, 10)} - + ))} diff --git a/backend/src/routes/admin/controller.ts b/backend/src/routes/admin/controller.ts index d4bfdbc..78f0365 100644 --- a/backend/src/routes/admin/controller.ts +++ b/backend/src/routes/admin/controller.ts @@ -1088,4 +1088,23 @@ export const downloadFavoritesReportController = async (req: Request, res: Respo error: "An unexpected exception occurred!", }); } +}; + +export const deleteContactMessage = async (req: Request, res: Response) => { + const { id } = req.params; + + try { + const deletedMessage = await prisma.contactMessage.delete({ + where: { id }, + }); + + res.status(200).json({ + message: "Contact message deleted successfully!", + deletedMessage, + }); + } catch (error) { + res.status(500).json({ + error: "An error occurred while deleting the contact message!", + }); + } }; \ No newline at end of file diff --git a/backend/src/routes/admin/route.ts b/backend/src/routes/admin/route.ts index 2483c73..6388864 100644 --- a/backend/src/routes/admin/route.ts +++ b/backend/src/routes/admin/route.ts @@ -1,5 +1,5 @@ import {Router} from 'express'; -import { getPostReactionsController,getFavoritesController,adminLoginController, adminProfileController, allUserForAdmin, blockUserController, unblockUserController, getAdminPostsController, getAdminTrendingPostsController, getAdminStatsController, getGraphsStatsController, updatePostController, deletePostController, getPostByIdController, getAllContactMessages, deleteCommentController, downloadReportController, getFeedbacks, toggleFeedbackVisibility, downloadCommentsReportController, downloadFavoritesReportController, downloadReactionsReportController, downloadUsersReportController, downloadContactMessagesReportController, downloadPostsReportController } from './controller'; +import { getPostReactionsController,getFavoritesController,adminLoginController, adminProfileController, allUserForAdmin, blockUserController, unblockUserController, getAdminPostsController, getAdminTrendingPostsController, getAdminStatsController, getGraphsStatsController, updatePostController, deletePostController, getPostByIdController, getAllContactMessages, deleteCommentController, downloadReportController, getFeedbacks, toggleFeedbackVisibility, downloadCommentsReportController, downloadFavoritesReportController, downloadReactionsReportController, downloadUsersReportController, downloadContactMessagesReportController, downloadPostsReportController, deleteContactMessage } from './controller'; import { isAdmin } from '../../middleware/adminAuth'; const adminRouter = Router(); @@ -54,4 +54,6 @@ adminRouter.get("/downloadusersfavoritesreport", downloadFavoritesReportControll adminRouter.get("/downloadusersreactionreport", downloadReactionsReportController); +adminRouter.delete("/deletecontactmessage/:id", isAdmin, deleteContactMessage); + export default adminRouter; \ No newline at end of file