Refactor how we output favorite bool on parties
This commit is contained in:
parent
8d9b434d1e
commit
07dc8dd457
5 changed files with 27 additions and 25 deletions
|
|
@ -2,19 +2,6 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
|||
before_action :set_from_slug, except: ['create', 'update', 'index', 'favorites']
|
||||
before_action :set, only: ['update', 'destroy']
|
||||
|
||||
def index
|
||||
now = DateTime.current
|
||||
start_time = (now - params['recency'].to_i.seconds).to_datetime.beginning_of_day unless request.params['recency'].blank?
|
||||
|
||||
conditions = {}
|
||||
conditions[:element] = request.params['element'] unless request.params['element'].blank?
|
||||
conditions[:raid] = request.params['raid'] unless request.params['raid'].blank?
|
||||
conditions[:created_at] = start_time..now unless request.params['recency'].blank?
|
||||
|
||||
@parties = Party.where(conditions)
|
||||
render :all, status: :ok
|
||||
end
|
||||
|
||||
def create
|
||||
@party = Party.new(shortcode: random_string)
|
||||
@party.extra = party_params['extra']
|
||||
|
|
@ -27,14 +14,32 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
|||
end
|
||||
|
||||
def show
|
||||
@favorited = (current_user) ? @party.is_favorited(current_user) : false
|
||||
render_not_found_response if @party.nil?
|
||||
end
|
||||
|
||||
def index
|
||||
now = DateTime.current
|
||||
start_time = (now - params['recency'].to_i.seconds).to_datetime.beginning_of_day unless request.params['recency'].blank?
|
||||
|
||||
conditions = {}
|
||||
conditions[:element] = request.params['element'] unless request.params['element'].blank?
|
||||
conditions[:raid] = request.params['raid'] unless request.params['raid'].blank?
|
||||
conditions[:created_at] = start_time..now unless request.params['recency'].blank?
|
||||
|
||||
@parties = Party.where(conditions).each { |party|
|
||||
party.favorited = (current_user) ? party.is_favorited(current_user) : false
|
||||
}
|
||||
|
||||
render :all, status: :ok
|
||||
end
|
||||
|
||||
def favorites
|
||||
raise Api::V1::UnauthorizedError unless current_user
|
||||
|
||||
@parties = current_user.favorite_parties
|
||||
@parties = current_user.favorite_parties.each { |party|
|
||||
party.favorited = party.is_favorited(current_user)
|
||||
}
|
||||
|
||||
render :all, status: :ok
|
||||
end
|
||||
|
||||
|
|
@ -80,6 +85,7 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
|||
|
||||
def set_from_slug
|
||||
@party = Party.where("shortcode = ?", params[:id]).first
|
||||
@party.favorited = (current_user) ? @party.is_favorited(current_user) : false
|
||||
end
|
||||
|
||||
def set
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
object :party
|
||||
|
||||
attributes :id, :name, :description, :element, :shortcode, :created_at, :updated_at
|
||||
attributes :id, :name, :description, :element, :favorited, :shortcode, :created_at, :updated_at
|
||||
|
||||
node :is_extra do |p|
|
||||
node :extra do |p|
|
||||
p.extra
|
||||
end
|
||||
|
||||
node :is_favorite do |p|
|
||||
@favorited
|
||||
end
|
||||
|
||||
node :user do |p|
|
||||
partial('users/base', :object => p.user)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
object @party
|
||||
|
||||
attributes :id, :name, :description, :shortcode
|
||||
attributes :id, :name, :description, :shortcode, :favorited, :created_at, :updated_at
|
||||
|
||||
node :user do |p|
|
||||
partial('users/base', :object => p.user)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
object @party
|
||||
|
||||
attributes :id, :name, :description, :shortcode
|
||||
attributes :id, :name, :description, :shortcode, :favorited, :created_at, :updated_at
|
||||
|
||||
node :user do |p|
|
||||
partial('users/base', :object => p.user)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
object @party
|
||||
|
||||
attributes :id, :name, :description, :shortcode
|
||||
attributes :id, :name, :description, :shortcode, :favorited, :created_at, :updated_at
|
||||
|
||||
node :user do |p|
|
||||
partial('users/base', :object => p.user)
|
||||
|
|
@ -10,7 +10,7 @@ node :raid do |p|
|
|||
partial('raids/base', :object => p.raid)
|
||||
end
|
||||
|
||||
node :is_extra do |p|
|
||||
node :extra do |p|
|
||||
p.extra
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue