variants
This commit is contained in:
@@ -38,7 +38,7 @@ func (r *GORMCartItemRepository) Create(cartItem models.CartItem) (models.CartIt
|
||||
|
||||
func (r *GORMCartItemRepository) GetAll() ([]models.CartItem, error) {
|
||||
var cartItems []models.CartItem
|
||||
result := r.DB.Preload("ShopItem").Find(&cartItems)
|
||||
result := r.DB.Preload("ShopItem").Preload("ItemVariant").Find(&cartItems)
|
||||
|
||||
return cartItems, result.Error
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (t *GORMCartItemRepository) GetById(id string) (models.CartItem, error) {
|
||||
}
|
||||
|
||||
var cartItem models.CartItem
|
||||
result := t.DB.First(&cartItem, uint(cartItemId))
|
||||
result := t.DB.Preload("ShopItem").Preload("ItemVariant").First(&cartItem, uint(cartItemId))
|
||||
|
||||
if result.Error != nil {
|
||||
return models.CartItem{}, result.Error
|
||||
@@ -85,6 +85,6 @@ func (r *GORMCartItemRepository) DeleteById(id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
result := r.DB.Omit("ShopItem").Delete(&models.CartItem{}, cartItemId)
|
||||
result := r.DB.Omit("ShopItem").Omit("ItemVariant").Delete(&models.CartItem{}, cartItemId)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
@@ -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