Dawid Wysokiński
d244dc69bf
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#140
43 lines
919 B
Go
43 lines
919 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
|
)
|
|
|
|
const (
|
|
tribeChangeChunkSize = 500
|
|
)
|
|
|
|
//counterfeiter:generate -o internal/mock/tribe_change_repository.gen.go . TribeChangeRepository
|
|
type TribeChangeRepository interface {
|
|
Create(ctx context.Context, params ...domain.CreateTribeChangeParams) error
|
|
}
|
|
|
|
type TribeChange struct {
|
|
repo TribeChangeRepository
|
|
}
|
|
|
|
func NewTribeChange(repo TribeChangeRepository) *TribeChange {
|
|
return &TribeChange{repo: repo}
|
|
}
|
|
|
|
func (t *TribeChange) Create(ctx context.Context, params ...domain.CreateTribeChangeParams) error {
|
|
for i := 0; i < len(params); i += tribeChangeChunkSize {
|
|
end := i + tribeChangeChunkSize
|
|
if end > len(params) {
|
|
end = len(params)
|
|
}
|
|
|
|
chunk := params[i:end]
|
|
|
|
if err := t.repo.Create(ctx, chunk...); err != nil {
|
|
return fmt.Errorf("TribeChangeRepository.Create: %w", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|