37 lines
780 B
Go
37 lines
780 B
Go
package services
|
|
|
|
import(
|
|
"fmt"
|
|
|
|
"git.dynamicdiscord.de/kalipso/zineshop/models"
|
|
"git.dynamicdiscord.de/kalipso/zineshop/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)
|
|
}
|