variants
This commit is contained in:
@@ -12,6 +12,7 @@ type ShopItemRepository interface {
|
||||
GetAll() ([]models.ShopItem, error)
|
||||
GetAllPublic() ([]models.ShopItem, error)
|
||||
GetById(string) (models.ShopItem, error)
|
||||
GetVariantById(string) (models.ItemVariant, error)
|
||||
//GetByTagId(string) ([]models.ShopItem, error)
|
||||
Update(models.ShopItem) (models.ShopItem, error)
|
||||
DeleteById(string) error
|
||||
@@ -48,7 +49,6 @@ func (r *GORMShopItemRepository) GetAllPublic() ([]models.ShopItem, error) {
|
||||
result := r.DB.Preload("Tags").Preload("Variants").Where("is_public = 1").Find(&shopItems)
|
||||
|
||||
return shopItems, result.Error
|
||||
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetById(id string) (models.ShopItem, error) {
|
||||
@@ -68,6 +68,24 @@ func (r *GORMShopItemRepository) GetById(id string) (models.ShopItem, error) {
|
||||
return shopItem, nil
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetVariantById(id string) (models.ItemVariant, error) {
|
||||
itemVariantId, err := strconv.Atoi(id)
|
||||
|
||||
if err != nil {
|
||||
return models.ItemVariant{}, err
|
||||
}
|
||||
|
||||
var itemVariant models.ItemVariant
|
||||
result := r.DB.First(&itemVariant, uint(itemVariantId))
|
||||
|
||||
if result.Error != nil {
|
||||
return models.ItemVariant{}, result.Error
|
||||
}
|
||||
|
||||
return itemVariant, nil
|
||||
}
|
||||
|
||||
|
||||
func (r *GORMShopItemRepository) Update(shopItem models.ShopItem) (models.ShopItem, error) {
|
||||
err := r.DB.Model(&shopItem).Association("Tags").Replace(shopItem.Tags)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user