Update db function and add to web-back
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"myapp/internal/models"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
func (app *application) VirtualTerminal(w http.ResponseWriter, r *http.Request) {
|
||||
@ -43,12 +45,12 @@ func (app *application) PaymentSucceeded(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
// ChargeOnce displays the page to buy one widget
|
||||
func (app *application) ChargeOnce(w http.ResponseWriter, r *http.Request) {
|
||||
widget := models.Widget{
|
||||
ID: 1,
|
||||
Name: "Custom Widget",
|
||||
Description: "Paris 2024",
|
||||
InventoryLevel: 10,
|
||||
Price: 1000,
|
||||
id := chi.URLParam(r, "id")
|
||||
widgetID, _ := strconv.Atoi(id)
|
||||
|
||||
widget, err := app.DB.GetWidget(widgetID)
|
||||
if err != nil {
|
||||
app.errorLog.Println(err)
|
||||
}
|
||||
|
||||
data := make(map[string]interface{})
|
||||
|
@ -11,7 +11,7 @@ func (app *application) routes() http.Handler {
|
||||
|
||||
mux.Get("/virtual-terminal", app.VirtualTerminal)
|
||||
mux.Post("/payment-succeeded", app.PaymentSucceeded)
|
||||
mux.Get("/charge-once", app.ChargeOnce)
|
||||
mux.Get("/widget/{id}", app.ChargeOnce)
|
||||
|
||||
fileServer := http.FileServer(http.Dir("./static"))
|
||||
mux.Handle("/static/*", http.StripPrefix("/static", fileServer))
|
||||
|
@ -43,7 +43,7 @@
|
||||
aria-expanded="false">Products</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a class="dropdown-item" href="/charge-once">Buy one widget</a>
|
||||
<a class="dropdown-item" href="/widget/1">Buy one widget</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="#">Subscription</a>
|
||||
|
Reference in New Issue
Block a user