Categoriecontroller added
This commit is contained in:
@@ -185,6 +185,8 @@ func (server *Server) routeInit() {
|
||||
server.Router.HandleFunc("/products", server.Products).Methods("GET")
|
||||
server.Router.HandleFunc("/products/{slug}", server.GetProductByID).Methods("GET")
|
||||
|
||||
server.Router.HandleFunc("/section/{id}", server.SelectSection).Methods("GET")
|
||||
|
||||
staticFileDirectory := http.Dir("./assets/")
|
||||
staticFileHandler := http.StripPrefix("/public/", http.FileServer(staticFileDirectory))
|
||||
server.Router.PathPrefix("/public/").Handler(staticFileHandler).Methods("GET")
|
||||
|
||||
25
app/controllers/category_controller.go
Normal file
25
app/controllers/category_controller.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/unrolled/render"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (server *Server) Categories(w http.ResponseWriter, r *http.Request) {
|
||||
renderer := render.New(render.Options{
|
||||
Layout: "layout",
|
||||
Extensions: []string{".html", ".tmpl"},
|
||||
})
|
||||
|
||||
vars := mux.Vars(r)
|
||||
|
||||
if vars["id"] == "" {
|
||||
return
|
||||
}
|
||||
|
||||
_ = renderer.HTML(w, http.StatusOK, "home", map[string]interface{}{
|
||||
//"user": user,
|
||||
//"sectionen": sectionen,
|
||||
})
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func (server *Server) Home(w http.ResponseWriter, r *http.Request) {
|
||||
render := render.New(render.Options{
|
||||
renderer := render.New(render.Options{
|
||||
Layout: "layout",
|
||||
Extensions: []string{".html", ".tmpl"},
|
||||
})
|
||||
@@ -21,7 +21,7 @@ func (server *Server) Home(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
user := server.CurrentUser(w, r)
|
||||
|
||||
_ = render.HTML(w, http.StatusOK, "home", map[string]interface{}{
|
||||
_ = renderer.HTML(w, http.StatusOK, "home", map[string]interface{}{
|
||||
"user": user,
|
||||
"sectionen": sectionen,
|
||||
})
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Section struct {
|
||||
ID string
|
||||
@@ -9,3 +12,12 @@ type Section struct {
|
||||
UpdatedAt time.Time
|
||||
Categories []Category
|
||||
}
|
||||
|
||||
func GetSection(db *gorm.DB) ([]Section, error) {
|
||||
var sections []Section
|
||||
err := db.Debug().Model(&Section{}).Order("created_at desc").Find(§ions).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sections, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user