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

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