diff --git a/app.rb b/app.rb index 25fe181..c20d5fb 100644 --- a/app.rb +++ b/app.rb @@ -31,10 +31,11 @@ post '/' do end end -get '/bossfight/:username' do - username = params['username'] ? params['username'] : 'mafiaman' - user_raids = Raid.for_user(username) +get '/bossfight/?:username' do + @username = params['username'] ? params['username'] : 'mafiaman' + user_raids = Raid.for_user(@username) @first_negative = user_raids.first_negative + @soldiers_lost_to_date = user_raids.soldiers_lost_to_date(@first_negative.created_at) erb :bossfight end diff --git a/models/raid.rb b/models/raid.rb index c6ad3cd..6e35fec 100644 --- a/models/raid.rb +++ b/models/raid.rb @@ -16,4 +16,8 @@ class Raid < ActiveRecord::Base def self.first_negative where('money < 0').order(:created_at).first end + + def self.soldiers_lost_to_date(date) + where('date < ?', date).sum(:soldiers) + end end diff --git a/views/bossfight.erb b/views/bossfight.erb index 367f9d6..c82a135 100644 --- a/views/bossfight.erb +++ b/views/bossfight.erb @@ -1,3 +1,9 @@ +