2023-02-15 01:52:11 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-28 22:09:06 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-02-15 01:52:11 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/quota"
|
|
|
|
)
|
|
|
|
|
2023-07-06 06:38:13 +00:00
|
|
|
// ReportQuotaUsage writes a slice of *quota.NotificationDueEvent directly to the eventstore
|
|
|
|
func (c *Commands) ReportQuotaUsage(ctx context.Context, dueNotifications []*quota.NotificationDueEvent) error {
|
2023-03-28 22:09:06 +00:00
|
|
|
cmds := make([]eventstore.Command, len(dueNotifications))
|
|
|
|
for idx, notification := range dueNotifications {
|
|
|
|
cmds[idx] = notification
|
2023-02-15 01:52:11 +00:00
|
|
|
}
|
2023-03-28 22:09:06 +00:00
|
|
|
_, err := c.eventstore.Push(ctx, cmds...)
|
|
|
|
return err
|
2023-02-15 01:52:11 +00:00
|
|
|
}
|
|
|
|
|
2023-03-28 22:09:06 +00:00
|
|
|
func (c *Commands) UsageNotificationSent(ctx context.Context, dueEvent *quota.NotificationDueEvent) error {
|
|
|
|
id, err := c.idGenerator.Next()
|
2023-02-15 01:52:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-28 22:09:06 +00:00
|
|
|
_, err = c.eventstore.Push(
|
|
|
|
ctx,
|
|
|
|
quota.NewNotifiedEvent(ctx, id, dueEvent),
|
|
|
|
)
|
|
|
|
return err
|
2023-02-15 01:52:11 +00:00
|
|
|
}
|