Skip to content

Commit

Permalink
feat: implement show action
Browse files Browse the repository at this point in the history
  • Loading branch information
shaojunda committed Oct 15, 2019
1 parent 1d55c2e commit 9c91623
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/controllers/api/v1/contract_transactions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
module Api
module V1
class ContractTransactionsController < ApplicationController
before_action :validate_pagination_params, :pagination_params

def show
render json: {}
raise Api::V1::Exceptions::ContractNotFoundError if params[:id] != "dao"
dao_contract = DaoContract.default_contract
ckb_transactions = dao_contract.ckb_transactions.distinct.recent.page(@page).per(@page_size)
options = FastJsonapi::PaginationMetaGenerator.new(request: request, records: ckb_transactions, page: @page, page_size: @page_size).call

render json: CkbTransactionSerializer.new(ckb_transactions, options.merge({ params: { previews: true } }))
end

private

def pagination_params
@page = params[:page] || 1
@page_size = params[:page_size] || CkbTransaction.default_per_page
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/dao_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ class DaoContract < ApplicationRecord
def self.default_contract
find_or_create_by(id: 1)
end

def ckb_transactions
ckb_transaction_ids = CellOutput.dao.select("ckb_transaction_id")
CkbTransaction.where(id: ckb_transaction_ids)
end
end

# == Schema Information
Expand Down

0 comments on commit 9c91623

Please sign in to comment.