Refactor Customer and User Repository Methods for ObjectID Handling
- Updated GetByIDs methods in customer and user repositories to convert string IDs to bson.ObjectID, ensuring proper handling of MongoDB object IDs. - Enhanced error handling for ID conversion to provide clearer feedback when invalid IDs are provided. - Modified notification service calls in customer and user services to use context.Background() for asynchronous email sending, improving concurrency management. - Ensured consistent handling of company IDs in the customer repository for retrieving customers by companies.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
@@ -48,7 +50,7 @@ func (h *NotificationHandler) Send(c echo.Context) error {
|
||||
}
|
||||
|
||||
// Send notification
|
||||
h.service.Send(c.Request().Context(), &req)
|
||||
go h.service.Send(context.Background(), &req)
|
||||
|
||||
return response.Created(c, nil, "Notification sent successfully")
|
||||
}
|
||||
|
||||
@@ -397,6 +397,10 @@ func (s *notificationService) getCustomers(ctx context.Context, values []string,
|
||||
recipients := make([]notificationRecipient, 0)
|
||||
|
||||
if target == string(TargetAudienceSpecificRole) {
|
||||
if len(values) == 0 {
|
||||
return nil, errors.New("no role provided")
|
||||
}
|
||||
|
||||
customers, err := s.customerService.GetCustomersByRole(ctx, values[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user