Add AllMarkSeen Functionality to Notification System
- Introduced the AllMarkSeen method in the notification service to mark all notifications as seen for a user, enhancing user experience by allowing bulk actions on notifications. - Implemented the PublicAllMarkSeen handler to handle HTTP requests for marking all notifications as seen, ensuring proper request validation and response handling. - Updated the notification client and SDK to support the new AllMarkSeen functionality, improving the overall API capabilities. - Enhanced API documentation with Swagger comments for the new endpoint, ensuring clarity for API consumers.
This commit is contained in:
@@ -295,6 +295,33 @@ func (h *NotificationHandler) PublicMarkSeen(c echo.Context) error {
|
||||
return response.Success(c, nil, "Notification marked as seen successfully")
|
||||
}
|
||||
|
||||
// AllMarkSeen marks all notifications as seen for a user
|
||||
// @Summary Mark all notifications as seen for a user
|
||||
// @Description Mark all notifications as seen for a user
|
||||
// @Tags Notification
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param user_id path string true "User ID"
|
||||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security BearerAuth
|
||||
// @Router /api/v1/notifications/all-seen/{user_id} [get]
|
||||
func (h *NotificationHandler) PublicAllMarkSeen(c echo.Context) error {
|
||||
userID, err := customer.GetCustomerIDFromContext(c)
|
||||
if err != nil {
|
||||
return response.BadRequest(c, "user ID is required", "User ID must be provided")
|
||||
}
|
||||
|
||||
// Mark all notifications as seen
|
||||
err = h.service.AllMarkSeen(c.Request().Context(), userID)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to mark all notifications as seen")
|
||||
}
|
||||
|
||||
return response.Success(c, nil, "All notifications marked as seen successfully")
|
||||
}
|
||||
|
||||
// ViewNotification gets a single notification by ID
|
||||
// @Summary Get notification details
|
||||
// @Description Get detailed information about a specific notification
|
||||
|
||||
@@ -20,6 +20,7 @@ type Service interface {
|
||||
GetNotifications(ctx context.Context, req *SearchForm, pagination *response.Pagination) (*NotificationListResponse, error)
|
||||
GetNotification(ctx context.Context, notificationID string) (*NotificationResponse, error)
|
||||
MarkSeen(ctx context.Context, notificationID, userID string) error
|
||||
AllMarkSeen(ctx context.Context, userID string) error
|
||||
getUsers(ctx context.Context, userIDs []string) ([]notificationRecipient, error)
|
||||
getCustomers(ctx context.Context, values []string, target string) ([]notificationRecipient, error)
|
||||
}
|
||||
@@ -308,6 +309,18 @@ func (s *notificationService) MarkSeen(ctx context.Context, notificationID, user
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *notificationService) AllMarkSeen(ctx context.Context, userID string) error {
|
||||
s.logger.Info("Marking all notifications as seen", map[string]interface{}{
|
||||
"user_id": userID,
|
||||
})
|
||||
|
||||
_, err := s.sdk.AllMarkSeen(ctx, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return 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