Enhance Notification System with New API Endpoints and Response Structures

- Added new endpoints for marking notifications as seen and retrieving detailed notification information for both admin and user contexts, improving the flexibility of the notification system.
- Implemented the MarkSeen and ViewNotification methods in the NotificationHandler, ensuring proper handling of notification visibility and details retrieval.
- Updated the NotificationService interface to include methods for getting notification details and marking notifications as seen, enhancing service capabilities.
- Enhanced the notification response structures to include additional fields such as Image, Seen, and ScheduledAt, providing richer data in API responses.
- Updated API documentation with Swagger comments for the new endpoints and response formats, ensuring clarity for API consumers.
This commit is contained in:
n.nakhostin
2025-09-21 11:26:54 +03:30
parent 0f981880b5
commit 5906904caf
12 changed files with 1200 additions and 45 deletions
+34 -8
View File
@@ -1,6 +1,8 @@
package notification
import (
"time"
"github.com/asaskevich/govalidator"
)
@@ -24,15 +26,15 @@ type NotificationMethods struct {
// NotificationRequest represents the request structure for sending notifications
type NotificationRequest struct {
UserID string `json:"user_id,omitempty" valid:"optional"`
Title string `json:"title" valid:"required"`
Message string `json:"message" valid:"required,length(1|1000)"`
Type string `json:"type" valid:"required,in(info|warning|alert|reject)"`
EventType EventType `json:"event_type" valid:"required,in(EMAIL|SMS|PUSH|OTP)"`
Priority string `json:"priority" valid:"required,in(low|medium|important)"`
UserID string `json:"user_id"`
Title string `json:"title"`
Message string `json:"message"`
Type string `json:"type"`
EventType EventType `json:"event_type"`
Priority string `json:"priority"`
ScheduledAt int64 `json:"scheduled_at"`
Metadata map[string]any `json:"metadata,omitempty" valid:"optional"`
Methods NotificationMethods `json:"methods" valid:"required"`
Metadata map[string]any `json:"metadata"`
Methods NotificationMethods `json:"methods"`
}
// NotificationResponse represents the successful response from notification service
@@ -40,6 +42,30 @@ type NotificationResponse struct {
Status string `json:"status"`
}
// DetailedNotificationResponse represents a detailed notification response
type DetailedNotificationResponse struct {
Data struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Title string `json:"title"`
Message string `json:"message"`
Link string `json:"link"`
Image string `json:"image"`
Type string `json:"type"` // info, warning, alert, reject
Priority string `json:"priority"` // low, medium, important
EventType string `json:"event_type"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Methods map[string]string `json:"methods"`
Metadata map[string]any `json:"metadata"`
Status string `json:"status"` // pending, sent, failed
Seen bool `json:"seen"`
SeenAt int64 `json:"seen_at"`
ScheduledAt int64 `json:"scheduled_at"`
IsScheduled bool `json:"is_scheduled"`
} `json:"data"`
}
// NotificationErrorResponse represents the error response from notification service
type NotificationErrorResponse struct {
Error string `json:"error"`