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
|
||||
}
|
||||
|
||||
@@ -21,3 +21,12 @@ func GetSection(db *gorm.DB) ([]Section, error) {
|
||||
}
|
||||
return sections, nil
|
||||
}
|
||||
|
||||
func GetSectionByID(db *gorm.DB, id string) (Section, error) {
|
||||
var section Section
|
||||
err := db.Debug().Model(&Section{}).Where("id = ?", id).Find(§ion).Error
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
return section, nil
|
||||
}
|
||||
|
||||
@@ -24,6 +24,25 @@ type Product struct {
|
||||
DeletedAt gorm.DeletedAt
|
||||
}
|
||||
|
||||
func (p *Product) CreateProduct(db *gorm.DB, param *Product) (*Product, error) {
|
||||
product := &Product{
|
||||
ID: param.ID,
|
||||
Name: param.Name,
|
||||
Price: param.Price,
|
||||
CategoryID: param.CategoryID,
|
||||
Description: param.Description,
|
||||
ShortDescription: param.ShortDescription,
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
}
|
||||
|
||||
err := db.Debug().Create(&product).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return product, nil
|
||||
}
|
||||
|
||||
func (p *Product) GetProducts(db *gorm.DB, perPage int, page int) (*[]Product, int64, error) {
|
||||
|
||||
var count int64
|
||||
|
||||
@@ -14,6 +14,7 @@ type User struct {
|
||||
Email string
|
||||
Password string
|
||||
RememberToken string
|
||||
Admin bool
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt
|
||||
|
||||
Reference in New Issue
Block a user