From 1bedaaeecf3d39e7ba85deb645f0ca3070ddf75c Mon Sep 17 00:00:00 2001 From: vinchent Date: Thu, 22 Aug 2024 09:56:14 +0200 Subject: [PATCH] show sales & subscriptions --- cmd/web/handlers.go | 20 +++++++++++++++++++- cmd/web/routes.go | 1 + cmd/web/templates/sale.page.gohtml | 12 +++++++++++- static/js/sale.js | 7 +++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 87a5136..d5a3920 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -381,7 +381,25 @@ func (app *application) AllSubscriptions(w http.ResponseWriter, r *http.Request) } func (app *application) ShowSale(w http.ResponseWriter, r *http.Request) { - if err := app.renderTemplate(w, r, "sale", &templateData{}); err != nil { + stringMap := make(map[string]string) + stringMap["title"] = "Sale" + stringMap["cancel"] = "/admin/all-sales" + + if err := app.renderTemplate(w, r, "sale", &templateData{ + StringMap: stringMap, + }); err != nil { + app.errorLog.Println(err) + } +} + +func (app *application) ShowSubscriptions(w http.ResponseWriter, r *http.Request) { + stringMap := make(map[string]string) + stringMap["title"] = "Subscriptions" + stringMap["cancel"] = "/admin/all-subscriptions" + + if err := app.renderTemplate(w, r, "sale", &templateData{ + StringMap: stringMap, + }); err != nil { app.errorLog.Println(err) } } diff --git a/cmd/web/routes.go b/cmd/web/routes.go index b14546a..c5dba9e 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -18,6 +18,7 @@ func (app *application) routes() http.Handler { mux.Get("/all-sales", app.AllSales) mux.Get("/all-subscriptions", app.AllSubscriptions) mux.Get("/sales/{id}", app.ShowSale) + mux.Get("/subscriptions/{id}", app.ShowSubscriptions) }) // mux.Post("/virtual-terminal-payment-succeeded", app.VirtualTerminalPaymentSucceeded) diff --git a/cmd/web/templates/sale.page.gohtml b/cmd/web/templates/sale.page.gohtml index de0ed38..0444f39 100644 --- a/cmd/web/templates/sale.page.gohtml +++ b/cmd/web/templates/sale.page.gohtml @@ -1,11 +1,21 @@ {{template "base" .}} {{define "title"}} -Sale +{{index .StringMap "title"}} {{end}} {{define "content"}}

Sale


+
+ Order No:
+ Customer:
+ Product:
+ Quantity:
+ Total Sale:
+
+
+Cancel +Refund Order {{end}} {{define "js"}} diff --git a/static/js/sale.js b/static/js/sale.js index 78a2007..36dc0d2 100644 --- a/static/js/sale.js +++ b/static/js/sale.js @@ -15,6 +15,13 @@ export function showInfo(api) { .then(response => response.json()) .then(function (data) { console.log(data); + if (data) { + document.getElementById("order-no").innerHTML = data.id + document.getElementById("customer").innerHTML = data.customer.first_name + " " + data.customer.last_name + document.getElementById("product").innerHTML = data.widget.name + document.getElementById("quantity").innerHTML = data.quantity + document.getElementById("amount").innerHTML = formatCurrency(data.transaction.amount) + } }); }