Files
zineshop/services/shopItemService.go
2025-03-04 16:42:59 +01:00

37 lines
744 B
Go

package services
import(
"fmt"
"example.com/gin/test/models"
"example.com/gin/test/repositories"
)
var(
ShopItems ShopItemService = ShopItemService{}
)
type ShopItemService struct {}
func (u *ShopItemService) NewShopItem(name string, abstract string, description string, price float64, tagIds []string) (models.ShopItem, error) {
shopItem := models.ShopItem{
Name: name,
Abstract: abstract,
Description: description,
BasePrice: price,
IsPublic: true,
}
for _, tagId := range tagIds {
tag, err := repositories.Tags.GetById(tagId)
if err != nil {
return models.ShopItem{}, fmt.Errorf("Could not get tag by id")
}
shopItem.Tags = append(shopItem.Tags, tag)
}
return repositories.ShopItems.Create(shopItem)
}