This repository has been archived on 2024-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
core-old/internal/service/tribe_change.go
Dawid Wysokiński b05089b940
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
feat: tribe changes (#122)
Reviewed-on: twhelp/core#122
2022-11-11 09:29:32 +00:00

49 lines
1.1 KiB
Go

package service
import (
"context"
"fmt"
"gitea.dwysokinski.me/twhelp/core/internal/domain"
"go.opentelemetry.io/otel/codes"
)
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 {
ctx, span := tracer.Start(ctx, "TribeChange.Create")
defer span.End()
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 {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
return fmt.Errorf("TribeChangeRepository.Create: %w", err)
}
}
return nil
}