test get list user passed
This commit is contained in:
parent
c3d20a9d5f
commit
c90d1dfb31
@ -6,15 +6,13 @@ type RequestGetListUsers struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResponseGetListUsers struct {
|
type ResponseGetListUsers struct {
|
||||||
TotalItems int `json:"_total_items"`
|
TotalItems int `json:"_total_items"`
|
||||||
//Page int `json:"_page"`
|
Links LinksSelf `json:"_links"`
|
||||||
//PageCount int `json:"_page_count"`
|
Embedded EmbeddedGetListUsers `json:"_embedded"`
|
||||||
Links LinksSelf `json:"_links"`
|
|
||||||
Embedded EmbeddedGetListUsers `json:"_embedded"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmbeddedGetListUsers struct {
|
type EmbeddedGetListUsers struct {
|
||||||
Users []Users `json:"users"`
|
Users []Users `json:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SelfLink struct {
|
type SelfLink struct {
|
||||||
@ -26,18 +24,17 @@ type LinksSelf struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Users struct {
|
type Users struct {
|
||||||
ID int32 `json:"id"`
|
ID int32 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
IsConfirmed bool `json:"is_confirmed"`
|
IsConfirmed bool `json:"is_confirmed"`
|
||||||
ConfirmLinkSentAt int `json:"confirm_link_sent_at"`
|
ConfirmLinkSentAt int `json:"confirm_link_sent_at"`
|
||||||
Lang string `json:"lang"`
|
Lang string `json:"lang"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Groups Groups `json:"groups"`
|
Groups []Groups `json:"groups"`
|
||||||
//Rights Rights `json:"rights"`
|
Links SelfLink `json:"_links"`
|
||||||
Links SelfLink `json:"_links"`
|
Rights Rights `json:"_embedded"`
|
||||||
Embedded Embedded `json:"_embedded"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Rights struct {
|
type Rights struct {
|
||||||
@ -51,9 +48,9 @@ type Rights struct {
|
|||||||
IsAdmin bool `json:"is_admin"`
|
IsAdmin bool `json:"is_admin"`
|
||||||
IsFree bool `json:"is_free"`
|
IsFree bool `json:"is_free"`
|
||||||
IsActive bool `json:"is_active"`
|
IsActive bool `json:"is_active"`
|
||||||
GroupID *int `json:"group_id,omitempty"`
|
GroupID int `json:"group_id,omitempty"`
|
||||||
RoleID *int `json:"role_id,omitempty"`
|
RoleID int `json:"role_id,omitempty"`
|
||||||
Role *string `json:"role,omitempty"`
|
Role string `json:"role,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Leads struct {
|
type Leads struct {
|
||||||
|
@ -34,6 +34,7 @@ func NewDataUpdaterWC(deps Deps) *DataUpdater {
|
|||||||
func (wc *DataUpdater) Start(ctx context.Context) {
|
func (wc *DataUpdater) Start(ctx context.Context) {
|
||||||
nextStart := calculateTime()
|
nextStart := calculateTime()
|
||||||
ticker := time.NewTicker(time.Second * time.Duration(nextStart))
|
ticker := time.NewTicker(time.Second * time.Duration(nextStart))
|
||||||
|
//ticker := time.NewTicker(10 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -234,24 +235,22 @@ func (wc *DataUpdater) UserUpdater(ctx context.Context, allTokens []model.Token)
|
|||||||
for _, token := range allTokens {
|
for _, token := range allTokens {
|
||||||
page := 1
|
page := 1
|
||||||
limit := 250
|
limit := 250
|
||||||
for {
|
userData, err := wc.amoClient.GetUserList(models.RequestGetListUsers{
|
||||||
userData, err := wc.amoClient.GetUserList(models.RequestGetListUsers{
|
Page: page,
|
||||||
Page: page,
|
Limit: limit,
|
||||||
Limit: limit,
|
}, token.AccessToken)
|
||||||
}, token.AccessToken)
|
if err != nil {
|
||||||
if err != nil {
|
wc.logger.Error("error getting user list", zap.Error(err))
|
||||||
wc.logger.Error("error getting user list", zap.Error(err))
|
break
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if userData == nil || len(userData.Embedded.Users) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
listUser[token.AccountID] = append(listUser[token.AccountID], userData.Embedded.Users...)
|
|
||||||
|
|
||||||
page++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if userData == nil || len(userData.Embedded.Users) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
listUser[token.AccountID] = append(listUser[token.AccountID], userData.Embedded.Users...)
|
||||||
|
|
||||||
|
page++
|
||||||
}
|
}
|
||||||
|
|
||||||
for accountID, users := range listUser {
|
for accountID, users := range listUser {
|
||||||
@ -261,14 +260,23 @@ func (wc *DataUpdater) UserUpdater(ctx context.Context, allTokens []model.Token)
|
|||||||
}
|
}
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
if user.ID == mainAccount.AmoID {
|
if user.ID == mainAccount.AmoID {
|
||||||
|
err := wc.repo.AmoRepo.CheckMainUser(ctx, model.User{
|
||||||
|
Name: user.Name,
|
||||||
|
Role: int32(user.Rights.RoleID),
|
||||||
|
Group: int32(user.Rights.GroupID),
|
||||||
|
Email: user.Email,
|
||||||
|
AmoID: user.ID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := wc.repo.AmoRepo.CheckAndUpdateUsers(ctx, model.User{
|
err := wc.repo.AmoRepo.CheckAndUpdateUsers(ctx, model.User{
|
||||||
AmoID: user.ID,
|
AmoID: user.ID,
|
||||||
Name: user.FullName,
|
Name: user.FullName,
|
||||||
Group: int32(*user.Embedded.Rights.GroupID),
|
Group: int32(user.Rights.GroupID),
|
||||||
Role: int32(*user.Embedded.Rights.RoleID),
|
Role: int32(user.Rights.RoleID),
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Amouserid: mainAccount.Amouserid,
|
Amouserid: mainAccount.Amouserid,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user