Sectionen im Home hinzugefügt
This commit is contained in:
@@ -2,6 +2,8 @@ package controllers
|
||||
|
||||
import (
|
||||
"github.com/unrolled/render"
|
||||
"log"
|
||||
"moretcgshop/app/models"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -11,9 +13,16 @@ func (server *Server) Home(w http.ResponseWriter, r *http.Request) {
|
||||
Extensions: []string{".html", ".tmpl"},
|
||||
})
|
||||
|
||||
sectionen, err := models.GetSection(server.DB)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
user := server.CurrentUser(w, r)
|
||||
|
||||
_ = render.HTML(w, http.StatusOK, "home", map[string]interface{}{
|
||||
"user": user,
|
||||
"user": user,
|
||||
"sectionen": sectionen,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,14 +1,37 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Category struct {
|
||||
ID string
|
||||
ParentID string
|
||||
ID string `gorm:"size:36;not null;uniqueIndex;primary_key"`
|
||||
ParentID string `gorm:"size:36;"`
|
||||
Section Section
|
||||
SectionID string
|
||||
SectionID string `gorm:"size:36;index"`
|
||||
Products []Product `gorm:"many2many:product_categories;"`
|
||||
Name string
|
||||
Name string `gorm:"size:100;"`
|
||||
Image string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (p *Category) Get(db *gorm.DB, perPage int, page int) (*[]Product, int64, error) {
|
||||
|
||||
var count int64
|
||||
var products []Product
|
||||
|
||||
err := db.Debug().Model(&Product{}).Count(&count).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
26
database/fakers/section_faker.go
Normal file
26
database/fakers/section_faker.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package fakers
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
"moretcgshop/app/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
func SectionFaker(db *gorm.DB) []*models.Section {
|
||||
var res []*models.Section
|
||||
|
||||
var temp *models.Section
|
||||
var games []string = []string{"One-Piece", "Yu-Gi-Oh", "My Little Pony"}
|
||||
|
||||
for _, game := range games {
|
||||
temp = &models.Section{
|
||||
ID: uuid.New().String(),
|
||||
Name: game,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
}
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -13,6 +13,7 @@ func RegisterSeeders(db *gorm.DB) []Seeder {
|
||||
return []Seeder{
|
||||
{Seeder: fakers.UserFaker(db)},
|
||||
{Seeder: fakers.ProductFaker(db)},
|
||||
{Seeder: fakers.SectionFaker(db)},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,43 +5,31 @@
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<nav class="nav-category">
|
||||
<h2>Kategorien</h2>
|
||||
<h2>Spiele</h2>
|
||||
<ul class="menu-category">
|
||||
<li><a href="#">YU - GI - OH</a></li>
|
||||
<li><a href="#">My Little Pony</a></li>
|
||||
<li><a href="#">One Piece</a></li>
|
||||
<!--<li><a href="#">Baby and Toys</a></li>
|
||||
<li><a href="#">Sports</a></li>
|
||||
<li><a href="#">Digital Goods</a></li>-->
|
||||
{{ range $i, $section := .sectionen }}
|
||||
<li><a href="/section/{{ $i }}">{{ $section.Name }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<div id="carouselExampleIndicators" class="carousel slide carousel-fade" data-ride="carousel">
|
||||
<ol class="carousel-indicators">
|
||||
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
|
||||
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
|
||||
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
|
||||
{{ range $i, $section := .sectionen }}
|
||||
<li data-target="#carouselExampleIndicators" data-slide-to="{{ $i }}" {{ if eq $i 0 }} class="active" {{ end }} ></li>
|
||||
{{ end }}
|
||||
</ol>
|
||||
<div class="carousel-inner shadow-sm rounded">
|
||||
<div class="carousel-item active">
|
||||
<img class="d-block w-100" src="https://cdn1.epicgames.com/spt-assets/441b22f4c4414997a2994eba40e60daf/my-little-pony-a-maretime-bay-adventure-video-n33x0.png" alt="First slide">
|
||||
|
||||
{{ range $i, $section := .sectionen }}
|
||||
<div class="carousel-item {{ if eq $i 0 }} active {{ end }}">
|
||||
<img class="d-block w-100" src="/public/img/slides/slide1.jpg" alt="First slide">
|
||||
<div class="carousel-caption d-none d-md-block">
|
||||
<h5>Mountains, Nature Collection</h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="carousel-item">
|
||||
<img class="d-block w-100" src="https://occ-0-2794-2219.1.nflxso.net/dnm/api/v6/E8vDc_W8CLv7-yMQu8KMEC7Rrr8/AAAABUX2KYwwhnfPwUIGOPB6DKz-f2tiWG2I1yE0swf9FQihfCjOYZg0eKiWdtExO4N0kjwkAWuTFhu1eLD2eesOqjtxsI0BaBdkFCRp.jpg?r=219" alt="Second slide">
|
||||
<div class="carousel-caption d-none d-md-block">
|
||||
<h5>Freedom, Sea Collection</h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="carousel-item">
|
||||
<img class="d-block w-100" src="/public/img/slides/slide3.jpg" alt="Third slide">
|
||||
<div class="carousel-caption d-none d-md-block">
|
||||
<h5>Living the Dream, Lost Island</h5>
|
||||
<h5>{{ $section.Name }}</h5>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
<!-- End Slider -->
|
||||
|
||||
Reference in New Issue
Block a user