Skip to content

Commit

Permalink
feat: add function to remove declined events if config parameter is set
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Huck committed Aug 12, 2023
1 parent 7c23a11 commit 1ad213e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions internal/sync/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sync
import (
"context"
"fmt"
"slices"

Check failure on line 6 in internal/sync/controller.go

View workflow job for this annotation

GitHub Actions / test

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.4/x64/src/slices)

Check failure on line 6 in internal/sync/controller.go

View workflow job for this annotation

GitHub Actions / vet

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.4/x64/src/slices)

Check failure on line 6 in internal/sync/controller.go

View workflow job for this annotation

GitHub Actions / STATICCHECK

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.4/x64/src/slices) (compile)
"time"

"github.com/inovex/CalendarSync/internal/models"
Expand Down Expand Up @@ -77,6 +78,12 @@ func (p Controller) SynchroniseTimeframe(ctx context.Context, start time.Time, e
return err
}

// remove declined events
if !p.SyncDeclinedEvents {
log.Debug("We're not syncing declined events, to enable set sync.sync_declined_events to true in your config.yaml")
eventsInSource = removeDeclinedEvents(eventsInSource)
}

// Transform source events before comparing them to the sink events
transformedEventsInSource := []models.Event{}

Expand Down Expand Up @@ -228,3 +235,18 @@ func maps(events []models.Event) map[string]models.Event {
}
return result
}

func removeDeclinedEvents(events []models.Event) []models.Event {
var toDeleteIndex []int
for i, event := range events {
log.Warn("event accept check", "accepted", event.Accepted)
if !event.Accepted {
toDeleteIndex = append(toDeleteIndex, i)
}
}
for _, k := range toDeleteIndex {
log.Warn("Deleting event id", "id", k)
events = slices.Delete(events, k, k+1)
}
return events
}

0 comments on commit 1ad213e

Please sign in to comment.