mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-15 01:57:41 +00:00
use global id generator (#142)
* use global id generator * remove duplicate `UserRemoved` Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -7,16 +7,15 @@ import (
|
||||
es_int "github.com/caos/zitadel/internal/eventstore"
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
es_sdk "github.com/caos/zitadel/internal/eventstore/sdk"
|
||||
"github.com/caos/zitadel/internal/id"
|
||||
grant_model "github.com/caos/zitadel/internal/usergrant/model"
|
||||
"github.com/caos/zitadel/internal/usergrant/repository/eventsourcing/model"
|
||||
"github.com/sony/sonyflake"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type UserGrantEventStore struct {
|
||||
es_int.Eventstore
|
||||
userGrantCache *UserGrantCache
|
||||
idGenerator *sonyflake.Sonyflake
|
||||
idGenerator id.Generator
|
||||
}
|
||||
|
||||
type UserGrantConfig struct {
|
||||
@@ -29,11 +28,10 @@ func StartUserGrant(conf UserGrantConfig) (*UserGrantEventStore, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
idGenerator := sonyflake.NewSonyflake(sonyflake.Settings{})
|
||||
return &UserGrantEventStore{
|
||||
Eventstore: conf.Eventstore,
|
||||
userGrantCache: userGrantCache,
|
||||
idGenerator: idGenerator,
|
||||
idGenerator: id.SonyFlakeGenerator,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -59,11 +57,12 @@ func (es *UserGrantEventStore) AddUserGrant(ctx context.Context, grant *grant_mo
|
||||
if grant == nil || !grant.IsValid() {
|
||||
return nil, caos_errs.ThrowPreconditionFailed(nil, "EVENT-sdiw3", "User grant invalid")
|
||||
}
|
||||
id, err := es.idGenerator.NextID()
|
||||
//TODO: Check Uniqueness
|
||||
id, err := es.idGenerator.Next()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
grant.AggregateID = strconv.FormatUint(id, 10)
|
||||
grant.AggregateID = id
|
||||
|
||||
repoGrant := model.UserGrantFromModel(grant)
|
||||
|
||||
|
@@ -5,9 +5,9 @@ import (
|
||||
mock_cache "github.com/caos/zitadel/internal/cache/mock"
|
||||
"github.com/caos/zitadel/internal/eventstore/mock"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/id"
|
||||
"github.com/caos/zitadel/internal/usergrant/repository/eventsourcing/model"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/sony/sonyflake"
|
||||
)
|
||||
|
||||
func GetMockedEventstore(ctrl *gomock.Controller, mockEs *mock.MockEventstore) *UserGrantEventStore {
|
||||
@@ -25,8 +25,8 @@ func GetMockCache(ctrl *gomock.Controller) *UserGrantCache {
|
||||
return &UserGrantCache{userGrantCache: mockCache}
|
||||
}
|
||||
|
||||
func GetSonyFlacke() *sonyflake.Sonyflake {
|
||||
return sonyflake.NewSonyflake(sonyflake.Settings{})
|
||||
func GetSonyFlacke() id.Generator {
|
||||
return id.SonyFlakeGenerator
|
||||
}
|
||||
|
||||
func GetMockUserGrantByIDOK(ctrl *gomock.Controller) *UserGrantEventStore {
|
||||
|
Reference in New Issue
Block a user