actualize items list in db
This commit is contained in:
@ -1,18 +1,49 @@
|
||||
package entity
|
||||
|
||||
func IterWithErr[T any](t []T, err error) iterWithErr[T] {
|
||||
return iterWithErr[T]{
|
||||
func IterIntoMap[K comparable, V any](v []V, err error) iterIntoMap[K, V] {
|
||||
bi := IterWithErr(v, err)
|
||||
|
||||
return iterIntoMap[K, V]{
|
||||
baseIter: bi,
|
||||
}
|
||||
}
|
||||
|
||||
type iterIntoMap[K comparable, V any] struct {
|
||||
baseIter[V]
|
||||
}
|
||||
|
||||
func (i iterIntoMap[K, V]) Map(f func(V) (K, error)) (map[K]V, error) {
|
||||
if i.err != nil {
|
||||
return nil, i.err
|
||||
}
|
||||
|
||||
out := make(map[K]V, len(i.items))
|
||||
for _, item := range i.items {
|
||||
var key K
|
||||
key, i.err = f(item)
|
||||
if i.err != nil {
|
||||
return nil, i.err
|
||||
}
|
||||
|
||||
out[key] = item
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func IterWithErr[T any](t []T, err error) baseIter[T] {
|
||||
return baseIter[T]{
|
||||
items: t,
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
|
||||
type iterWithErr[T any] struct {
|
||||
type baseIter[T any] struct {
|
||||
items []T
|
||||
err error
|
||||
}
|
||||
|
||||
func (iter iterWithErr[T]) Do(f func(T) error) error {
|
||||
func (iter baseIter[T]) Do(f func(T) error) error {
|
||||
if iter.err != nil {
|
||||
return iter.err
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ type GoodsItemRepository interface {
|
||||
GetByCart(context.Context, int64) (GoodsItem, error)
|
||||
|
||||
UpsertMany(context.Context, ...GoodsItem) ([]GoodsItem, error)
|
||||
Delete(context.Context, string) (GoodsItem, error)
|
||||
}
|
||||
|
||||
type CategoryRepository interface {
|
||||
|
||||
Reference in New Issue
Block a user