Skip to content

Commit

Permalink
Merge pull request #100 from Arquisoft/rankings
Browse files Browse the repository at this point in the history
Rankings
  • Loading branch information
ChristianFN2 authored Apr 7, 2024
2 parents b5b4eff + 747e829 commit 626c3b0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
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

0 comments on commit 626c3b0

Please sign in to comment.