Files
eway/internal/core/creategoodsitem.go
2024-01-24 16:12:16 +03:00

46 lines
935 B
Go

package core
import (
"context"
"fmt"
"git.loyso.art/frx/eway/internal/entity"
)
type CreateGoodsItemParams struct {
GoodsItems []entity.GoodsItem
}
type CreateGoodsItemResult struct {
GoodsItems []entity.GoodsItem
}
type createGoodsItemAction struct {
baseAction
}
type CreateGoodsItemAction Action[CreateGoodsItemParams, CreateGoodsItemResult]
func NewCreateGoodsItemAction(
env *Env,
) ActionDecorator[CreateGoodsItemParams, CreateGoodsItemResult, CreateGoodsItemAction] {
ba := newBaseAction(env)
action := &createGoodsItemAction{
baseAction: ba,
}
return applyDecorators(action)
}
func (a *createGoodsItemAction) Do(
ctx context.Context,
params CreateGoodsItemParams,
) (result CreateGoodsItemResult, err error) {
result.GoodsItems, err = a.env.repository.GoodsItem().UpsertMany(ctx, params.GoodsItems...)
if err != nil {
return result, fmt.Errorf("upserting items: %w", err)
}
return result, nil
}