mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-19 22:37:35 +00:00
59 lines
2.0 KiB
Go
59 lines
2.0 KiB
Go
|
package view
|
||
|
|
||
|
import (
|
||
|
"github.com/jinzhu/gorm"
|
||
|
|
||
|
global_model "github.com/caos/zitadel/internal/model"
|
||
|
usr_model "github.com/caos/zitadel/internal/user/model"
|
||
|
"github.com/caos/zitadel/internal/user/repository/view/model"
|
||
|
"github.com/caos/zitadel/internal/view"
|
||
|
)
|
||
|
|
||
|
func UserSessionByID(db *gorm.DB, table, sessionID string) (*model.UserSessionView, error) {
|
||
|
userSession := new(model.UserSessionView)
|
||
|
query := view.PrepareGetByKey(table, model.UserSessionSearchKey(usr_model.USERSESSIONSEARCHKEY_SESSION_ID), sessionID)
|
||
|
err := query(db, userSession)
|
||
|
return userSession, err
|
||
|
}
|
||
|
|
||
|
func UserSessionByIDs(db *gorm.DB, table, agentID, userID string) (*model.UserSessionView, error) {
|
||
|
userSession := new(model.UserSessionView)
|
||
|
userAgentQuery := model.UserSessionSearchQuery{
|
||
|
Key: usr_model.USERSESSIONSEARCHKEY_USER_AGENT_ID,
|
||
|
Method: global_model.SEARCHMETHOD_EQUALS,
|
||
|
Value: agentID,
|
||
|
}
|
||
|
userQuery := model.UserSessionSearchQuery{
|
||
|
Key: usr_model.USERSESSIONSEARCHKEY_USER_ID,
|
||
|
Method: global_model.SEARCHMETHOD_EQUALS,
|
||
|
Value: userID,
|
||
|
}
|
||
|
query := view.PrepareGetByQuery(table, userAgentQuery, userQuery)
|
||
|
err := query(db, userSession)
|
||
|
return userSession, err
|
||
|
}
|
||
|
|
||
|
func UserSessionsByAgentID(db *gorm.DB, table, agentID string) ([]*model.UserSessionView, error) {
|
||
|
userSessions := make([]*model.UserSessionView, 0)
|
||
|
userAgentQuery := &usr_model.UserSessionSearchQuery{
|
||
|
Key: usr_model.USERSESSIONSEARCHKEY_USER_AGENT_ID,
|
||
|
Method: global_model.SEARCHMETHOD_EQUALS,
|
||
|
Value: agentID,
|
||
|
}
|
||
|
query := view.PrepareSearchQuery(table, model.UserSessionSearchRequest{
|
||
|
Queries: []*usr_model.UserSessionSearchQuery{userAgentQuery},
|
||
|
})
|
||
|
_, err := query(db, userSessions)
|
||
|
return userSessions, err
|
||
|
}
|
||
|
|
||
|
func PutUserSession(db *gorm.DB, table string, session *model.UserSessionView) error {
|
||
|
save := view.PrepareSave(table)
|
||
|
return save(db, session)
|
||
|
}
|
||
|
|
||
|
func DeleteUserSession(db *gorm.DB, table, sessionID string) error {
|
||
|
delete := view.PrepareDeleteByKey(table, model.UserSessionSearchKey(usr_model.USERSESSIONSEARCHKEY_USER_ID), sessionID)
|
||
|
return delete(db)
|
||
|
}
|