amocrm/internal/service/user.go

78 lines
2.1 KiB
Go

package service
import (
"context"
"fmt"
"go.uber.org/zap"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
)
func (s *Service) UpdateListUsers(ctx context.Context) error {
err := s.repository.AmoRepo.UpdateListUsers(ctx)
if err != nil {
return err
}
return nil
}
func (s *Service) GettingUserWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListResp, error) {
response, err := s.repository.AmoRepo.GettingUserWithPagination(ctx, req)
if err != nil {
s.logger.Error("error getting users with pagination", zap.Error(err))
return nil, err
}
return response, nil
}
func (s *Service) SoftDeleteAccount(ctx context.Context, accountID string) error {
err := s.repository.AmoRepo.SoftDeleteAccount(ctx, accountID)
if err != nil {
s.logger.Error("error soft delete current account in softDeleteAccount service", zap.Error(err))
return err
}
return nil
}
func (s *Service) GetCurrentAccount(ctx context.Context, accountID string) (*model.GetCurrentAccountResp, error) {
user, err := s.repository.AmoRepo.GetCurrentAccount(ctx, accountID)
if err != nil {
s.logger.Error("error getting current account in getCurrentAccount service", zap.Error(err))
return nil, err
}
response := model.GetCurrentAccountResp{
ID: user.ID,
Name: user.Name,
Subdomain: user.Subdomain,
Accountid: user.Accountid,
Amouserid: user.Amouserid,
Amocrmid: user.AmoID,
Country: user.Country,
Createdat: user.Createdat,
}
return &response, nil
}
func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*model.ConnectAccountResp, error) {
//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
//}
fmt.Println("AAAAAAAAAAAAAAAAA")
link, err := s.socialAuthClient.GenerateAmocrmAuthURL(accountID)
if err != nil {
s.logger.Error("error sending request to pena social auth service:", zap.Error(err))
}
response := model.ConnectAccountResp{
Link: link,
}
return &response, nil
}