2023-02-15 02:52:11 +01:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-29 00:09:06 +02:00
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
2023-02-15 02:52:11 +01:00
|
|
|
"github.com/zitadel/zitadel/internal/repository/quota"
|
|
|
|
)
|
|
|
|
|
2023-07-06 08:38:13 +02: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-29 00:09:06 +02:00
|
|
|
cmds := make([]eventstore.Command, len(dueNotifications))
|
|
|
|
for idx, notification := range dueNotifications {
|
|
|
|
cmds[idx] = notification
|
2023-02-15 02:52:11 +01:00
|
|
|
}
|
2023-03-29 00:09:06 +02:00
|
|
|
_, err := c.eventstore.Push(ctx, cmds...)
|
|
|
|
return err
|
2023-02-15 02:52:11 +01:00
|
|
|
}
|
|
|
|
|
2023-03-29 00:09:06 +02:00
|
|
|
func (c *Commands) UsageNotificationSent(ctx context.Context, dueEvent *quota.NotificationDueEvent) error {
|
|
|
|
id, err := c.idGenerator.Next()
|
2023-02-15 02:52:11 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-03-29 00:09:06 +02:00
|
|
|
_, err = c.eventstore.Push(
|
|
|
|
ctx,
|
|
|
|
quota.NewNotifiedEvent(ctx, id, dueEvent),
|
|
|
|
)
|
|
|
|
return err
|
2023-02-15 02:52:11 +01:00
|
|
|
}
|