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
6 changes: 3 additions & 3 deletions app/controllers/snapshots_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
class SnapshotsController < ApplicationController
def index
add_total_stat(params)

base_scope = Snapshot.includes(:card_pool, :cards, :restriction)
base_scope = Snapshot.includes(:card_pool)
snapshots = SnapshotResource.all(params, base_scope)

respond_with(snapshots)
end

def show
snapshot = SnapshotResource.find(params)
base_scope = Snapshot.includes(:card_pool)
snapshot = SnapshotResource.find(params, base_scope)
respond_with(snapshot)
end
end
2 changes: 1 addition & 1 deletion app/models/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class Snapshot < ApplicationRecord

# TODO(plural): Convert date_start to a real date field.
def num_cards
cards.length
cards.count
end
end
8 changes: 5 additions & 3 deletions app/resources/snapshot_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
class SnapshotResource < ApplicationResource
primary_endpoint '/snapshots', %i[index show]

self.default_page_size = 1000

attribute :id, :string
attribute :format_id, :string
attribute :active, :boolean
attribute :card_cycle_ids, :array_of_strings do
@object.card_pool.card_pool_card_cycles.pluck(:card_cycle_id)
@object.card_cycle_ids
end
attribute :card_set_ids, :array_of_strings do
@object.card_pool.card_pool_card_sets.pluck(:card_set_id)
@object.card_set_ids
end
attribute :card_pool_id, :string
attribute :restriction_id, :string
attribute :num_cards, :integer do
@object.card_pool.cards.length
@object.card_pool.cards.count
end
attribute :date_start, :date
attribute :updated_at, :datetime
Expand Down