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) {
|
||||
shopItems, _ := repositories.ShopItems.GetAll()
|
||||
fmt.Println(len(shopItems))
|
||||
itemOrder := c.Query("order")
|
||||
|
||||
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{
|
||||
"title": "shopItem Page",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<div class="bg-white">
|
||||
<div class="mx-auto max-w-2xl px-4 py-16 sm:px-6 sm:py-24 lg:max-w-7xl">
|
||||
<h2 class="text-2xl font-bold tracking-tight text-gray-900">Available Zines</h2>
|
||||
<h2 class="text-2xl font-bold tracking-tight text-gray-900">Available Zines</h2>
|
||||
|
||||
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
|
||||
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
|
||||
<div class="mt-6 grid grid-cols-1 gap-x-6 gap-y-10 md:grid-cols-2 xl:grid-cols-4">
|
||||
{{ range .data.shopItems }}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user