Kategorien und Produkte können zur DB hinzugefügt werden.

This commit is contained in:
2023-11-20 15:51:42 +01:00
parent a87b0b3979
commit 5340963ac2
12 changed files with 330 additions and 19 deletions

View File

@@ -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
}