Add method for displaying a user's favorites
This commit is contained in:
parent
a45193d1b8
commit
7feb5157c8
1 changed files with 21 additions and 15 deletions
|
|
@ -1,7 +1,20 @@
|
|||
class Api::V1::PartiesController < Api::V1::ApiController
|
||||
before_action :set_from_slug, except: ['create', 'update', 'index']
|
||||
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)
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
@party = Party.new(shortcode: random_string)
|
||||
@party.extra = party_params['extra']
|
||||
|
|
@ -17,6 +30,13 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
|||
render_not_found_response if @party.nil?
|
||||
end
|
||||
|
||||
def favorites
|
||||
raise Api::V1::UnauthorizedError unless current_user
|
||||
|
||||
@parties = current_user.favorite_parties
|
||||
render :all, status: :ok
|
||||
end
|
||||
|
||||
def update
|
||||
if @party.user != current_user
|
||||
render_unauthorized_response
|
||||
|
|
@ -49,20 +69,6 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
|||
render :characters, status: :ok
|
||||
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)
|
||||
|
||||
render :all, status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def random_string
|
||||
|
|
|
|||
Loading…
Reference in a new issue