Release v0.20: регистрация, авторизация, личный кабинет
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
@@ -10,16 +9,16 @@ import (
|
||||
)
|
||||
|
||||
type HomeHandler struct {
|
||||
products *repository.ProductRepository
|
||||
templates *template.Template
|
||||
products *repository.ProductRepository
|
||||
pages *Pages
|
||||
}
|
||||
|
||||
func NewHomeHandler(products *repository.ProductRepository, templates *template.Template) *HomeHandler {
|
||||
return &HomeHandler{products: products, templates: templates}
|
||||
func NewHomeHandler(products *repository.ProductRepository, pages *Pages) *HomeHandler {
|
||||
return &HomeHandler{products: products, pages: pages}
|
||||
}
|
||||
|
||||
type homePageData struct {
|
||||
Title string
|
||||
Layout
|
||||
Products []models.Product
|
||||
Categories []string
|
||||
TotalItems int
|
||||
@@ -52,14 +51,12 @@ func (h *HomeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
data := homePageData{
|
||||
Title: "Главная",
|
||||
Layout: h.pages.layout(r, "Главная", "home"),
|
||||
Products: featured,
|
||||
Categories: categories,
|
||||
TotalItems: total,
|
||||
}
|
||||
data.Success = flashMsg(r, "ok")
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := h.templates.ExecuteTemplate(w, "home.html", data); err != nil {
|
||||
log.Printf("render home: %v", err)
|
||||
}
|
||||
h.pages.render(w, "home.html", data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user