Skip to content

Commit

Permalink
Merge pull request #392 from MeetDOD/issue-379
Browse files Browse the repository at this point in the history
Feat: Removed like/dislikes and created logic for reactions on leaderboard successfully issue 379
  • Loading branch information
Ultimateutkarsh11 authored Jul 9, 2024
2 parents e0cc977 + 7964c6c commit 712505c
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 24 deletions.
2 changes: 0 additions & 2 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ model Post {
author User @relation("authorPosts", fields: [authorId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
likes Int @default(0)
dislikes Int @default(0)
comments Comment[] @relation("postComments")
favorites Favorite[] @relation("postFavorites")
reactions Reaction[]
Expand Down
1 change: 0 additions & 1 deletion backend/src/routes/admin/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export const getAdminTrendingPostsController = async (req: Request, res: Respons
jsCodeSnippet: true,
description: true,
tags: true,
likes:true,
createdAt:true,
comments:true,
author: {
Expand Down
18 changes: 10 additions & 8 deletions backend/src/routes/post/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ export const getPostController = async (req: Request, res: Response) => {
jsCodeSnippet: true,
description: true,
tags: true,
likes: true,
dislikes: true,
author: {
select: {
id: true,
Expand Down Expand Up @@ -581,30 +579,34 @@ export const getLeaderboardController = async (req: Request, res: Response) => {
},
posts: {
select: {
likes: true,
reactions: {
select: {
id: true,
},
},
},
},
},
});

const userLikes = leaderboard.map((user) => ({
const userReactions = leaderboard.map((user) => ({
id: user.id,
username: user.username,
postCount: user._count.posts,
totalLikes: user.posts.reduce((sum, post) => sum + post.likes, 0),
totalReactions: user.posts.reduce((sum, post) => sum + post.reactions.length, 0),
}));

userLikes.sort((a, b) => b.totalLikes - a.totalLikes);
userReactions.sort((a, b) => b.totalReactions - a.totalReactions);

const top10Users = userLikes.slice(0, 10);
const top10Users = userReactions.slice(0, 10);

res.status(200).json({
leaderboard: top10Users.map((user, index) => ({
rank: index + 1,
userId: user.id,
username: user.username,
postCount: user.postCount,
totalLikes: user.totalLikes,
totalReactions: user.totalReactions,
})),
});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"profile": "Profile",
"username": "Username",
"posts": "Posts",
"likes": "Likes"
"reactions": "Reactions"
},
"newPost":{
"createPost": "Create New Post",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/guj/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"profile": "પ્રોફાઇલ",
"username": "વપરાશકર્તા નામ",
"posts": "પોસ્ટ્સ",
"likes": "લાઈક્સ"
"reactions": "પ્રતિક્રિયાઓ"
},
"newPost": {
"createPost": "નવી પોસ્ટ બનાવો",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"profile": "प्रोफ़ाइल",
"username": "उपयोगकर्ता नाम",
"posts": "पोस्ट्स",
"likes": "पसंद"
"reactions": "प्रतिक्रियाओं"
},
"newPost": {
"createPost": "नई पोस्ट बनाएं",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/mh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"profile": "प्रोफाइल",
"username": "वापरकर्तानाव",
"posts": "पोस्ट्स",
"likes": "लाइक्स"
"reactions": "प्रतिक्रिया"
},
"newPost":{
"createPost": "नवीन पोस्ट तयार करा",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/tam/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
"profile": "சுயவிவரம்",
"username": "பயனர்பெயர்",
"posts": "பதிவுகள்",
"likes": "விருப்புகள்"
"reactions": "எதிர்வினைகள்"
},
"newPost": {
"createPost": "புதிய பதிவை உருவாக்கு",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/tel/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
"profile": "ప్రొఫైలు",
"username": "వాడుకరి పేరు",
"posts": "పోస్టులు",
"likes": "లైక్లు"
"reactions": "ప్రతిచర్యలు"
},
"newPost": {
"createPost": "కొత్త పోస్ట్ రేఖలు",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/ur/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"profile": "پروفائل",
"username": "یوزر نام",
"posts": "پوسٹس",
"likes": "پسند"
"reactions": "رد عمل"
},
"newPost": {
"createPost": "نئی پوسٹ بنائیں",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/wb/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"profile": "প্রোফাইল",
"username": "ব্যবহারকারীর নাম",
"posts": "পোস্টসমূহ",
"likes": "লাইকসমূহ"
"reactions": "প্রতিক্রিয়া"
},
"newPost": {
"createPost": "নতুন পোস্ট তৈরি করুন",
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/pages/LeaderBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const LeaderBoard = () => {
document.title='Style Share | Top users 😎'

return (
<div className="-mt-7 min-h-screen text-[#000435] bg-white dark:text-white dark:bg-[#000435]" style={{ backgroundImage: `url(${bgHero})`, backgroundSize: 'cover', backgroundPosition: 'center' }}>
<div className="min-h-screen text-[#000435] bg-white dark:text-white dark:bg-[#000435]" style={{ backgroundImage: `url(${bgHero})`, backgroundSize: 'cover', backgroundPosition: 'center' }}>
<div className="p-3 mb-10 text-[#000435] bg-white dark:text-white dark:bg-[#000435]" style={{ backgroundImage: `url(${bgHero})`, backgroundSize: 'cover', backgroundPosition: 'center' }}>
<h2 className="text-3xl text-[#5f67de] bg-white dark:text-white dark:bg-[#000435] font-bold text-center mb-8">{t("navbar.links.leaderboard")} 🥳</h2>
<div className="shadow-md text-[#5f67de] bg-white dark:text-white dark:bg-[#000435] backdrop-blur-sm rounded-lg p-4 border-2 border-sky-500 lg:mx-52 md:mx-20 overflow-x-auto">
Expand All @@ -28,11 +28,11 @@ const LeaderBoard = () => {
<table className="min-w-full divide-y divide-gray-200">
<thead className="text-center text-sm font-medium text-[#000435] bg-white dark:text-white dark:bg-[#5f67de] border-b-2 border-sky-600">
<tr>
<th scope="col" className="px-2 py-3 sm:px-6 text-[#5f67de] bg-white dark:text-white dark:bg-[#000435] uppercase tracking-wider">{t("leaderboard.rank")}</th> {/* Adjusted padding for small screens */}
<th scope="col" className="px-2 py-3 sm:px-6 text-[#5f67de] bg-white dark:text-white dark:bg-[#000435] uppercase tracking-wider">{t("leaderboard.rank")}</th>
<th scope="col" className="px-2 py-3 sm:px-6 text-[#5f67de] bg-white dark:text-white dark:bg-[#000435] uppercase tracking-wider">{t("leaderboard.profile")}</th>
<th scope="col" className="px-2 py-3 sm:px-6 text-[#5f67de] bg-white dark:text-white dark:bg-[#000435] uppercase tracking-wider">{t("leaderboard.username")}</th>
<th scope="col" className="px-2 py-3 sm:px-6 text-[#5f67de] bg-white dark:text-white dark:bg-[#000435] uppercase tracking-wider">{t("leaderboard.posts")}</th>
<th scope="col" className="px-2 py-3 sm:px-6 text-[#5f67de] bg-white dark:text-white dark:bg-[#000435] uppercase tracking-wider">{t("leaderboard.likes")}</th>
<th scope="col" className="px-2 py-3 sm:px-6 text-[#5f67de] bg-white dark:text-white dark:bg-[#000435] uppercase tracking-wider">{t("leaderboard.reactions")}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -62,7 +62,7 @@ const LeaderBoard = () => {
<div className="text-sm text-[#000435] dark:text-gray-50">{user.postCount}</div>
</td>
<td className="px-2 py-4 sm:px-6">
<div className="text-sm text-[#000435] dark:text-gray-50">{user.totalLikes}</div>
<div className="text-sm text-[#000435] dark:text-gray-50">{user.totalReactions}</div>
</td>
</tr>
))}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ export interface ILeaderboardUser {
userId: string;
username: string;
postCount: number;
totalLikes:number;
totalReactions:number;
}

0 comments on commit 712505c

Please sign in to comment.