Kategorien und Produkte können zur DB hinzugefügt werden.
This commit is contained in:
@@ -17,13 +17,39 @@ type Category struct {
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func (p *Category) GetCategorie(db *gorm.DB, sectionID string) (*[]Category, error) {
|
||||
func (p *Category) GetCategory(db *gorm.DB, sectionID string) (*[]Category, error) {
|
||||
|
||||
var categorie []Category
|
||||
var categories []Category
|
||||
|
||||
err := db.Debug().Model(&Category{}).Order("created_at desc").Where("section_id = ?", sectionID).Find(&categorie).Error
|
||||
err := db.Debug().Model(&Category{}).Order("created_at desc").Where("section_id = ?", sectionID).Find(&categories).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &categorie, nil
|
||||
return &categories, nil
|
||||
}
|
||||
|
||||
func (p *Category) GetCategoryByID(db *gorm.DB, categoryID string) (*Category, error) {
|
||||
var result Category
|
||||
|
||||
err := db.Debug().Model(&Category{}).Where("id = ?", categoryID).Find(&result).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (p *Category) CreateCategory(db *gorm.DB, param *Category) (*Category, error) {
|
||||
category := &Category{
|
||||
ID: param.ID,
|
||||
Name: param.Name,
|
||||
SectionID: param.SectionID,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
}
|
||||
|
||||
err := db.Debug().Create(&category).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return category, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user