github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/account_identity/account_identity.go (about) 1 package account_identity 2 3 import ( 4 "context" 5 6 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx" 7 "github.com/machinefi/w3bstream/pkg/enums" 8 "github.com/machinefi/w3bstream/pkg/errors/status" 9 "github.com/machinefi/w3bstream/pkg/models" 10 "github.com/machinefi/w3bstream/pkg/types" 11 ) 12 13 // GetBySFIDAndType get account identity from model by account id and identity type 14 func GetBySFIDAndType(ctx context.Context, id types.SFID, t enums.AccountIdentityType) (*models.AccountIdentity, error) { 15 d := types.MustMgrDBExecutorFromContext(ctx) 16 m := &models.AccountIdentity{ 17 RelAccount: models.RelAccount{AccountID: id}, 18 AccountIdentityInfo: models.AccountIdentityInfo{Type: t}, 19 } 20 21 if err := m.FetchByAccountIDAndType(d); err != nil { 22 if sqlx.DBErr(err).IsNotFound() { 23 return nil, status.AccountIdentityNotFound 24 } 25 return nil, status.DatabaseError.StatusErr().WithDesc(err.Error()) 26 } 27 return m, nil 28 }