Skip to content

Commit

Permalink
fix: add sorting to search results
Browse files Browse the repository at this point in the history
  • Loading branch information
KaemonIsland committed Sep 16, 2022
1 parent 6754c50 commit d18d807
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/controllers/api/v1/cards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def search_with_collection
.per(params[:per_page] || 30)

render 'api/v1/cards/cards.json.jbuilder', status: 200
end
end

def search_with_deck
@deck = Deck.find(params[:deck_id])
Expand All @@ -44,9 +44,9 @@ def search_with_deck

def load_query
if params[:q][:collection_only] && @collection
@query = @collection.cards.with_color(params[:colors], Card).ransack(params[:q])
@query = @collection.cards.with_color(params[:colors], Card).order("original_release_date ASC").ransack(params[:q])
else
@query = Card.with_color(params[:colors], Card).ransack(params[:q])
@query = Card.with_color(params[:colors], Card).order("original_release_date ASC").ransack(params[:q])
end

@sorted_cards = Card.sort_by_color(@query.result.by_mana_and_name.limit(500))
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/decks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Api::V1::DecksController < ApplicationController

def index
if current_user
@decks = current_user.decks.order(updated_at: :desc)
@decks = current_user.decks.order(updated_at: :desc)
render 'api/v1/decks/decks.json.jbuilder', status: 200
else
render json: { error: 'User must be signed in' }, status: 401
Expand Down
2 changes: 1 addition & 1 deletion app/models/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def self.sort_by_color(cards)
C: [],
}

cards.each do |card|
cards.each do |card|
card_colors = card.color_identity

if card_colors.empty?
Expand Down

0 comments on commit d18d807

Please sign in to comment.