github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/systemssync/service.go (about) 1 package systemssync 2 3 import ( 4 "context" 5 6 "github.com/kyma-incubator/compass/components/director/internal/model" 7 "github.com/kyma-incubator/compass/components/director/pkg/log" 8 "github.com/pkg/errors" 9 ) 10 11 // SystemsSyncRepository represents the Systems Sync timestamps repository layer 12 // 13 //go:generate mockery --name=SystemsSyncRepository --output=automock --outpkg=automock --case=underscore --disable-version-string 14 type SystemsSyncRepository interface { 15 List(ctx context.Context) ([]*model.SystemSynchronizationTimestamp, error) 16 Upsert(ctx context.Context, in *model.SystemSynchronizationTimestamp) error 17 } 18 19 type service struct { 20 syncSystemsRepo SystemsSyncRepository 21 } 22 23 // NewService returns new SystemsSyncService 24 func NewService(syncSystemsRepo SystemsSyncRepository) *service { 25 return &service{ 26 syncSystemsRepo: syncSystemsRepo, 27 } 28 } 29 30 // List returns all synchronization timestamps of the systems 31 func (s *service) List(ctx context.Context) ([]*model.SystemSynchronizationTimestamp, error) { 32 log.C(ctx).Infof("Listing systems sync timestamps for all tenants") 33 34 syncTimestamps, err := s.syncSystemsRepo.List(ctx) 35 if err != nil { 36 return nil, errors.Wrap(err, "error while listing the sync timestamps") 37 } 38 39 return syncTimestamps, nil 40 } 41 42 // Upsert updates sync timestamp or creates new one if it doesn't exist 43 func (s *service) Upsert(ctx context.Context, in *model.SystemSynchronizationTimestamp) error { 44 log.C(ctx).Infof("Upserting systems sync timestamps") 45 46 err := s.syncSystemsRepo.Upsert(ctx, in) 47 if err != nil { 48 return errors.Wrap(err, "error while upserting the sync timestamp") 49 } 50 51 return nil 52 }