Add License Integration

This commit is contained in:
aditya.siregar
2024-08-02 00:51:54 +07:00
parent 5e26402c10
commit c1ae2fd14a
9 changed files with 92 additions and 29 deletions
+14 -1
View File
@@ -21,11 +21,13 @@ type AuthServiceImpl struct {
emailSvc repository.EmailService
emailCfg config.Email
trxRepo repository.TransactionManager
license repository.License
}
func New(authRepo repository.Auth,
crypto repository.Crypto, user repository.User, emailSvc repository.EmailService,
emailCfg config.Email, trxRepo repository.TransactionManager,
license repository.License,
) *AuthServiceImpl {
return &AuthServiceImpl{
authRepo: authRepo,
@@ -34,6 +36,7 @@ func New(authRepo repository.Auth,
emailSvc: emailSvc,
emailCfg: emailCfg,
trxRepo: trxRepo,
license: license,
}
}
@@ -57,8 +60,18 @@ func (u *AuthServiceImpl) AuthenticateUser(ctx context.Context, email, password
if err != nil {
return nil, err
}
var licensePartner entity.PartnerLicense
return user.ToUserAuthenticate(signedToken), nil
if user.PartnerID != nil {
parterLicense, err := u.license.FindByPartnerIDMaxEndDate(ctx, user.PartnerID)
if err != nil {
logger.ContextLogger(ctx).Error("error when get user license", zap.Error(err))
return nil, errors.ErrorInternalServer
}
licensePartner = parterLicense.ToPartnerLicense()
}
return user.ToUserAuthenticate(signedToken, licensePartner), nil
}
func (u *AuthServiceImpl) SendPasswordResetLink(ctx context.Context, email string) error {
+1 -1
View File
@@ -42,7 +42,7 @@ type ServiceManagerImpl struct {
func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl) *ServiceManagerImpl {
return &ServiceManagerImpl{
AuthSvc: auth.New(repo.Auth, repo.Crypto, repo.User, repo.EmailService, cfg.Email, repo.Trx),
AuthSvc: auth.New(repo.Auth, repo.Crypto, repo.User, repo.EmailService, cfg.Email, repo.Trx, repo.License),
EventSvc: event.NewEventService(repo.Event),
UserSvc: users.NewUserService(repo.User, repo.Branch),
BranchSvc: branch.NewBranchService(repo.Branch),