Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/resources/decklist_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ class DecklistResource < ApplicationResource
end
end

# Will return decklists where every card has at least one printing in the specified card set(s).
# Multiple values are treated as the union of card sets, matching the legacy /decklist/find?packs[] behavior.
filter :card_set_id, :string do
eq do |scope, card_set_ids|
card_ids = Printing.where(card_set_id: card_set_ids).select(:card_id)
decklists_with_other_cards = DecklistCard.where.not(card_id: card_ids).select(:decklist_id)
scope.where.not(id: decklists_with_other_cards)
end
end

attribute :card_slots, :hash
attribute :num_cards, :integer
attribute :influence_spent, :integer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddCardIdDecklistIdIndexToDecklistsCards < ActiveRecord::Migration[8.1]
def change
add_index :decklists_cards, %i[card_id decklist_id]
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2026_05_20_044700) do
ActiveRecord::Schema[8.1].define(version: 2026_05_22_120000) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pgcrypto"
Expand Down Expand Up @@ -182,6 +182,7 @@
t.string "card_id", null: false
t.uuid "decklist_id", null: false
t.integer "quantity", null: false
t.index ["card_id", "decklist_id"], name: "index_decklists_cards_on_card_id_and_decklist_id"
t.index ["decklist_id", "card_id"], name: "index_decklists_cards_on_decklist_id_and_card_id", unique: true
end

Expand Down
38 changes: 38 additions & 0 deletions spec/resources/decklist_resource_reads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,44 @@
end
end

context 'with card_set_id' do
let!(:corp_decklist) { Decklist.find('11111111-1111-1111-1111-111111111111') }
let!(:runner_decklist) { Decklist.find('22222222-2222-2222-2222-222222222222') }

it 'returns decklists whose cards all have a printing in the set' do
params[:filter] = { card_set_id: { eq: 'core' } }
render
decklist_ids = d.map(&:id)

expect(decklist_ids).to include(corp_decklist.id)
expect(decklist_ids).to include(runner_decklist.id)
end

it 'excludes decklists with any card not printed in the set' do
params[:filter] = { card_set_id: { eq: 'midnight_sun' } }
render
decklist_ids = d.map(&:id)

expect(decklist_ids).not_to include(corp_decklist.id)
expect(decklist_ids).not_to include(runner_decklist.id)
end

it 'treats multiple card sets as a union of legal cards' do
params[:filter] = { card_set_id: { eq: 'core,midnight_sun' } }
render
decklist_ids = d.map(&:id)

expect(decklist_ids).to include(corp_decklist.id)
expect(decklist_ids).to include(runner_decklist.id)
end

it 'combines with faction_id' do
params[:filter] = { card_set_id: { eq: 'core' }, faction_id: { eq: 'criminal' } }
render
expect(d.map(&:id)).to eq([runner_decklist.id])
end
end

context 'with card_id and exclude_card_id combined' do
let!(:corp_decklist) { Decklist.find('11111111-1111-1111-1111-111111111111') }
let!(:runner_decklist) { Decklist.find('22222222-2222-2222-2222-222222222222') }
Expand Down
Loading