Live video on the AT Protocol
79
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v0.8.13 50 lines 1.4 kB view raw
1package statedb 2 3import ( 4 "errors" 5 6 "github.com/streamplace/oatproxy/pkg/oatproxy" 7 "gorm.io/gorm" 8) 9 10func (state *StatefulDB) CreateOAuthSession(id string, session *oatproxy.OAuthSession) error { 11 return state.DB.Create(session).Error 12} 13 14func (state *StatefulDB) LoadOAuthSession(id string) (*oatproxy.OAuthSession, error) { 15 var session oatproxy.OAuthSession 16 if err := state.DB.Where("downstream_dpop_jkt = ?", id).First(&session).Error; err != nil { 17 if errors.Is(err, gorm.ErrRecordNotFound) { 18 return nil, nil 19 } 20 return nil, err 21 } 22 return &session, nil 23} 24 25func (state *StatefulDB) UpdateOAuthSession(id string, session *oatproxy.OAuthSession) error { 26 res := state.DB.Model(&oatproxy.OAuthSession{}).Where("downstream_dpop_jkt = ?", id).Updates(session) 27 if res.Error != nil { 28 return res.Error 29 } 30 if res.RowsAffected == 0 { 31 return errors.New("no rows affected") 32 } 33 return nil 34} 35 36func (state *StatefulDB) ListOAuthSessions() ([]oatproxy.OAuthSession, error) { 37 var sessions []oatproxy.OAuthSession 38 if err := state.DB.Find(&sessions).Error; err != nil { 39 return nil, err 40 } 41 return sessions, nil 42} 43 44func (state *StatefulDB) GetSessionByDID(did string) (*oatproxy.OAuthSession, error) { 45 var session oatproxy.OAuthSession 46 if err := state.DB.Where("repo_did = ? AND revoked_at IS NULL", did).Order("updated_at DESC").First(&session).Error; err != nil { 47 return nil, err 48 } 49 return &session, nil 50}