From e6aec21affc69f798d0ff26ea289c9255a64ae87 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 9 Sep 2023 22:52:51 +0200 Subject: [PATCH] Add share pointer to type Order --- pages/market.html | 18 ++++-------------- src/db.go | 5 +++-- src/market.go | 1 + 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/pages/market.html b/pages/market.html index d5333bc..9024d86 100644 --- a/pages/market.html +++ b/pages/market.html @@ -50,7 +50,7 @@ {{ range .Orders }} - {{ if and (eq .ShareId $.YesShare.Id) (eq .Side "BUY") }} + {{ if and (eq .Share.Description "YES") (eq .Side "BUY") }}
YES @@ -60,27 +60,17 @@ {{ else }} {{ end }} - {{ if and (eq .ShareId $.YesShare.Id) (eq .Side "SELL") }} + {{ if (eq .Side "SELL") }}
- YES + {{.Share.Description}} {{.Quantity}} @ {{.Price}}
{{ else }} {{ end }} - {{ if and (eq .ShareId $.NoShare.Id) (eq .Side "SELL") }} - -
- NO - {{.Quantity}} @ {{.Price}} -
- - {{ else }} - - {{ end }} - {{ if and (eq .ShareId $.NoShare.Id) (eq .Side "BUY") }} + {{ if and (eq .Share.Description "NO") (eq .Side "BUY") }}
NO diff --git a/src/db.go b/src/db.go index b2684d1..6330134 100644 --- a/src/db.go +++ b/src/db.go @@ -71,9 +71,10 @@ func (db *DB) FetchShares(marketId int, shares *[]Share) error { func (db *DB) FetchOrders(marketId int, orders *[]Order) error { rows, err := db.Query(""+ - "SELECT o.id, share_id, o.pubkey, side, quantity, price, order_id "+ + "SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, s.description, o.order_id "+ "FROM orders o "+ "JOIN invoices i ON o.invoice_id = i.id "+ + "JOIN shares s ON o.share_id = s.id "+ "WHERE share_id = ANY(SELECT id FROM shares WHERE market_id = $1) "+ "AND i.confirmed_at IS NOT NULL "+ "ORDER BY price DESC", marketId) @@ -83,7 +84,7 @@ func (db *DB) FetchOrders(marketId int, 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.OrderId) + rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.Share.Description, &order.OrderId) *orders = append(*orders, order) } return nil diff --git a/src/market.go b/src/market.go index 92ace61..1072e4a 100644 --- a/src/market.go +++ b/src/market.go @@ -25,6 +25,7 @@ type Share struct { type Order struct { Session + Share Id string ShareId string `form:"share_id"` Side string `form:"side"`