From d129a403ff0248f3c43db4984adada1178cefb23 Mon Sep 17 00:00:00 2001
From: tmn21 <tmn21@inf.ufpr.br>
Date: Tue, 16 May 2023 11:40:15 -0300
Subject: [PATCH] ISSUE #41: UPDATE top_users route

---
 app/controllers/v1/users_controller.rb | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/app/controllers/v1/users_controller.rb b/app/controllers/v1/users_controller.rb
index 5fdc1d08..de41f351 100644
--- a/app/controllers/v1/users_controller.rb
+++ b/app/controllers/v1/users_controller.rb
@@ -178,9 +178,12 @@ class V1::UsersController < ApplicationController
     render status: :ok, json: response
   end
 
+  # GET /v1/top_users
   def show_top_users
-    # select id, level from users order by level desc limit 5;
-    users = paginate User.all.order("level DESC").limit(6)
+    # select users who are not admin and order by level, limit to 5 users
+    ids = User.joins(:roles_users).where(roles_users: {role_id: 3}).pluck(:user_id)
+    users = User.where.not(id: ids).order("level DESC").limit(5)
+
     render json: users
   end
 
-- 
GitLab