2024-04-09 15:52:37 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"amocrm/internal/models"
|
|
|
|
"context"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Service) UpdateListUsers(ctx context.Context) error {
|
|
|
|
|
|
|
|
err := s.repository.UpdateListUsers(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) GettingUserFromCash(ctx context.Context) (*models.UserListResp, error) {
|
|
|
|
|
|
|
|
response, err := s.repository.GettingUserFromCash(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return response, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) SoftDeleteAccount(ctx context.Context) error {
|
|
|
|
|
|
|
|
err := s.repository.SoftDeleteAccount(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) GetCurrentAccount(ctx context.Context) (*models.GetCurrentAccountResp, error) {
|
|
|
|
|
|
|
|
response, err := s.repository.GetCurrentAccount(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return response, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*models.ConnectAccountResp, error) {
|
|
|
|
err := s.repository.CreateAccount(ctx, accountID)
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("error create account in connectAccount service", zap.Error(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
|
|
|
response := models.ConnectAccountResp{
|
|
|
|
Link: link,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &response, nil
|
|
|
|
}
|