Integrate Notification Service into Tender Management System

- Added a new notification service to handle various notification types (email, SMS, push, OTP).
- Implemented configuration for the notification service, allowing customization via environment variables.
- Updated user and customer services to utilize the notification service for sending welcome emails and status updates.
- Introduced a builder pattern for constructing notification requests, enhancing usability and flexibility.
- Enhanced error handling and logging for notification operations, ensuring robust service integration.
- Updated documentation to include usage examples and configuration details for the new notification SDK.
This commit is contained in:
n.nakhostin
2025-09-16 15:35:36 +03:30
parent 05a307e345
commit 108629278a
15 changed files with 1429 additions and 21 deletions
+19 -9
View File
@@ -3,10 +3,12 @@ package user
import (
"context"
"errors"
"fmt"
"strings"
"time"
"tm/pkg/authorization"
"tm/pkg/logger"
"tm/pkg/notification"
"tm/pkg/response"
"go.mongodb.org/mongo-driver/v2/bson"
@@ -34,19 +36,21 @@ type Service interface {
// userService implements the Service interface
type userService struct {
repository Repository
logger logger.Logger
authService authorization.AuthorizationService
validator ValidationService
repository Repository
logger logger.Logger
authService authorization.AuthorizationService
validator ValidationService
notification notification.SDK
}
// NewUserService creates a new user service
func NewUserService(repository Repository, logger logger.Logger, authService authorization.AuthorizationService, validator ValidationService) Service {
func NewUserService(repository Repository, logger logger.Logger, authService authorization.AuthorizationService, validator ValidationService, notificationSDK notification.SDK) Service {
return &userService{
repository: repository,
logger: logger,
authService: authService,
validator: validator,
repository: repository,
logger: logger,
authService: authService,
validator: validator,
notification: notificationSDK,
}
}
@@ -112,6 +116,8 @@ func (s *userService) Register(ctx context.Context, form *CreateUserForm) (*User
"role": user.Role,
})
go s.notification.SendEmail(ctx, form.Email, fmt.Sprintf("Welcome to Tender Management\nUsername: %s\nPassword: %s", form.Username, form.Password), user.ID.Hex())
return user.ToResponse(), nil
}
@@ -214,6 +220,8 @@ func (s *userService) UpdateStatus(ctx context.Context, id string, form *UpdateU
"status": form.Status,
})
go s.notification.SendEmail(ctx, user.Email, fmt.Sprintf("Your account has been %s", strings.ToUpper(form.Status)), user.ID.Hex())
return nil
}
@@ -442,6 +450,8 @@ func (s *userService) ChangePassword(ctx context.Context, userID string, form *C
"user_id": userID,
})
go s.notification.SendEmail(ctx, user.Email, "Your password has been reset successfully", user.ID.Hex())
return nil
}