zitadel/internal/auth/repository/eventsourcing/view/user_session.go
Silvan 3118a99c1e
fix: pubsub (#1122)
* 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

* fix: process ALL previous sequences

* fix: spooler and pubsub

* handler check

* fix: process events until all done

* fix break on query err

* fix: handler

* fix: process sequence or return error

* check aggregate id

* fix: log only in error case

* fix tests

* fix: handlers

* fix: spooler

* fix: spooler

* fix: tests

* fix: continue

Co-authored-by: Livio Amstutz <livio.a@gmail.com>
2020-12-21 18:42:34 +01:00

74 lines
2.3 KiB
Go

package view
import (
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/models"
"github.com/caos/zitadel/internal/user/repository/view"
"github.com/caos/zitadel/internal/user/repository/view/model"
"github.com/caos/zitadel/internal/view/repository"
)
const (
userSessionTable = "auth.user_sessions"
)
func (v *View) UserSessionByIDs(agentID, userID string) (*model.UserSessionView, error) {
return view.UserSessionByIDs(v.Db, userSessionTable, agentID, userID)
}
func (v *View) UserSessionsByUserID(userID string) ([]*model.UserSessionView, error) {
return view.UserSessionsByUserID(v.Db, userSessionTable, userID)
}
func (v *View) UserSessionsByAgentID(agentID string) ([]*model.UserSessionView, error) {
return view.UserSessionsByAgentID(v.Db, userSessionTable, agentID)
}
func (v *View) ActiveUserSessions() ([]*model.UserSessionView, error) {
return view.ActiveUserSessions(v.Db, userSessionTable)
}
func (v *View) PutUserSession(userSession *model.UserSessionView, event *models.Event) error {
err := view.PutUserSession(v.Db, userSessionTable, userSession)
if err != nil {
return err
}
return v.ProcessedUserSessionSequence(event)
}
func (v *View) PutUserSessions(userSession []*model.UserSessionView, event *models.Event) error {
err := view.PutUserSessions(v.Db, userSessionTable, userSession...)
if err != nil {
return err
}
return v.ProcessedUserSessionSequence(event)
}
func (v *View) DeleteUserSessions(userID string, event *models.Event) error {
err := view.DeleteUserSessions(v.Db, userSessionTable, userID)
if err != nil && !errors.IsNotFound(err) {
return err
}
return v.ProcessedUserSessionSequence(event)
}
func (v *View) GetLatestUserSessionSequence(aggregateType string) (*repository.CurrentSequence, error) {
return v.latestSequence(userSessionTable, aggregateType)
}
func (v *View) ProcessedUserSessionSequence(event *models.Event) error {
return v.saveCurrentSequence(userSessionTable, event)
}
func (v *View) UpdateUserSessionSpoolerRunTimestamp() error {
return v.updateSpoolerRunSequence(userSessionTable)
}
func (v *View) GetLatestUserSessionFailedEvent(sequence uint64) (*repository.FailedEvent, error) {
return v.latestFailedEvent(userSessionTable, sequence)
}
func (v *View) ProcessedUserSessionFailedEvent(failedEvent *repository.FailedEvent) error {
return v.saveFailedEvent(failedEvent)
}