Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rankings #100

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions users/userservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions users/userservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"bcrypt": "^5.1.1",
"body-parser": "^1.20.2",
"express": "^4.18.2",
"mongoose": "^8.0.4",
"ramda": "^0.29.1"
"mongoose": "^8.0.4"
},
"devDependencies": {
"jest": "^29.7.0",
Expand Down
9 changes: 3 additions & 6 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const express = require('express');
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
const bodyParser = require('body-parser');
const R = require('ramda');

const User = require('./user-model')

Expand Down Expand Up @@ -45,10 +44,8 @@ app.get('/rankings/:filter', async (req, res) => {
const userRanking = getRankingFor(loggedUser) */

const category = req.params.filter;
const usersRanking = (await User.find());
const ascendingUsers = R.sortBy(R.prop("ranking." + category + ".points"), usersRanking);
const sortedUsers = R.reverse(ascendingUsers);
const sortedRanking = sortedUsers.map( (user, index) => {
const usersRanking = (await User.find()).sort((a, b) => b.ranking[category].points - a.ranking[category].points)
.map((user, index) => {
return {
// User global data
name: user.username,
Expand All @@ -61,7 +58,7 @@ app.get('/rankings/:filter', async (req, res) => {
})

//res.json(userRanking, usersRanking)
res.json(sortedRanking)
res.status(200).json(usersRanking)
} catch (error) {
res.status(400).json({ error: error.message });
}
Expand Down
8 changes: 6 additions & 2 deletions webapp/src/components/ranking/RankingLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ const RankingsLayout = () => {
Monuments
</button>
<button className="flex items-center px-4 py-2 text-gray-100 rounded-lg hover:bg-[#73689b]"
onClick={() => handleFilterClick('food')}>
Food
onClick={() => handleFilterClick('foods')}>
Foods
</button>
<button className="flex items-center px-4 py-2 text-gray-100 rounded-lg hover:bg-[#73689b]"
onClick={() => handleFilterClick('tourist_attractions')}>
Attractions
</button>
</nav>
</div>
Expand Down
Loading