MiniappGoService/internal/domains/profile/service/checkUser.go

24 lines
680 B
Go

package profileService
import (
"errors"
"fmt"
"gitea.cybertalant.ru/VisionCareerMiniapp/MiniappGoService/internal/application/types"
)
func (t *service) CheckUser(id int64, username *string) (*types.User, error) {
op := "profileService/CheckUsers"
// Check if there is a user with this tg_id
existUser, err := t.profileRepository.GetUserById(id)
if existUser == nil && err == nil {
existUser, err = t.profileRepository.CreateUser(id, username)
}
if err != nil || existUser == nil {
t.logger.Error(fmt.Sprintf("%v: %v", op, err.Error()))
return nil, errors.New("an error occurred while checking if user with this telegram id exist")
}
return existUser, nil
}