From 7145977250b533218ce82ab4be0149b4ff18d189 Mon Sep 17 00:00:00 2001 From: "m.nazemi" Date: Wed, 15 Apr 2026 15:53:51 +0330 Subject: [PATCH] get notification fix --- internal/notification/handler.go | 11 +++++++++++ internal/notification/service.go | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/internal/notification/handler.go b/internal/notification/handler.go index 678f2ee..706e2f8 100644 --- a/internal/notification/handler.go +++ b/internal/notification/handler.go @@ -259,6 +259,17 @@ func (h *NotificationHandler) CustomerNotifications(c echo.Context) error { // Call service notifications, err := h.service.GetNotifications(c.Request().Context(), form, pagination) if err != nil { + // Log the actual error for debugging + c.Logger().Error("GetNotifications failed", map[string]interface{}{ + "error": err.Error(), + "status": form.Status, + "priority": form.Priority, + "eventType": form.EventType, + "recipient": form.Recipient, + "limit": pagination.Limit, + "offset": pagination.Offset, + "page": (pagination.Offset / pagination.Limit) + 1, + }) return response.InternalServerError(c, "Failed to get notifications") } diff --git a/internal/notification/service.go b/internal/notification/service.go index ed8821a..3158b46 100644 --- a/internal/notification/service.go +++ b/internal/notification/service.go @@ -201,7 +201,7 @@ func (s *notificationService) GetNotifications(ctx context.Context, req *SearchF Seen: req.Seen, Priority: req.Priority, PerPage: pagination.Limit, - Page: pagination.Offset / pagination.Limit, + Page: (pagination.Offset / pagination.Limit) + 1, // Convert 0-based offset to 1-based page number }) if err != nil { s.logger.Error("Failed to get notifications", map[string]interface{}{ @@ -233,13 +233,25 @@ func (s *notificationService) GetNotifications(ctx context.Context, req *SearchF recipient = cust } + // Handle Link pointer - return nil if empty + var linkPtr *string + if notification.Link != "" { + linkPtr = ¬ification.Link + } + + // Handle Image pointer - return nil if empty + var imagePtr *string + if notification.Image != "" { + imagePtr = ¬ification.Image + } + notificationsResponse = append(notificationsResponse, &NotificationResponse{ ID: notification.ID, UserID: notification.UserID, Recipient: recipient, Title: notification.Title, Message: notification.Message, - Link: ¬ification.Link, + Link: linkPtr, Priority: notification.Priority, Type: notification.Type, EventType: notification.EventType, @@ -248,7 +260,7 @@ func (s *notificationService) GetNotifications(ctx context.Context, req *SearchF Metadata: notification.Metadata, ScheduleAt: notification.ScheduledAt, IsScheduled: notification.IsScheduled, - Image: ¬ification.Image, + Image: imagePtr, Seen: notification.Seen, SeenAt: notification.SeenAt, ScheduledAt: notification.ScheduledAt,