44 lines
1.2 KiB
Ruby
44 lines
1.2 KiB
Ruby
|
class LootController < ApplicationController
|
||
|
skip_before_action :verify_authenticity_token, only: [ :create ]
|
||
|
before_action :authenticate, only: [ :create ]
|
||
|
|
||
|
respond_to? :json
|
||
|
|
||
|
def create
|
||
|
@loot = Loot.new(item_id: params[:item_id], item_name: params[:item_name], timestamp: params[:timestamp], roll_type: params[:roll_type])
|
||
|
|
||
|
player = Player.find_by(name: params[:player])
|
||
|
if player.nil?
|
||
|
player = Player.new(name: params[:player], wins: 0, losses: 0, purse: 0)
|
||
|
player.save
|
||
|
end
|
||
|
@loot.player = player
|
||
|
|
||
|
if @loot.save
|
||
|
render json: {}, status: :ok
|
||
|
else
|
||
|
render json: { error: "Unable to process input" }, status: :unprocessable_content
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def index
|
||
|
@players = Player.all.reject(&:alt?).map { |player| [
|
||
|
player.name,
|
||
|
player.get_loot_count_with_roll("mainspec"),
|
||
|
player.get_loot_count_with_roll("minor"),
|
||
|
player.get_loot_count_with_roll("offspec"),
|
||
|
player.get_loot_count_with_roll("transmog"),
|
||
|
]}.sort
|
||
|
end
|
||
|
|
||
|
def list
|
||
|
@loot = Loot.all.sort_by &:timestamp
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def already_reported_response
|
||
|
render json: { error: "Already reported this loot" }, status: :already_reported
|
||
|
end
|
||
|
end
|