File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,15 @@ class DecklistResource < ApplicationResource
36
36
end
37
37
end
38
38
39
+ # Will return decklists that do NOT contain any of the specified cards.
40
+ filter :exclude_card_id , :string do
41
+ eq do |scope , card_ids |
42
+ scope . left_joins ( :decklist_cards )
43
+ . group ( 'decklists.id' )
44
+ . having ( 'COUNT(CASE WHEN decklists_cards.card_id IN (?) THEN 1 END) = 0' , card_ids )
45
+ end
46
+ end
47
+
39
48
attribute :card_slots , :hash
40
49
attribute :num_cards , :integer
41
50
attribute :influence_spent , :integer
Original file line number Diff line number Diff line change 50
50
end
51
51
end
52
52
53
+ get '/api/v3/public/decklists?filter[exclude_card_id]=pennyshaver,stargate' do
54
+ parameter :exclude_card_id , type : :string , required : true
55
+
56
+ example_request 'Filter - Get decklists excluding all supplied Card ids' do
57
+ explanation <<~EXPLANATION
58
+ The exclude_card_id filter can accept a single card_id or a comma-separated list of card ids.
59
+
60
+ If multiple card ids are supplied, the decklist must NOT contain any of the
61
+ cards to be included in the results.
62
+ EXPLANATION
63
+
64
+ expect ( status ) . to eq 200
65
+ end
66
+ end
67
+
53
68
get '/api/v3/public/decklists?filter[faction_id]=:faction_id' do
54
69
parameter :nsg_rules_team_verified , type : :boolean , required : true
55
70
Original file line number Diff line number Diff line change 42
42
expect ( d . map ( &:id ) ) . to eq ( [ decklist . id ] )
43
43
end
44
44
end
45
+
46
+ context 'with exclude_card_id' do
47
+ let! ( :corp_decklist ) { Decklist . find ( '11111111-1111-1111-1111-111111111111' ) }
48
+ let! ( :runner_decklist ) { Decklist . find ( '22222222-2222-2222-2222-222222222222' ) }
49
+
50
+ it 'excludes decklists with one specified card' do
51
+ params [ :filter ] = { exclude_card_id : { eq : 'pennyshaver' } }
52
+
53
+ render
54
+ decklist_ids = d . map ( &:id )
55
+
56
+ expect ( decklist_ids ) . to include ( corp_decklist . id )
57
+ expect ( decklist_ids ) . not_to include ( runner_decklist . id )
58
+ end
59
+
60
+ it 'excludes decklists with multiple specified cards' do
61
+ params [ :filter ] =
62
+ { exclude_card_id : { eq : 'pennyshaver,adonis_campaign' } }
63
+ render
64
+ decklist_ids = d . map ( &:id )
65
+
66
+ expect ( decklist_ids ) . not_to include ( corp_decklist . id )
67
+ expect ( decklist_ids ) . not_to include ( runner_decklist . id )
68
+ end
69
+
70
+ it 'exludes no decklists when nonexistent card is specified' do
71
+ params [ :filter ] = { exclude_card_id : { eq : 'nonexistent_card' } }
72
+ render
73
+ decklist_ids = d . map ( &:id )
74
+
75
+ expect ( decklist_ids ) . to include ( corp_decklist . id )
76
+ expect ( decklist_ids ) . to include ( runner_decklist . id )
77
+ end
78
+ end
45
79
end
46
80
47
81
describe 'sideloading' do
You can’t perform that action at this time.
0 commit comments