Refactor Notification Management and Enhance Customer Features

- Updated the notification handling logic to utilize a new SDK for sending notifications, improving the flexibility and scalability of the notification system.
- Introduced new methods in the notification service for sending notifications to users and customers based on various target audience types, enhancing the notification delivery capabilities.
- Added a new endpoint to assign companies to a customer, improving customer management functionalities.
- Refactored the customer entity and forms to replace 'CompanyIDs' with 'Companies', ensuring consistency across the data model.
- Enhanced API documentation with Swagger comments for the new endpoint and updated notification structures, ensuring clarity for API consumers.
This commit is contained in:
n.nakhostin
2025-09-20 16:54:51 +03:30
parent d2f7c6a1e5
commit 9037cb5917
18 changed files with 607 additions and 1471 deletions
+16 -60
View File
@@ -1,70 +1,26 @@
package notification
import (
"tm/pkg/response"
"go.mongodb.org/mongo-driver/v2/bson"
)
// CreateRequest represents the request to create a notification
type NotificationRequest struct {
Recipient []string `json:"recipient" valid:"required,stringlength(1|100)"`
Tender bson.ObjectID `json:"tender" valid:"optional,stringlength(1|100)"`
Channels []DeliveryChannel `json:"channels" valid:"required,minlength(1)"`
Type NotificationType `json:"type" valid:"required,notification_type"`
Priority NotificationPriority `json:"priority" valid:"required,notification_priority"`
Target TargetAudienceType `json:"target" valid:"required,target_audience"`
Title string `json:"title" valid:"required,stringlength(1|200)"`
Description string `json:"description" valid:"required,stringlength(1|1000)"`
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"`
Schedule ScheduleRequest `json:"schedule" valid:"optional"`
}
type ScheduleRequest struct {
Time int64 `json:"time" valid:"required,int64"`
}
// NotificationResponse represents the response after creating a notification
type NotificationResponse struct {
ID string `json:"id"`
Tender string `json:"tender"`
Channels []DeliveryChannel `json:"channels"`
Type NotificationType `json:"type"`
Priority NotificationPriority `json:"priority"`
Target TargetAudienceType `json:"target"`
Title string `json:"title"`
Description string `json:"description"`
Link string `json:"link"`
Schedule ScheduleResponse `json:"schedule"`
}
type ScheduleResponse struct {
Time int64 `json:"time"`
}
type NotificationsResponse struct {
Notifications []*NotificationResponse `json:"notifications"`
Meta *response.Meta `json:"-"`
}
func (n *Notification) ToResponse() *NotificationResponse {
return &NotificationResponse{
ID: n.ID.Hex(),
Tender: n.Tender.Hex(),
Channels: n.Channels,
Type: n.Type,
Priority: n.Priority,
Target: n.Target,
Title: n.Title,
Description: n.Description,
Link: *n.Link,
Schedule: ScheduleResponse{
Time: n.Schedule.Time,
},
}
ScheduleAt int64 `json:"schedule_at" valid:"optional"`
}
// SearchForm represents the form for searching notifications
type SearchForm struct {
Search *string `query:"q" valid:"optional"`
Search *string `query:"q" valid:"optional"`
Status NotificationStatus `query:"status" valid:"optional"`
SortBy *string `query:"sort_by" valid:"optional"`
SortOrder *string `query:"sort_order" valid:"optional"`
Limit *int `query:"limit" valid:"optional"`
Offset *int `query:"offset" valid:"optional"`
}