issue #20 add sort, not yet in view
All checks were successful
Go / build (push) Successful in 12m10s
All checks were successful
Go / build (push) Successful in 12m10s
This commit is contained in:
@@ -11,6 +11,11 @@ import (
|
||||
type ShopItemRepository interface {
|
||||
Create(models.ShopItem) (models.ShopItem, error)
|
||||
GetAll() ([]models.ShopItem, error)
|
||||
GetAllSorted(string) ([]models.ShopItem, error)
|
||||
GetAllNewestFirst() ([]models.ShopItem, error)
|
||||
GetAllNewestLast() ([]models.ShopItem, error)
|
||||
GetAllLexicalFirst() ([]models.ShopItem, error)
|
||||
GetAllLexicalLast() ([]models.ShopItem, error)
|
||||
GetAllPublic() ([]models.ShopItem, error)
|
||||
GetById(string) (models.ShopItem, error)
|
||||
GetNextOfId(string) (models.ShopItem, error)
|
||||
@@ -47,6 +52,29 @@ func (r *GORMShopItemRepository) GetAll() ([]models.ShopItem, error) {
|
||||
return shopItems, result.Error
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetAllSorted(sortString string) ([]models.ShopItem, error) {
|
||||
var shopItems []models.ShopItem
|
||||
result := r.DB.Preload("Tags").Preload("Variants").Order(sortString).Find(&shopItems)
|
||||
|
||||
return shopItems, result.Error
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetAllNewestFirst() ([]models.ShopItem, error) {
|
||||
return r.GetAllSorted("created_at desc")
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetAllNewestLast() ([]models.ShopItem, error) {
|
||||
return r.GetAllSorted("created_at asc")
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetAllLexicalFirst() ([]models.ShopItem, error) {
|
||||
return r.GetAllSorted("name asc")
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetAllLexicalLast() ([]models.ShopItem, error) {
|
||||
return r.GetAllSorted("name desc")
|
||||
}
|
||||
|
||||
func (r *GORMShopItemRepository) GetAllPublic() ([]models.ShopItem, error) {
|
||||
var shopItems []models.ShopItem
|
||||
result := r.DB.Preload("Tags").Preload("Variants").Where("is_public = 1").Find(&shopItems)
|
||||
|
||||
Reference in New Issue
Block a user