add next/previous button to edititemhtml
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
|
||||
@@ -12,6 +13,8 @@ type ShopItemRepository interface {
|
||||
GetAll() ([]models.ShopItem, error)
|
||||
GetAllPublic() ([]models.ShopItem, error)
|
||||
GetById(string) (models.ShopItem, error)
|
||||
GetNextOfId(string) (models.ShopItem, error)
|
||||
GetPreviousOfId(string) (models.ShopItem, error)
|
||||
GetByTagId(string) ([]models.ShopItem, error)
|
||||
GetVariantById(string) (models.ItemVariant, error)
|
||||
Update(models.ShopItem) (models.ShopItem, error)
|
||||
@@ -68,6 +71,30 @@ func (r *GORMShopItemRepository) GetById(id string) (models.ShopItem, error) {
|
||||
return shopItem, nil
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetNextOfId(id string) (models.ShopItem, error) {
|
||||
var nextItem models.ShopItem
|
||||
if err := r.DB.Where("id > ?", id).Order("id asc").First(&nextItem).Error; err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
return models.ShopItem{}, err
|
||||
} else {
|
||||
return models.ShopItem{}, fmt.Errorf("No Item found")
|
||||
}
|
||||
}
|
||||
return nextItem, nil
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetPreviousOfId(id string) (models.ShopItem, error) {
|
||||
var previousItem models.ShopItem
|
||||
if err := r.DB.Where("id < ?", id).Order("id desc").First(&previousItem).Error; err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
return models.ShopItem{}, err
|
||||
} else {
|
||||
return models.ShopItem{}, fmt.Errorf("No Item found")
|
||||
}
|
||||
}
|
||||
return previousItem, nil
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetByTagId(id string) ([]models.ShopItem, error) {
|
||||
tagId, err := strconv.Atoi(id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user