Enhance Notification Management with New Endpoints and Response Structures
- Added new endpoints for retrieving notifications for both admins and users, improving the flexibility of the notification system. - Implemented query parameters for filtering notifications by status, method, event type, type, and recipient, enhancing usability. - Introduced new response structures for notifications, including pagination information, to provide better data handling in API responses. - Updated API documentation with Swagger comments for the new endpoints and response formats, ensuring clarity for API consumers. - Refactored notification handling logic to support the new features, promoting a more robust notification management system.
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
// NotificationService defines the interface for notification business logic
|
||||
type Service interface {
|
||||
Send(ctx context.Context, req *NotificationRequest) error
|
||||
GetNotifications(ctx context.Context, req *SearchForm, pagination *response.Pagination) (*NotificationListResponse, error)
|
||||
getUsers(ctx context.Context, userIDs []string) ([]notificationRecipient, error)
|
||||
getCustomers(ctx context.Context, values []string, target string) ([]notificationRecipient, error)
|
||||
}
|
||||
@@ -138,6 +139,63 @@ func (s *notificationService) Send(ctx context.Context, req *NotificationRequest
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *notificationService) GetNotifications(ctx context.Context, req *SearchForm, pagination *response.Pagination) (*NotificationListResponse, error) {
|
||||
s.logger.Info("Getting notifications", map[string]interface{}{
|
||||
"status": req.Status,
|
||||
"method": req.Method,
|
||||
"event_type": req.EventType,
|
||||
"type": req.Type,
|
||||
"recipient": req.Recipient,
|
||||
"limit": pagination.Limit,
|
||||
"offset": pagination.Offset,
|
||||
})
|
||||
|
||||
notifications, err := s.sdk.GetNotifications(ctx, ¬ification.GetNotificationsRequest{
|
||||
Status: req.Status,
|
||||
Method: req.Method,
|
||||
EventType: req.EventType,
|
||||
Type: req.Type,
|
||||
UserID: req.Recipient,
|
||||
PerPage: pagination.Limit,
|
||||
Page: pagination.Offset / pagination.Limit,
|
||||
})
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get notifications", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notificationsResponse := make([]*NotificationResponse, 0)
|
||||
for _, notification := range notifications.Data {
|
||||
notificationsResponse = append(notificationsResponse, &NotificationResponse{
|
||||
ID: notification.ID,
|
||||
UserID: notification.UserID,
|
||||
Title: notification.Title,
|
||||
Description: notification.Message,
|
||||
Link: ¬ification.Link,
|
||||
Priority: notification.Priority,
|
||||
Type: notification.Type,
|
||||
EventType: notification.EventType,
|
||||
Status: notification.Status,
|
||||
Methods: notification.Methods,
|
||||
Metadata: notification.Metadata,
|
||||
ScheduleAt: notification.ScheduledAt,
|
||||
})
|
||||
}
|
||||
|
||||
return &NotificationListResponse{
|
||||
Notifications: notificationsResponse,
|
||||
Meta: &response.Meta{
|
||||
Total: notifications.Pagination.Total,
|
||||
Limit: notifications.Pagination.PerPage,
|
||||
Offset: pagination.Offset,
|
||||
Page: notifications.Pagination.CurrentPage,
|
||||
Pages: notifications.Pagination.TotalPages,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *notificationService) getUsers(ctx context.Context, userIDs []string) ([]notificationRecipient, error) {
|
||||
recipients := make([]notificationRecipient, 0)
|
||||
offset := 0
|
||||
|
||||
Reference in New Issue
Block a user