| package patch |
|
|
| import ( |
| "github.com/openmeterio/openmeter/openmeter/subscription" |
| ) |
|
|
| type PatchUnscheduleEdit struct{} |
|
|
| func (p PatchUnscheduleEdit) Op() subscription.PatchOperation { |
| return subscription.PatchOperationUnschedule |
| } |
|
|
| func (p PatchUnscheduleEdit) Path() subscription.SpecPath { |
| return subscription.NewPhasePath("") |
| } |
|
|
| func (p PatchUnscheduleEdit) Validate() error { |
| if err := p.Op().Validate(); err != nil { |
| return err |
| } |
|
|
| return nil |
| } |
|
|
| var _ subscription.Patch = PatchUnscheduleEdit{} |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func (p PatchUnscheduleEdit) ApplyTo(spec *subscription.SubscriptionSpec, actx subscription.ApplyContext) error { |
| currentPhase, exists := spec.GetCurrentPhaseAt(actx.CurrentTime) |
| if !exists { |
| return &subscription.PatchConflictError{Msg: "current phase doesn't exist, cannot unschedule edits"} |
| } |
|
|
| currentPhaseCadence, err := spec.GetPhaseCadence(currentPhase.PhaseKey) |
| if err != nil { |
| return err |
| } |
|
|
| for iK, items := range currentPhase.ItemsByKey { |
| for i := len(items) - 1; i >= 0; i-- { |
| if c := items[i].GetCadence(currentPhaseCadence); c.IsActiveAt(actx.CurrentTime) { |
| |
| currentPhase.ItemsByKey[iK][i].ActiveToOverrideRelativeToPhaseStart = nil |
|
|
| break |
| } |
|
|
| |
| currentPhase.ItemsByKey[iK] = items[:i] |
| } |
| } |
|
|
| return nil |
| } |
|
|