2024-04-09 15:52:37 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"go.uber.org/zap"
|
2024-04-17 12:21:06 +00:00
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
2024-04-09 15:52:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Service) UpdateListUsers(ctx context.Context) error {
|
|
|
|
|
2024-04-17 12:21:06 +00:00
|
|
|
err := s.repository.AmoRepo.UpdateListUsers(ctx)
|
2024-04-09 15:52:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:23:19 +00:00
|
|
|
func (s *Service) GettingUserWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListResp, error) {
|
|
|
|
response, err := s.repository.AmoRepo.GettingUserWithPagination(ctx, req)
|
2024-04-09 15:52:37 +00:00
|
|
|
if err != nil {
|
2024-04-12 16:39:51 +00:00
|
|
|
s.logger.Error("error getting users with pagination", zap.Error(err))
|
2024-04-09 15:52:37 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return response, nil
|
|
|
|
}
|
|
|
|
|
2024-04-11 09:55:26 +00:00
|
|
|
func (s *Service) SoftDeleteAccount(ctx context.Context, accountID string) error {
|
2024-04-17 12:21:06 +00:00
|
|
|
err := s.repository.AmoRepo.SoftDeleteAccount(ctx, accountID)
|
2024-04-09 15:52:37 +00:00
|
|
|
if err != nil {
|
2024-04-11 09:55:26 +00:00
|
|
|
s.logger.Error("error soft delete current account in softDeleteAccount service", zap.Error(err))
|
2024-04-09 15:52:37 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-04-17 12:21:06 +00:00
|
|
|
func (s *Service) GetCurrentAccount(ctx context.Context, accountID string) (*model.GetCurrentAccountResp, error) {
|
|
|
|
user, err := s.repository.AmoRepo.GetCurrentAccount(ctx, accountID)
|
2024-04-09 15:52:37 +00:00
|
|
|
if err != nil {
|
2024-04-11 09:55:26 +00:00
|
|
|
s.logger.Error("error getting current account in getCurrentAccount service", zap.Error(err))
|
2024-04-09 15:52:37 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-04-11 09:55:26 +00:00
|
|
|
|
2024-04-17 12:21:06 +00:00
|
|
|
response := model.GetCurrentAccountResp{
|
2024-04-11 09:55:26 +00:00
|
|
|
ID: user.ID,
|
|
|
|
Name: user.Name,
|
|
|
|
Subdomain: user.Subdomain,
|
|
|
|
Accountid: user.Accountid,
|
|
|
|
Amouserid: user.Amouserid,
|
2024-04-17 12:21:06 +00:00
|
|
|
Amocrmid: user.AmoID,
|
2024-04-11 09:55:26 +00:00
|
|
|
Country: user.Country,
|
|
|
|
Createdat: user.Createdat,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &response, nil
|
2024-04-09 15:52:37 +00:00
|
|
|
}
|
|
|
|
|
2024-04-17 12:21:06 +00:00
|
|
|
func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*model.ConnectAccountResp, error) {
|
2024-04-17 16:34:31 +00:00
|
|
|
//err := s.repository.AmoRepo.CreateAccount(ctx, accountID)
|
|
|
|
//if err != nil {
|
|
|
|
// s.logger.Error("error create account in connectAccount service", zap.Error(err))
|
|
|
|
// return nil, err
|
|
|
|
//}
|
2024-04-09 15:52:37 +00:00
|
|
|
|
2024-04-09 16:53:23 +00:00
|
|
|
shifr, err := s.encrypt.EncryptStr(accountID)
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("error encrypted account id in service ConnectAccount:", zap.Error(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
link, err := s.socialAuthClient.GenerateAmocrmAuthURL(string(shifr))
|
2024-04-09 15:52:37 +00:00
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("error sending request to pena social auth service:", zap.Error(err))
|
|
|
|
}
|
|
|
|
|
2024-04-17 12:21:06 +00:00
|
|
|
response := model.ConnectAccountResp{
|
2024-04-09 15:52:37 +00:00
|
|
|
Link: link,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &response, nil
|
|
|
|
}
|