From f91080da27ecb9df30e07949a5aa6a5a11dca29c Mon Sep 17 00:00:00 2001 From: ekzyis Date: Mon, 27 Nov 2023 17:45:07 +0100 Subject: [PATCH] Add order status column --- db/init.sql | 3 ++- db/market.go | 10 ++++++---- vue/src/components/OrderRow.vue | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/db/init.sql b/db/init.sql index 157036b..58800ee 100644 --- a/db/init.sql +++ b/db/init.sql @@ -47,7 +47,8 @@ CREATE TABLE orders( side ORDER_SIDE NOT NULL, quantity BIGINT NOT NULL, price BIGINT NOT NULL, - invoice_id UUID NOT NULL REFERENCES invoices(id) + invoice_id UUID NOT NULL REFERENCES invoices(id), + order_id UUID REFERENCES orders(id) ); ALTER TABLE orders ADD CONSTRAINT order_price CHECK(price > 0 AND price < 100); ALTER TABLE orders ADD CONSTRAINT order_quantity CHECK(quantity > 0); diff --git a/db/market.go b/db/market.go index efe66f9..98fd678 100644 --- a/db/market.go +++ b/db/market.go @@ -114,7 +114,8 @@ func (db *DB) CreateOrder(tx *sql.Tx, ctx context.Context, order *Order) error { func (db *DB) FetchUserOrders(pubkey string, orders *[]Order) error { query := "" + - "SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, o.invoice_id, o.created_at, s.description, s.market_id, i.confirmed_at " + + "SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, o.invoice_id, o.created_at, s.description, s.market_id, i.confirmed_at, " + + "CASE WHEN o.order_id IS NOT NULL THEN 'EXECUTED' ELSE 'WAITING' END AS status " + "FROM orders o " + "JOIN invoices i ON o.invoice_id = i.id " + "JOIN shares s ON o.share_id = s.id " + @@ -127,7 +128,7 @@ func (db *DB) FetchUserOrders(pubkey string, orders *[]Order) error { defer rows.Close() for rows.Next() { var order Order - rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.CreatedAt, &order.ShareDescription, &order.Share.MarketId, &order.Invoice.ConfirmedAt) + rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.CreatedAt, &order.ShareDescription, &order.Share.MarketId, &order.Invoice.ConfirmedAt, &order.Status) *orders = append(*orders, order) } return nil @@ -135,7 +136,8 @@ func (db *DB) FetchUserOrders(pubkey string, orders *[]Order) error { func (db *DB) FetchMarketOrders(marketId int64, orders *[]Order) error { query := "" + - "SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, o.invoice_id, o.created_at, s.description, s.market_id " + + "SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, o.invoice_id, o.created_at, s.description, s.market_id, " + + "CASE WHEN o.order_id IS NOT NULL THEN 'EXECUTED' ELSE 'WAITING' END AS status " + "FROM orders o " + "JOIN shares s ON o.share_id = s.id " + "JOIN invoices i ON i.id = o.invoice_id " + @@ -148,7 +150,7 @@ func (db *DB) FetchMarketOrders(marketId int64, orders *[]Order) error { defer rows.Close() for rows.Next() { var order Order - rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.CreatedAt, &order.ShareDescription, &order.Share.MarketId) + rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.CreatedAt, &order.ShareDescription, &order.Share.MarketId, &order.Status) *orders = append(*orders, order) } return nil diff --git a/vue/src/components/OrderRow.vue b/vue/src/components/OrderRow.vue index aae9b2d..410b06b 100644 --- a/vue/src/components/OrderRow.vue +++ b/vue/src/components/OrderRow.vue @@ -3,7 +3,7 @@ {{ order.MarketId }} {{ order.side }} {{ order.quantity }} {{ order.ShareDescription }} @ {{ order.price }} sats {{ ago(new Date(order.CreatedAt)) }} - + {{ order.Status }}