Files
Mazyar 534213f10e
continuous-integration/drone/push Build is passing
Enhance notification search functionality with user ID filtering
- Added a new `UserID` field to the `SearchForm` to allow filtering notifications by user ID.
- Implemented the `ResolvedRecipients` method to return user IDs based on the `user_id` or `recipient` query parameters, improving the flexibility of notification searches.
- Updated the `GetNotifications` method in the service layer to utilize the new recipient resolution logic, ensuring accurate retrieval of notifications based on user ID.

This update enhances the notification management capabilities, providing more granular control over notification searches.
2026-06-28 11:04:24 +03:30

84 lines
3.2 KiB
Go

package notification
import (
"strings"
"tm/pkg/response"
)
// CreateRequest represents the request to create a notification
type NotificationRequest struct {
Recipient []string `json:"recipient"`
Tender string `json:"tender" valid:"optional,stringlength(1|100)"`
Channels []DeliveryChannel `json:"channels" valid:"required"`
Type NotificationType `json:"type" valid:"required"`
Priority NotificationPriority `json:"priority" valid:"required"`
Target TargetAudienceType `json:"target" valid:"required"`
Title string `json:"title" valid:"required"`
Description string `json:"description" valid:"required"`
Link *string `json:"link" valid:"optional,url"`
Image *string `json:"image" valid:"optional,url"`
ScheduleAt int64 `json:"schedule_at" valid:"optional"`
}
// SearchForm represents the form for searching notifications
type SearchForm struct {
Q *string `query:"q" valid:"optional"`
Search *string `query:"search" valid:"optional"`
Status string `query:"status" valid:"optional"`
Method string `query:"method" valid:"optional"`
EventType string `query:"event_type" valid:"optional"`
Type string `query:"type" valid:"optional"`
Recipient []string `query:"recipient" json:"recipient" valid:"optional"`
UserID string `query:"user_id" valid:"optional"`
Seen *bool `query:"seen" valid:"optional"`
Priority string `query:"priority" valid:"optional"`
}
// ResolvedSearch returns the search term from either the search or q query parameter.
func (f *SearchForm) ResolvedSearch() string {
if f.Search != nil && strings.TrimSpace(*f.Search) != "" {
return strings.TrimSpace(*f.Search)
}
if f.Q != nil {
return strings.TrimSpace(*f.Q)
}
return ""
}
// ResolvedRecipients returns the user IDs to filter by from user_id or recipient query params.
func (f *SearchForm) ResolvedRecipients() []string {
if id := strings.TrimSpace(f.UserID); id != "" {
return []string{id}
}
return f.Recipient
}
type NotificationListResponse struct {
Notifications []*NotificationResponse `json:"notifications"`
Meta *response.Meta `json:"meta"`
}
type NotificationResponse struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Recipient any `json:"recipient"`
Title string `json:"title"`
Message string `json:"message"`
Link *string `json:"link"`
Image *string `json:"image"`
Priority string `json:"priority"`
Type string `json:"type"`
EventType string `json:"event_type"`
Status string `json:"status"`
Methods map[string]string `json:"methods"`
Metadata map[string]any `json:"metadata"`
ScheduleAt int64 `json:"schedule_at"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
Seen bool `json:"seen"`
SeenAt int64 `json:"seen_at"`
IsScheduled bool `json:"is_scheduled"`
ScheduledAt int64 `json:"scheduled_at"`
}