Categorien werden aufgelistet.
This commit is contained in:
@@ -182,10 +182,10 @@ func (server *Server) routeInit() {
|
|||||||
server.Router.HandleFunc("/register", server.DoRegister).Methods("POST")
|
server.Router.HandleFunc("/register", server.DoRegister).Methods("POST")
|
||||||
server.Router.HandleFunc("/logout", server.Logout).Methods("GET")
|
server.Router.HandleFunc("/logout", server.Logout).Methods("GET")
|
||||||
|
|
||||||
server.Router.HandleFunc("/products", server.Products).Methods("GET")
|
server.Router.HandleFunc("/products/cat/{id}", server.Products).Methods("GET")
|
||||||
server.Router.HandleFunc("/products/{slug}", server.GetProductByID).Methods("GET")
|
server.Router.HandleFunc("/products/{slug}", server.GetProductByID).Methods("GET")
|
||||||
|
|
||||||
server.Router.HandleFunc("/section/{id}", server.SelectSection).Methods("GET")
|
server.Router.HandleFunc("/section/{id}", server.Categories).Methods("GET")
|
||||||
|
|
||||||
staticFileDirectory := http.Dir("./assets/")
|
staticFileDirectory := http.Dir("./assets/")
|
||||||
staticFileHandler := http.StripPrefix("/public/", http.FileServer(staticFileDirectory))
|
staticFileHandler := http.StripPrefix("/public/", http.FileServer(staticFileDirectory))
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/unrolled/render"
|
"github.com/unrolled/render"
|
||||||
|
"moretcgshop/app/models"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,8 +19,17 @@ func (server *Server) Categories(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = renderer.HTML(w, http.StatusOK, "home", map[string]interface{}{
|
categorieModel := models.Category{}
|
||||||
|
|
||||||
|
categorien, err := categorieModel.GetCategorie(server.DB, vars["id"])
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
println(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = renderer.HTML(w, http.StatusOK, "categories", map[string]interface{}{
|
||||||
//"user": user,
|
//"user": user,
|
||||||
//"sectionen": sectionen,
|
"categorien": categorien,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,21 +17,13 @@ type Category struct {
|
|||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Category) Get(db *gorm.DB, perPage int, page int) (*[]Product, int64, error) {
|
func (p *Category) GetCategorie(db *gorm.DB, sectionID string) (*[]Category, error) {
|
||||||
|
|
||||||
var count int64
|
var categorie []Category
|
||||||
var products []Product
|
|
||||||
|
|
||||||
err := db.Debug().Model(&Product{}).Count(&count).Error
|
err := db.Debug().Model(&Category{}).Order("created_at desc").Where("section_id = ?", sectionID).Find(&categorie).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
return &categorie, nil
|
||||||
offset := (page - 1) * perPage
|
|
||||||
|
|
||||||
err = db.Debug().Model(&Product{}).Order("created_at desc").Limit(perPage).Offset(offset).Find(&products).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
return &products, count, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
34
templates/pages/categories.html
Normal file
34
templates/pages/categories.html
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{{ define "categories" }}
|
||||||
|
<section class="breadcrumb-section pb-3 pt-3">
|
||||||
|
<div class="container">
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<li class="breadcrumb-item"><a href="/">Home</a></li>
|
||||||
|
<li class="breadcrumb-item"><a href="/products">Products</a></li>
|
||||||
|
<li class="breadcrumb-item active" aria-current="page">{{ .product.Name}}</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section class="product-page pb-4 pt-4">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-3 col-md-4 col-12">
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="sidebar-widget">
|
||||||
|
<div class="widget-title">
|
||||||
|
<h3>Kategorien</h3>
|
||||||
|
</div>
|
||||||
|
<div class="widget-content widget-categories">
|
||||||
|
<ul>
|
||||||
|
{{ range $i, $categorie := .categorien }}
|
||||||
|
<li><a href="/products/{{ $categorie.ID }}">{{ $categorie.Name }}</a></li>
|
||||||
|
{{ end }}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{{ end }}
|
||||||
Reference in New Issue
Block a user