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:
@@ -333,8 +333,20 @@ func (rc *UserController) InviteHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rc *UserController) MainView(c *gin.Context) {
|
func (rc *UserController) MainView(c *gin.Context) {
|
||||||
shopItems, _ := repositories.ShopItems.GetAll()
|
itemOrder := c.Query("order")
|
||||||
fmt.Println(len(shopItems))
|
|
||||||
|
var shopItems []models.ShopItem
|
||||||
|
if itemOrder == "newestFirst" {
|
||||||
|
shopItems, _ = repositories.ShopItems.GetAllNewestFirst()
|
||||||
|
} else if itemOrder == "oldestFirst" {
|
||||||
|
shopItems, _ = repositories.ShopItems.GetAllNewestLast()
|
||||||
|
} else if itemOrder == "az" {
|
||||||
|
shopItems, _ = repositories.ShopItems.GetAllLexicalFirst()
|
||||||
|
} else if itemOrder == "za" {
|
||||||
|
shopItems, _ = repositories.ShopItems.GetAllLexicalLast()
|
||||||
|
} else {
|
||||||
|
shopItems, _ = repositories.ShopItems.GetAllNewestFirst()
|
||||||
|
}
|
||||||
|
|
||||||
data := CreateSessionData(c, gin.H{
|
data := CreateSessionData(c, gin.H{
|
||||||
"title": "shopItem Page",
|
"title": "shopItem Page",
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ import (
|
|||||||
type ShopItemRepository interface {
|
type ShopItemRepository interface {
|
||||||
Create(models.ShopItem) (models.ShopItem, error)
|
Create(models.ShopItem) (models.ShopItem, error)
|
||||||
GetAll() ([]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)
|
GetAllPublic() ([]models.ShopItem, error)
|
||||||
GetById(string) (models.ShopItem, error)
|
GetById(string) (models.ShopItem, error)
|
||||||
GetNextOfId(string) (models.ShopItem, error)
|
GetNextOfId(string) (models.ShopItem, error)
|
||||||
@@ -47,6 +52,29 @@ func (r *GORMShopItemRepository) GetAll() ([]models.ShopItem, error) {
|
|||||||
return shopItems, result.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) {
|
func (r *GORMShopItemRepository) GetAllPublic() ([]models.ShopItem, error) {
|
||||||
var shopItems []models.ShopItem
|
var shopItems []models.ShopItem
|
||||||
result := r.DB.Preload("Tags").Preload("Variants").Where("is_public = 1").Find(&shopItems)
|
result := r.DB.Preload("Tags").Preload("Variants").Where("is_public = 1").Find(&shopItems)
|
||||||
|
|||||||
Reference in New Issue
Block a user