Enable filtering list of favorite parties

This commit is contained in:
Justin Edmund 2022-02-27 22:52:25 -08:00
parent 86640d5986
commit 186fde79be
3 changed files with 10 additions and 4 deletions

View file

@ -36,7 +36,13 @@ class Api::V1::PartiesController < Api::V1::ApiController
def favorites
raise Api::V1::UnauthorizedError unless current_user
@parties = current_user.favorite_parties.each { |party|
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?
conditions[:favorites] = { user_id: current_user.id }
@parties = Party.joins(:favorites).where(conditions).each { |party|
party.favorited = party.is_favorited(current_user)
}

View file

@ -1,6 +1,6 @@
class Favorite < ApplicationRecord
belongs_to :user
has_one :party
belongs_to :party
def party
Party.find(self.party_id)

View file

@ -2,12 +2,12 @@ class Party < ApplicationRecord
##### ActiveRecord Associations
belongs_to :user, optional: true
belongs_to :raid, optional: true
belongs_to :favorite, optional: true
has_many :characters, foreign_key: "party_id", class_name: "GridCharacter", dependent: :destroy
has_many :weapons, foreign_key: "party_id", class_name: "GridWeapon", dependent: :destroy
has_many :summons, foreign_key: "party_id", class_name: "GridSummon", dependent: :destroy
has_many :favorites
attr_accessor :favorited
def is_favorited(user)