v0.30: product pages, categories, sale prices and order status timeline
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
type CustomerHandler struct {
|
||||
products *repository.ProductRepository
|
||||
categories *repository.CategoryRepository
|
||||
users *repository.UserRepository
|
||||
cart *repository.CartRepository
|
||||
orders *repository.OrderRepository
|
||||
@@ -53,14 +54,26 @@ type checkoutPage struct {
|
||||
|
||||
type accountPage struct {
|
||||
shopPage
|
||||
Orders []models.Order
|
||||
Name string
|
||||
Phone string
|
||||
Orders []models.Order
|
||||
Name string
|
||||
Phone string
|
||||
Address string
|
||||
}
|
||||
|
||||
type productPage struct {
|
||||
shopPage
|
||||
Product models.Product
|
||||
}
|
||||
|
||||
type categoryPage struct {
|
||||
shopPage
|
||||
Category models.Category
|
||||
Products []models.Product
|
||||
}
|
||||
|
||||
func NewCustomerHandler(
|
||||
products *repository.ProductRepository,
|
||||
categories *repository.CategoryRepository,
|
||||
users *repository.UserRepository,
|
||||
cart *repository.CartRepository,
|
||||
orders *repository.OrderRepository,
|
||||
@@ -69,7 +82,7 @@ func NewCustomerHandler(
|
||||
templates *template.Template,
|
||||
) *CustomerHandler {
|
||||
return &CustomerHandler{
|
||||
products: products, users: users, cart: cart, orders: orders, stats: stats,
|
||||
products: products, categories: categories, users: users, cart: cart, orders: orders, stats: stats,
|
||||
userSession: userSession, cartSession: cartSession, templates: templates,
|
||||
}
|
||||
}
|
||||
@@ -121,6 +134,40 @@ func (h *CustomerHandler) Home(w http.ResponseWriter, r *http.Request) {
|
||||
h.render(w, "home.html", p)
|
||||
}
|
||||
|
||||
func (h *CustomerHandler) ProductPage(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.Atoi(r.PathValue("id"))
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
product, err := h.products.GetActiveByID(r.Context(), id)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
p := productPage{
|
||||
shopPage: h.basePage(r, w, product.Name),
|
||||
Product: product,
|
||||
}
|
||||
h.render(w, "product.html", p)
|
||||
}
|
||||
|
||||
func (h *CustomerHandler) CategoryPage(w http.ResponseWriter, r *http.Request) {
|
||||
slug := r.PathValue("slug")
|
||||
cat, err := h.categories.GetBySlug(r.Context(), slug)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
products, _ := h.products.ByCategoryID(r.Context(), cat.ID)
|
||||
p := categoryPage{
|
||||
shopPage: h.basePage(r, w, cat.Name),
|
||||
Category: cat,
|
||||
Products: products,
|
||||
}
|
||||
h.render(w, "category.html", p)
|
||||
}
|
||||
|
||||
func (h *CustomerHandler) RegisterPage(w http.ResponseWriter, r *http.Request) {
|
||||
if _, ok := auth.UserIDFromSession(h.userSession, r); ok {
|
||||
http.Redirect(w, r, "/account", http.StatusSeeOther)
|
||||
|
||||
Reference in New Issue
Block a user