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:
@@ -20,6 +20,9 @@ type Repository interface {
|
||||
GetByID(ctx context.Context, id string) (*Customer, error)
|
||||
GetByEmail(ctx context.Context, email string) (*Customer, error)
|
||||
GetByUsername(ctx context.Context, username string) (*Customer, error)
|
||||
GetByIDs(ctx context.Context, ids []string) ([]Customer, error)
|
||||
GetByRole(ctx context.Context, role CustomerRole) ([]Customer, error)
|
||||
GetByCompanies(ctx context.Context, companies []string) ([]Customer, error)
|
||||
GetByCompanyID(ctx context.Context, companyID string, pagination *response.Pagination) ([]*Customer, int64, error)
|
||||
Search(ctx context.Context, form *SearchCustomersForm, pagination *response.Pagination) ([]Customer, int64, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
@@ -168,6 +171,48 @@ func (r *customerRepository) GetByUsername(ctx context.Context, username string)
|
||||
return customer, nil
|
||||
}
|
||||
|
||||
// GetByIDs retrieves customers by IDs
|
||||
func (r *customerRepository) GetByIDs(ctx context.Context, ids []string) ([]Customer, error) {
|
||||
customers, err := r.ormRepo.FindAll(ctx, bson.M{"_id": bson.M{"$in": ids}}, orm.NewPaginationBuilder().Limit(len(ids)).Build())
|
||||
if err != nil {
|
||||
if errors.Is(err, orm.ErrDocumentNotFound) {
|
||||
return nil, errors.New("customers not found")
|
||||
}
|
||||
r.logger.Error("Failed to get customers by IDs", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"ids": ids,
|
||||
})
|
||||
return nil, err
|
||||
}
|
||||
return customers.Items, nil
|
||||
}
|
||||
|
||||
// GetByRole retrieves customers by role
|
||||
func (r *customerRepository) GetByRole(ctx context.Context, role CustomerRole) ([]Customer, error) {
|
||||
customers, err := r.ormRepo.FindAll(ctx, bson.M{"role": role}, orm.NewPaginationBuilder().Build())
|
||||
if err != nil {
|
||||
if errors.Is(err, orm.ErrDocumentNotFound) {
|
||||
return nil, errors.New("customers not found")
|
||||
}
|
||||
r.logger.Error("Failed to get customers by role", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"role": role,
|
||||
})
|
||||
return nil, err
|
||||
}
|
||||
return customers.Items, nil
|
||||
}
|
||||
|
||||
// GetByCompanies retrieves customers by companies
|
||||
|
||||
func (r *customerRepository) GetByCompanies(ctx context.Context, companies []string) ([]Customer, error) {
|
||||
customers, err := r.ormRepo.FindAll(ctx, bson.M{"companies": bson.M{"$in": companies}}, orm.NewPaginationBuilder().Build())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return customers.Items, nil
|
||||
}
|
||||
|
||||
// GetByCompanyID retrieves customers by company ID with pagination
|
||||
func (r *customerRepository) GetByCompanyID(ctx context.Context, companyID string, pagination *response.Pagination) ([]*Customer, int64, error) {
|
||||
// Build pagination
|
||||
|
||||
Reference in New Issue
Block a user