Enhance notification search functionality and update API documentation
- Added `search` and `q` query parameters to the `SearchForm` for improved notification searching capabilities. - Implemented `ResolvedSearch` method to prioritize search term resolution from the new parameters. - Updated `GetByUserID` repository method to support searching notifications by title and message using regex. - Enhanced logging in the `GetNotifications` service method to include search parameters. - Updated Swagger documentation to reflect the new search parameters for the notification API. This update improves the user experience by allowing more flexible and efficient searching of notifications.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"tm/pkg/response"
|
||||
)
|
||||
|
||||
@@ -21,13 +23,26 @@ type NotificationRequest struct {
|
||||
|
||||
// SearchForm represents the form for searching notifications
|
||||
type SearchForm struct {
|
||||
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"`
|
||||
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"`
|
||||
Seen *bool `query:"seen" valid:"optional"`
|
||||
Priority string `query:"priority" 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 ""
|
||||
}
|
||||
|
||||
type NotificationListResponse struct {
|
||||
|
||||
Reference in New Issue
Block a user