Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: token collection sort by type is require #1879

Merged
merged 1 commit into from
May 23, 2024
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
2 changes: 1 addition & 1 deletion app/controllers/api/v2/nft/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def sort_collections(records)
order = "asc"
end
if sort == "block_timestamp"
TokenCollection.left_joins(:cell).order("cell_outputs.#{sort} #{order}")
records.left_joins(:cell).order("cell_outputs.#{sort} #{order}")
else
records.order("#{sort} #{order}")
end
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/api/v2/nft/collections_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class NFT::CollectionsControllerTest < ActionDispatch::IntegrationTest
cell1 = create(:cell_output, block_timestamp: timestamp, block: block1, ckb_transaction: transaction1)
cell3 = create(:cell_output, block_timestamp: 1.day.ago.to_i * 1000, block: block3, ckb_transaction: transaction3)
tc1 = create :token_collection, name: "token1", cell_id: cell1.id
tc2 = create :token_collection, name: "token2"
_tc3 = create :token_collection, name: "token3", cell_id: cell3.id
_tc2 = create :token_collection, name: "token2", standard: "cota"
tc3 = create :token_collection, name: "token3", cell_id: cell3.id

get api_v2_nft_collections_url, params: { sort: "timestamp.desc" }
get api_v2_nft_collections_url, params: { sort: "timestamp.desc", type: "nrc721" }
assert_response :success
assert_equal tc2.id, json["data"].first["id"]
assert_equal tc3.id, json["data"].first["id"]
assert_equal tc1.id, json["data"].last["id"]
assert_equal timestamp, json["data"].last["timestamp"]
end
Expand Down
Loading