From 1dc10d61bcd7dc2abd3a5370ca52aa494b437908 Mon Sep 17 00:00:00 2001 From: kalipso Date: Mon, 3 Mar 2025 17:49:38 +0100 Subject: [PATCH] allow updating tags of items --- repositories/shopItemRepository.go | 5 +++++ views/shopitem.html | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/repositories/shopItemRepository.go b/repositories/shopItemRepository.go index e1340a1..37f419a 100644 --- a/repositories/shopItemRepository.go +++ b/repositories/shopItemRepository.go @@ -69,6 +69,11 @@ func (r *GORMShopItemRepository) GetById(id string) (models.ShopItem, error) { } func (r *GORMShopItemRepository) Update(shopItem models.ShopItem) (models.ShopItem, error) { + err := r.DB.Model(&shopItem).Association("Tags").Replace(shopItem.Tags) + if err != nil { + return models.ShopItem{}, err + } + result := r.DB.Save(&shopItem) if result.Error != nil { return models.ShopItem{}, result.Error diff --git a/views/shopitem.html b/views/shopitem.html index c7c923a..c8128dd 100644 --- a/views/shopitem.html +++ b/views/shopitem.html @@ -34,6 +34,17 @@ {{ .data.shopItem.Price }}€ + +
+
+ Tags: + + {{ range .data.shopItem.Tags }} + {{ .Name }} + {{ end }} + +
+