From e84db076a449a62d5e980431a8e5eb86aa9ed482 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Mon, 27 Nov 2023 00:59:15 +0100 Subject: [PATCH] Use router-view for markets --- db/market.go | 20 +++++ server/router/handler/market.go | 17 ++++ server/router/router.go | 1 + vue/src/components/Market.vue | 122 ++++---------------------- vue/src/components/MarketOrders.vue | 57 ++++++++++++ vue/src/components/OrderForm.vue | 129 ++++++++++++++++++++++++++++ vue/src/index.css | 2 + vue/src/main.js | 9 +- vue/src/views/UserView.vue | 2 +- 9 files changed, 252 insertions(+), 107 deletions(-) create mode 100644 vue/src/components/MarketOrders.vue create mode 100644 vue/src/components/OrderForm.vue diff --git a/db/market.go b/db/market.go index 39db574..f1b4bed 100644 --- a/db/market.go +++ b/db/market.go @@ -132,3 +132,23 @@ func (db *DB) FetchUserOrders(pubkey string, orders *[]Order) error { } return nil } + +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 " + + "FROM orders o " + + "JOIN shares s ON o.share_id = s.id " + + "WHERE s.market_id = $1 " + + "ORDER BY o.created_at DESC" + rows, err := db.Query(query, marketId) + if err != nil { + return err + } + 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) + *orders = append(*orders, order) + } + return nil +} diff --git a/server/router/handler/market.go b/server/router/handler/market.go index e170191..8b2babc 100644 --- a/server/router/handler/market.go +++ b/server/router/handler/market.go @@ -112,6 +112,23 @@ func HandleCreateMarket(sc context.ServerContext) echo.HandlerFunc { } } +func HandleMarketOrders(sc context.ServerContext) echo.HandlerFunc { + return func(c echo.Context) error { + var ( + marketId int64 + orders []db.Order + err error + ) + if marketId, err = strconv.ParseInt(c.Param("id"), 10, 64); err != nil { + return echo.NewHTTPError(http.StatusBadRequest, "Bad Request") + } + if err = sc.Db.FetchMarketOrders(marketId, &orders); err != nil { + return err + } + return c.JSON(http.StatusOK, orders) + } +} + func HandleOrder(sc context.ServerContext) echo.HandlerFunc { return func(c echo.Context) error { var ( diff --git a/server/router/router.go b/server/router/router.go index dd86dd0..c1fb901 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -46,6 +46,7 @@ func addBackendRoutes(e *echo.Echo, sc ServerContext) { middleware.SessionGuard, middleware.LNDGuard) GET(e, sc, "/api/market/:id", handler.HandleMarket) + GET(e, sc, "/api/market/:id/orders", handler.HandleMarketOrders) POST(e, sc, "/api/order", handler.HandleOrder, middleware.SessionGuard, diff --git a/vue/src/components/Market.vue b/vue/src/components/Market.vue index 31cde0b..023ad79 100644 --- a/vue/src/components/Market.vue +++ b/vue/src/components/Market.vue @@ -10,62 +10,24 @@
{{ market.Description }}
- - -
- - - - - - - - - - - -
-
{{ err }}
+
+ +
+ + + diff --git a/vue/src/components/MarketOrders.vue b/vue/src/components/MarketOrders.vue new file mode 100644 index 0000000..07f3671 --- /dev/null +++ b/vue/src/components/MarketOrders.vue @@ -0,0 +1,57 @@ + + + + + diff --git a/vue/src/components/OrderForm.vue b/vue/src/components/OrderForm.vue new file mode 100644 index 0000000..0da5ccc --- /dev/null +++ b/vue/src/components/OrderForm.vue @@ -0,0 +1,129 @@ + + + + + diff --git a/vue/src/index.css b/vue/src/index.css index e6d2af9..d3d3e38 100644 --- a/vue/src/index.css +++ b/vue/src/index.css @@ -50,6 +50,7 @@ a.selected { .success:hover { background-color: #35df8d; + color: white; } .red { @@ -63,6 +64,7 @@ a.selected { .error:hover { background-color: #ff7386; + color: white; } .text-muted { diff --git a/vue/src/main.js b/vue/src/main.js index ba00761..299b429 100644 --- a/vue/src/main.js +++ b/vue/src/main.js @@ -13,6 +13,8 @@ import InvoiceView from '@/views/InvoiceView' import UserSettings from '@/components/UserSettings' import UserInvoices from '@/components/UserInvoices' import UserOrders from '@/components/UserOrders' +import OrderForm from '@/components/OrderForm' +import MarketOrders from '@/components/MarketOrders' const routes = [ { @@ -31,7 +33,12 @@ const routes = [ ] }, { - path: '/market/:id', component: MarketView + path: '/market/:id', + component: MarketView, + children: [ + { path: 'form', name: 'form', component: OrderForm }, + { path: 'orders', name: 'market-orders', component: MarketOrders } + ] }, { path: '/invoice/:id', component: InvoiceView diff --git a/vue/src/views/UserView.vue b/vue/src/views/UserView.vue index 204dc45..7a04c25 100644 --- a/vue/src/views/UserView.vue +++ b/vue/src/views/UserView.vue @@ -17,7 +17,7 @@ - +