zitadel/internal/admin/repository/eventsourcing/view/iam_member.go
Silvan dd5e4acd24
fix(event handling): use internal pubsub for view update (#1118)
* start sub

* start implement subsciptions

* start subscription

* implementation for member done

* admin done

* fix: tests

* extend handlers

* prepary notification

* no errors in adminapi

* changed current sequence in all packages

* ignore mocks

* works

* subscriptions as singleton

* tests

* refactor: rename function scope var
2020-12-18 16:47:45 +01:00

79 lines
2.5 KiB
Go

package view
import (
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/models"
iam_model "github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/internal/iam/repository/view"
"github.com/caos/zitadel/internal/iam/repository/view/model"
global_view "github.com/caos/zitadel/internal/view/repository"
)
const (
iamMemberTable = "adminapi.iam_members"
)
func (v *View) IAMMemberByIDs(orgID, userID string) (*model.IAMMemberView, error) {
return view.IAMMemberByIDs(v.Db, iamMemberTable, orgID, userID)
}
func (v *View) SearchIAMMembers(request *iam_model.IAMMemberSearchRequest) ([]*model.IAMMemberView, uint64, error) {
return view.SearchIAMMembers(v.Db, iamMemberTable, request)
}
func (v *View) IAMMembersByUserID(userID string) ([]*model.IAMMemberView, error) {
return view.IAMMembersByUserID(v.Db, iamMemberTable, userID)
}
func (v *View) PutIAMMember(org *model.IAMMemberView, event *models.Event) error {
err := view.PutIAMMember(v.Db, iamMemberTable, org)
if err != nil {
return err
}
return v.ProcessedIAMMemberSequence(event)
}
func (v *View) PutIAMMembers(members []*model.IAMMemberView, event *models.Event) error {
err := view.PutIAMMembers(v.Db, iamMemberTable, members...)
if err != nil {
return err
}
return v.ProcessedIAMMemberSequence(event)
}
func (v *View) DeleteIAMMember(iamID, userID string, event *models.Event) error {
err := view.DeleteIAMMember(v.Db, iamMemberTable, iamID, userID)
if err != nil && !errors.IsNotFound(err) {
return err
}
return v.ProcessedIAMMemberSequence(event)
}
func (v *View) DeleteIAMMembersByUserID(userID string, event *models.Event) error {
err := view.DeleteIAMMembersByUserID(v.Db, iamMemberTable, userID)
if err != nil {
return err
}
return v.ProcessedIAMMemberSequence(event)
}
func (v *View) GetLatestIAMMemberSequence(aggregateType string) (*global_view.CurrentSequence, error) {
return v.latestSequence(iamMemberTable, aggregateType)
}
func (v *View) ProcessedIAMMemberSequence(event *models.Event) error {
return v.saveCurrentSequence(iamMemberTable, event)
}
func (v *View) UpdateIAMMemberSpoolerRunTimestamp() error {
return v.updateSpoolerRunSequence(iamMemberTable)
}
func (v *View) GetLatestIAMMemberFailedEvent(sequence uint64) (*global_view.FailedEvent, error) {
return v.latestFailedEvent(iamMemberTable, sequence)
}
func (v *View) ProcessedIAMMemberFailedEvent(failedEvent *global_view.FailedEvent) error {
return v.saveFailedEvent(failedEvent)
}