Wird jetzt nach kategorien die Seiten angezeigt
This commit is contained in:
@@ -85,6 +85,7 @@ func GetFlash(w http.ResponseWriter, r *http.Request, name string) []string {
|
||||
|
||||
func (server *Server) Run(addr string) {
|
||||
fmt.Printf("Listening to port %s", addr)
|
||||
println("")
|
||||
log.Fatal(http.ListenAndServe(addr, server.Router))
|
||||
}
|
||||
|
||||
@@ -182,7 +183,7 @@ func (server *Server) routeInit() {
|
||||
server.Router.HandleFunc("/register", server.DoRegister).Methods("POST")
|
||||
server.Router.HandleFunc("/logout", server.Logout).Methods("GET")
|
||||
|
||||
server.Router.HandleFunc("/products/cat/{id}", server.Products).Methods("GET")
|
||||
server.Router.HandleFunc("/products/cat/{id}", server.ProductsByCategory).Methods("GET")
|
||||
server.Router.HandleFunc("/products/{slug}", server.GetProductByID).Methods("GET")
|
||||
|
||||
server.Router.HandleFunc("/section/{id}", server.Categories).Methods("GET")
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (server *Server) Products(w http.ResponseWriter, r *http.Request) {
|
||||
func (server *Server) ProductsByCategory(w http.ResponseWriter, r *http.Request) {
|
||||
renderer := render.New(render.Options{
|
||||
Layout: "layout",
|
||||
Extensions: []string{".html", ".tmpl"},
|
||||
@@ -17,14 +17,24 @@ func (server *Server) Products(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
|
||||
page, _ := strconv.Atoi(q.Get("page"))
|
||||
|
||||
vars := mux.Vars(r)
|
||||
if vars["id"] == "" {
|
||||
return
|
||||
}
|
||||
|
||||
category := vars["id"]
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
println(category)
|
||||
perPage := 9
|
||||
|
||||
_ = perPage
|
||||
productModel := models.Product{}
|
||||
|
||||
products, totalRows, err := productModel.GetProducts(server.DB, perPage, page)
|
||||
products, totalRows, err := productModel.GetProductsByCategory(server.DB, category)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user