diff --git a/features/shopping/api.go b/features/shopping/api.go new file mode 100644 index 0000000..fed790a --- /dev/null +++ b/features/shopping/api.go @@ -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) +} diff --git a/features/shopping/db.go b/features/shopping/db.go new file mode 100644 index 0000000..dc88ed5 --- /dev/null +++ b/features/shopping/db.go @@ -0,0 +1,9 @@ +package features_shopping + +import ( +// "MY/webapp/data" +// _ "github.com/mattn/go-sqlite3" +// sq "github.com/Masterminds/squirrel" +) + + diff --git a/features/shopping/init.go b/features/shopping/init.go new file mode 100644 index 0000000..520b0fa --- /dev/null +++ b/features/shopping/init.go @@ -0,0 +1,10 @@ +package features_shopping + +import ( + "github.com/gofiber/fiber/v2" +) + +func Setup(app *fiber.App) { + SetupApi(app) + SetupViews(app) +} diff --git a/features/shopping/views.go b/features/shopping/views.go new file mode 100644 index 0000000..0c8af99 --- /dev/null +++ b/features/shopping/views.go @@ -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) } +} diff --git a/tests/shopping/example_test.go b/tests/shopping/example_test.go new file mode 100644 index 0000000..f7318b7 --- /dev/null +++ b/tests/shopping/example_test.go @@ -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() +} diff --git a/views/shopping/checkout.html b/views/shopping/checkout.html new file mode 100644 index 0000000..416cd19 --- /dev/null +++ b/views/shopping/checkout.html @@ -0,0 +1,21 @@ +

Checkout

+ + + + + +
Price: $100.00
+ +
+
+ + + + +
Subtotal:$100.00
Total:$50.00
+ + + + + + diff --git a/views/shopping/index.html b/views/shopping/index.html new file mode 100644 index 0000000..23bdb5f --- /dev/null +++ b/views/shopping/index.html @@ -0,0 +1,24 @@ + + +

Products

+ +

I have these products for you:

+ + + +