From 9e1c4e7df402dbc0a83b92da911648bc33d97faf Mon Sep 17 00:00:00 2001 From: Miles Zhang Date: Thu, 23 May 2024 16:11:35 +0800 Subject: [PATCH] fix: token collection sort by type is require (#1879) Signed-off-by: Miles Zhang --- app/controllers/api/v2/nft/collections_controller.rb | 2 +- .../controllers/api/v2/nft/collections_controller_test.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v2/nft/collections_controller.rb b/app/controllers/api/v2/nft/collections_controller.rb index aad5c6d5c..92c5139a3 100644 --- a/app/controllers/api/v2/nft/collections_controller.rb +++ b/app/controllers/api/v2/nft/collections_controller.rb @@ -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 diff --git a/test/controllers/api/v2/nft/collections_controller_test.rb b/test/controllers/api/v2/nft/collections_controller_test.rb index f7a6bbe76..782a09675 100644 --- a/test/controllers/api/v2/nft/collections_controller_test.rb +++ b/test/controllers/api/v2/nft/collections_controller_test.rb @@ -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