add next/previous button to edititemhtml

This commit is contained in:
2025-04-16 13:59:43 +02:00
parent 861343b338
commit 1688e61ccb
4 changed files with 128 additions and 45 deletions

View File

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