add tagview
This commit is contained in:
@@ -213,7 +213,16 @@ func (rc *UserController) MainView(c *gin.Context) {
|
|||||||
"shopItems": shopItems,
|
"shopItems": shopItems,
|
||||||
})
|
})
|
||||||
|
|
||||||
fmt.Println(data)
|
c.HTML(http.StatusOK, "index.html", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *UserController) TagView(c *gin.Context) {
|
||||||
|
shopItems, _ := repositories.ShopItems.GetByTagId(c.Param("id"))
|
||||||
|
|
||||||
|
data := CreateSessionData(c, gin.H{
|
||||||
|
"title": "shopItem Page",
|
||||||
|
"shopItems": shopItems,
|
||||||
|
})
|
||||||
|
|
||||||
c.HTML(http.StatusOK, "index.html", data)
|
c.HTML(http.StatusOK, "index.html", data)
|
||||||
}
|
}
|
||||||
|
|||||||
1
main.go
1
main.go
@@ -88,6 +88,7 @@ func main() {
|
|||||||
|
|
||||||
viewRoutes.GET("/tags", authValidator.RequireAuth, shopItemController.TagView)
|
viewRoutes.GET("/tags", authValidator.RequireAuth, shopItemController.TagView)
|
||||||
viewRoutes.POST("/tags/:id", authValidator.RequireAuth, shopItemController.TagHandler)
|
viewRoutes.POST("/tags/:id", authValidator.RequireAuth, shopItemController.TagHandler)
|
||||||
|
viewRoutes.GET("/tags/:id", userController.TagView)
|
||||||
viewRoutes.POST("/tags", authValidator.RequireAuth, shopItemController.AddTagHandler)
|
viewRoutes.POST("/tags", authValidator.RequireAuth, shopItemController.AddTagHandler)
|
||||||
viewRoutes.GET("/cart", cartItemController.CartItemView)
|
viewRoutes.GET("/cart", cartItemController.CartItemView)
|
||||||
viewRoutes.POST("/cart", cartItemController.AddItemHandler)
|
viewRoutes.POST("/cart", cartItemController.AddItemHandler)
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package repositories
|
package repositories
|
||||||
|
|
||||||
import(
|
import (
|
||||||
"strconv"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"git.dynamicdiscord.de/kalipso/zineshop/models"
|
"git.dynamicdiscord.de/kalipso/zineshop/models"
|
||||||
)
|
)
|
||||||
@@ -12,8 +12,8 @@ type ShopItemRepository interface {
|
|||||||
GetAll() ([]models.ShopItem, error)
|
GetAll() ([]models.ShopItem, error)
|
||||||
GetAllPublic() ([]models.ShopItem, error)
|
GetAllPublic() ([]models.ShopItem, error)
|
||||||
GetById(string) (models.ShopItem, error)
|
GetById(string) (models.ShopItem, error)
|
||||||
|
GetByTagId(string) ([]models.ShopItem, error)
|
||||||
GetVariantById(string) (models.ItemVariant, error)
|
GetVariantById(string) (models.ItemVariant, error)
|
||||||
//GetByTagId(string) ([]models.ShopItem, error)
|
|
||||||
Update(models.ShopItem) (models.ShopItem, error)
|
Update(models.ShopItem) (models.ShopItem, error)
|
||||||
DeleteById(string) error
|
DeleteById(string) error
|
||||||
}
|
}
|
||||||
@@ -68,6 +68,23 @@ func (r *GORMShopItemRepository) GetById(id string) (models.ShopItem, error) {
|
|||||||
return shopItem, nil
|
return shopItem, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *GORMShopItemRepository) GetByTagId(id string) ([]models.ShopItem, error) {
|
||||||
|
tagId, err := strconv.Atoi(id)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var shopItems []models.ShopItem
|
||||||
|
result := r.DB.Joins("JOIN item_tags ON item_tags.shop_item_id = shop_items.id").Where("item_tags.tag_id = ?", tagId).Preload("Tags").Preload("Variants").Find(&shopItems)
|
||||||
|
|
||||||
|
if result.Error != nil {
|
||||||
|
return nil, result.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
return shopItems, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *GORMShopItemRepository) GetVariantById(id string) (models.ItemVariant, error) {
|
func (r *GORMShopItemRepository) GetVariantById(id string) (models.ItemVariant, error) {
|
||||||
itemVariantId, err := strconv.Atoi(id)
|
itemVariantId, err := strconv.Atoi(id)
|
||||||
|
|
||||||
@@ -85,7 +102,6 @@ func (r *GORMShopItemRepository) GetVariantById(id string) (models.ItemVariant,
|
|||||||
return itemVariant, nil
|
return itemVariant, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (r *GORMShopItemRepository) Update(shopItem models.ShopItem) (models.ShopItem, error) {
|
func (r *GORMShopItemRepository) Update(shopItem models.ShopItem) (models.ShopItem, error) {
|
||||||
err := r.DB.Model(&shopItem).Association("Tags").Replace(shopItem.Tags)
|
err := r.DB.Model(&shopItem).Association("Tags").Replace(shopItem.Tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user