Refactor Notification Management and Enhance Customer Features

- Updated the notification handling logic to utilize a new SDK for sending notifications, improving the flexibility and scalability of the notification system.
- Introduced new methods in the notification service for sending notifications to users and customers based on various target audience types, enhancing the notification delivery capabilities.
- Added a new endpoint to assign companies to a customer, improving customer management functionalities.
- Refactored the customer entity and forms to replace 'CompanyIDs' with 'Companies', ensuring consistency across the data model.
- Enhanced API documentation with Swagger comments for the new endpoint and updated notification structures, ensuring clarity for API consumers.
This commit is contained in:
n.nakhostin
2025-09-20 16:54:51 +03:30
parent d2f7c6a1e5
commit 9037cb5917
18 changed files with 607 additions and 1471 deletions
+62
View File
@@ -29,6 +29,9 @@ type Service interface {
Register(ctx context.Context, form *CreateCustomerForm) (*CustomerResponse, error)
GetByID(ctx context.Context, id string) (*CustomerResponse, error)
Search(ctx context.Context, form *SearchCustomersForm, pagination *response.Pagination) (*CustomerListResponse, error)
GetCustomersByIDs(ctx context.Context, ids []string) (*CustomerListResponse, error)
GetCustomersByRole(ctx context.Context, role string) (*CustomerListResponse, error)
GetCustomersByCompanies(ctx context.Context, companies []string) (*CustomerListResponse, error)
Update(ctx context.Context, id string, form *UpdateCustomerForm) (*CustomerResponse, error)
Delete(ctx context.Context, id string) error
UpdateStatus(ctx context.Context, id string, form *UpdateStatusForm) error
@@ -206,6 +209,65 @@ func (s *customerService) Search(ctx context.Context, form *SearchCustomersForm,
}, nil
}
// GetCustomersByIDs retrieves customers by IDs
func (s *customerService) GetCustomersByIDs(ctx context.Context, ids []string) (*CustomerListResponse, error) {
customers, err := s.repository.GetByIDs(ctx, ids)
if err != nil {
return nil, err
}
var customerResponses []*CustomerResponse
for _, customer := range customers {
customerResponses = append(customerResponses, customer.ToResponse(nil))
}
return &CustomerListResponse{
Customers: customerResponses,
}, nil
}
// GetCustomersByRole retrieves customers by role
func (s *customerService) GetCustomersByRole(ctx context.Context, role string) (*CustomerListResponse, error) {
customers, err := s.repository.GetByRole(ctx, CustomerRole(role))
if err != nil {
s.logger.Error("Failed to get customers by role", map[string]interface{}{
"error": err.Error(),
"role": role,
})
return nil, err
}
var customerResponses []*CustomerResponse
for _, customer := range customers {
customerResponses = append(customerResponses, customer.ToResponse(nil))
}
return &CustomerListResponse{
Customers: customerResponses,
}, nil
}
// GetCustomersByCompanies retrieves customers by companies
func (s *customerService) GetCustomersByCompanies(ctx context.Context, companies []string) (*CustomerListResponse, error) {
customers, err := s.repository.GetByCompanies(ctx, companies)
if err != nil {
s.logger.Error("Failed to get customers by companies", map[string]interface{}{
"error": err.Error(),
"companies": companies,
})
return nil, err
}
var customerResponses []*CustomerResponse
for _, customer := range customers {
customerResponses = append(customerResponses, customer.ToResponse(nil))
}
return &CustomerListResponse{
Customers: customerResponses,
}, nil
}
// Update updates a customer
func (s *customerService) Update(ctx context.Context, id string, form *UpdateCustomerForm) (*CustomerResponse, error) {
// Get existing customer