From ade32b4da846554a781eb785ae298dd9096cb97f Mon Sep 17 00:00:00 2001 From: Lionel Kubwimana Date: Thu, 11 Apr 2024 19:49:32 +0200 Subject: [PATCH] Update method to use namespacing and add scopes for filtering --- app/controllers/api/v1/curura/rankings_controller.rb | 3 +-- app/models/curura/game.rb | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/curura/rankings_controller.rb b/app/controllers/api/v1/curura/rankings_controller.rb index 5376cb2..e4d1346 100644 --- a/app/controllers/api/v1/curura/rankings_controller.rb +++ b/app/controllers/api/v1/curura/rankings_controller.rb @@ -24,8 +24,7 @@ def set_leaderboards end def games - binding.pry - @games ||= CururaGame.today + @games ||= ::Curura::Game.today end def country diff --git a/app/models/curura/game.rb b/app/models/curura/game.rb index 89af1d5..eae16f9 100644 --- a/app/models/curura/game.rb +++ b/app/models/curura/game.rb @@ -1,3 +1,7 @@ class Curura::Game < ApplicationRecord validates :score, :country, :start_time, presence: true + + scope :today, -> { where("start_time >= ?", Time.zone.now.beginning_of_day) } + scope :won_above_score, ->(score) { where("score > ?", score) } + scope :country, ->(country) { where(country: country) } end