Sectionen im Home hinzugefügt
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user