Changes for the initial shopping cart thing.

master
Zed A. Shaw 3 weeks ago
parent da6da800a0
commit 47e7b69af7
  1. 28
      features/shopping/api.go
  2. 9
      features/shopping/db.go
  3. 10
      features/shopping/init.go
  4. 11
      features/shopping/views.go
  5. 14
      tests/shopping/example_test.go
  6. 21
      views/shopping/checkout.html
  7. 24
      views/shopping/index.html

@ -0,0 +1,28 @@
package features_shopping
import (
"github.com/gofiber/fiber/v2"
"MY/webapp/data"
_ "github.com/mattn/go-sqlite3"
sq "github.com/Masterminds/squirrel"
"fmt"
)
func GetApiProducts(c *fiber.Ctx) error {
sql, args, err := sq.Select("*").From("Product").ToSql()
fmt.Println("SQL:", sql, args, err)
return data.SelectJson[data.Product](c, err, sql, args...)
}
func GetApiCart(c *fiber.Ctx) error {
return c.JSON(fiber.Map{})
}
func SetupApi(app *fiber.App) {
app.Get("/api/shopping/products", GetApiProducts)
app.Get("/api/shopping/cart", GetApiCart)
}

@ -0,0 +1,9 @@
package features_shopping
import (
// "MY/webapp/data"
// _ "github.com/mattn/go-sqlite3"
// sq "github.com/Masterminds/squirrel"
)

@ -0,0 +1,10 @@
package features_shopping
import (
"github.com/gofiber/fiber/v2"
)
func Setup(app *fiber.App) {
SetupApi(app)
SetupViews(app)
}

@ -0,0 +1,11 @@
package features_shopping
import (
"github.com/gofiber/fiber/v2"
. "MY/webapp/common"
)
func SetupViews(app *fiber.App) {
err := ConfigViews(app, "views/shopping")
if err != nil { panic(err) }
}

@ -0,0 +1,14 @@
package tests
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestLogin(t *testing.T) {
assert.Equal(true, false)
}
func TestMain(m *testing.M) {
m.Run()
}

@ -0,0 +1,21 @@
<h1>Checkout</h1>
<bar class="bg-gray-800">
<aside>I'm baby pork belly blackbird spyplane vape, bodega boys farm-to-table taxidermy JOMO chia copper mug intelligentsia distillery.</aside>
<bar class="justify-between" style="padding:30px">
<div class="text-2xl">Price: $100.00</div>
<a href="/shopping/remove/1"><button type="button">X</button></a>
</bar>
</bar>
<table>
<tr><th>Subtotal:</th><td>$100.00</td></tr>
<tr><th>Total:</th><td>$50.00</td></tr>
</table>
<bar>
<a href="/shopping/"><button type="button">Continue Shopping</button></a>
<a href="/paypal/"><button type="button">Pay with Paypal</button></a>
<a href="/paypal/"><button type="button">Pay with Credit Card</button></a>
</bar>

@ -0,0 +1,24 @@
<script>
let Data = new PaginateTable("/api/shopping/products")
</script>
<h1>Products</h1>
<p>I have these products for you:</p>
<block x-data="Data">
<template x-for="item in contents">
<bar class="bg-gray-800">
<shape x-text="item.Slug"></shape>
<div>
<h4 x-text="item.Title"></h4>
<aside x-text="item.Description"></aside>
<bar class="justify-between" style="padding:30px">
<div class="text-2xl">Price: <span x-text="item.Price"></span></div>
<a href="/shopping/checkout"><button type="button">Buy</button></a>
</bar>
</div>
</bar>
</template>
</block>
Loading…
Cancel
Save