-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1559 from nervosnetwork/develop
Deploy to testnet
- Loading branch information
Showing
32 changed files
with
2,406 additions
and
966 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
module Api | ||
module V1 | ||
class OmigaInscriptionsController < ApplicationController | ||
before_action :validate_query_params, only: :show | ||
before_action :validate_pagination_params, :pagination_params, | ||
only: :index | ||
|
||
def index | ||
udts = Udt.omiga_inscription | ||
|
||
if stale?(udts) | ||
udts = sort_udts(udts).page(@page).per(@page_size).fast_page | ||
options = FastJsonapi::PaginationMetaGenerator.new( | ||
request:, | ||
records: udts, | ||
page: @page, | ||
page_size: @page_size, | ||
).call | ||
|
||
render json: UdtSerializer.new(udts, options) | ||
end | ||
end | ||
|
||
def show | ||
udt = Udt.find_by!(type_hash: params[:id]) | ||
render json: UdtSerializer.new(udt) | ||
rescue ActiveRecord::RecordNotFound | ||
raise Api::V1::Exceptions::UdtNotFoundError | ||
end | ||
|
||
private | ||
|
||
def validate_query_params | ||
validator = Validations::Udt.new(params) | ||
|
||
if validator.invalid? | ||
errors = validator.error_object[:errors] | ||
status = validator.error_object[:status] | ||
|
||
render json: errors, status: | ||
end | ||
end | ||
|
||
def pagination_params | ||
@page = params[:page] || 1 | ||
@page_size = params[:page_size] || Udt.default_per_page | ||
end | ||
|
||
def sort_udts(records) | ||
sort, order = params.fetch(:sort, "id.desc").split(".", 2) | ||
sort = | ||
case sort | ||
when "created_time" then "block_timestamp" | ||
when "transactions" then "h24_ckb_transactions_count" | ||
else sort | ||
end | ||
|
||
if order.nil? || !order.match?(/^(asc|desc)$/i) | ||
order = "asc" | ||
end | ||
|
||
if sort == "mint_status" | ||
records.joins(:omiga_inscription_info).order("omiga_inscription_infos.mint_status #{order}") | ||
else | ||
records.order("#{sort} #{order}") | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.