Skip to content

Commit df6c1c0

Browse files
committed
feat: manage nfts view
1 parent 0f8d958 commit df6c1c0

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

src/main/resources/db/migration/V1.0.3__Baseline_Views.sql

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,33 @@ LEFT JOIN soonmarket_asset_base_v t2 ON t1.asset_id=t2.asset_id;
220220
-- base views for sale
221221
----------------------------------
222222

223-
CREATE OR replace VIEW soonmarket_listing_open_v as
224-
SELECT
223+
CREATE OR replace VIEW soonmarket_listing_valid_v as
224+
WITH valid_sales AS (
225+
SELECT
226+
t1.sale_id,
227+
BOOL_AND(COALESCE(t5.owner = t1.seller,FALSE)) AS VALID
228+
FROM atomicmarket_sale t1
229+
INNER JOIN atomicmarket_sale_asset t3 ON t1.sale_id=t3.sale_id
230+
LEFT JOIN atomicassets_asset_owner_log t4 ON t3.asset_id=t4.asset_id AND t4.current
231+
WHERE NOT EXISTS(SELECT 1 from atomicmarket_sale_state t2 where t1.sale_id=t2.sale_id)
232+
GROUP BY t1.sale_id
233+
)
234+
SELECT
225235
t1.sale_id AS listing_id,
226236
t3.asset_id,
227237
t3.template_id,
228238
t3.collection_id,
229-
t1.block_timestamp AS listing_date,
230-
t1.price AS listing_price,
231-
er.usd * t1.price AS listing_price_usd,
232-
t1.token AS listing_token,
239+
t2.block_timestamp AS listing_date,
240+
t2.price AS listing_price,
241+
er.usd * t2.price AS listing_price_usd,
242+
t2.token AS listing_token,
233243
bundle,
234-
bundle_size
235-
FROM atomicmarket_sale t1
244+
bundle_size
245+
FROM valid_sales t1
246+
INNER JOIN atomicmarket_sale t2 ON t1.sale_id=t2.sale_id
236247
INNER JOIN atomicmarket_sale_asset t3 ON t1.sale_id=t3.sale_id
237-
LEFT JOIN soonmarket_exchange_rate_latest_v er ON t1.token = er.token_symbol
238-
WHERE NOT EXISTS(SELECT 1 from atomicmarket_sale_state t2 where t1.sale_id=t2.sale_id);
248+
LEFT JOIN soonmarket_exchange_rate_latest_v er ON t2.token = er.token_symbol
249+
where VALID;
239250

240251
--
241252

src/main/resources/db/migration/V1.0.4__Baseline_API.sql

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ CREATE OR REPLACE VIEW soonmarket_nft_detail_v AS
195195
t2.listing_id,
196196
t3.auction_id
197197
FROM soonmarket_asset_v t1
198-
LEFT JOIN (select max(listing_id) AS listing_id,asset_id from soonmarket_listing_v t2 where not bundle GROUP BY asset_id)t2 ON t1.asset_id=t2.asset_id AND NOT t1.burned
198+
LEFT JOIN (select max(listing_id) AS listing_id,asset_id from soonmarket_listing_v t2 where not bundle GROUP BY asset_id and state is null)t2 ON t1.asset_id=t2.asset_id AND NOT t1.burned
199199
LEFT JOIN (select max(auction_Id) as auction_id,asset_id from soonmarket_auction_v t3 where active group by asset_id)t3 ON t1.asset_id=t3.asset_id AND NOT t1.burned;
200200

201201
COMMENT ON VIEW soonmarket_nft_detail_v IS 'View for NFT Details';
202202

203203
-----------------------------------------
204-
-- MyNFTs Mat-View TODO: move to function
204+
-- MyNFTs View
205205
-----------------------------------------
206206

207207
CREATE VIEW soonmarket_my_nfts_v as
@@ -235,25 +235,54 @@ SELECT
235235
t7.token as auction_token,
236236
t7.starting_price as auction_starting_bid,
237237
t7.current_bid as auction_current_bid,
238-
COALESCE(t7.bundle,false) AS bundle,
238+
COALESCE(t7.bundle,t8.bundle,false) AS bundle,
239239
t8.listing_id,
240240
t8.listing_date,
241241
t8.listing_token,
242242
t8.listing_price,
243243
t9.price,
244-
t9.token
244+
t9.token,
245+
COALESCE(COALESCE(t7.current_bid,t7.starting_price),t8.listing_price) AS filter_price_usd
245246
FROM atomicassets_asset_owner_log t1
246247
inner JOIN atomicassets_asset t2 ON t1.asset_id=t2.asset_id
247248
LEFT JOIN atomicassets_asset_data t3 ON t1.asset_id=t3.asset_id
248249
LEFT JOIN soonmarket_template_v t4 ON t2.template_id=t4.template_id
249250
LEFT JOIN soonmarket_collection_v t5 on t2.collection_id=t5.collection_id
250251
left JOIN LATERAL (SELECT auction_id,auction_end,token,starting_price,current_bid,bundle from soonmarket_auction_base_v where t1.asset_id=asset_id AND active) t7 ON true
251-
left JOIN LATERAL (SELECT listing_id,listing_date,listing_token,listing_price,bundle from soonmarket_listing_open_v where t1.asset_id=asset_id)t8 ON true
252+
left JOIN LATERAL (SELECT listing_id,listing_date,listing_token,listing_price,bundle from soonmarket_listing_valid_mv where t1.asset_id=asset_id)t8 ON true
252253
LEFT JOIN soonmarket_last_sold_for_asset_v t9 ON t1.asset_id=t9.asset_id AND buyer=OWNER
253-
WHERE t1.CURRENT;
254+
WHERE t1.CURRENT AND NOT blacklisted
254255

255256
COMMENT ON VIEW soonmarket_my_nfts_v IS 'View for MyNFTs';
256257

258+
-----------------------------------------
259+
-- Manage NFTs View
260+
-----------------------------------------
261+
262+
CREATE OR replace VIEW soonmarket_manageable_nft_v as
263+
SELECT * FROM(
264+
SELECT
265+
t1.minted - t1.burned AS num_circulating,
266+
t1.burned AS num_burned,
267+
t1.mintable AS num_mintable,
268+
t1.last_minting_date,
269+
t2.*
270+
FROM (
271+
SELECT
272+
creator,
273+
template_id,
274+
edition_size AS total,
275+
COUNT(*) AS minted,
276+
count(CASE WHEN burned THEN 1 end) AS burned,
277+
CASE WHEN edition_size != 0 THEN edition_size - COUNT(*) ELSE 0 END AS mintable,
278+
MAX(t1.mint_date) AS last_minting_date
279+
FROM soonmarket_nft t1
280+
WHERE edition_size != 1
281+
GROUP BY template_id,edition_size,creator) t1
282+
LEFT JOIN LATERAL (SELECT * from soonmarket_nft WHERE t1.template_id=template_id AND t1.creator=creator AND edition_size!=1 LIMIT 1)t2 ON TRUE
283+
UNION ALL
284+
SELECT NULL,NULL,NULL,NULL, * FROM soonmarket_nft WHERE edition_size=1)t
285+
257286
----------------------------------
258287
-- Collection Detail View
259288
----------------------------------

0 commit comments

Comments
 (0)