Integrate Notification Management into Tender Management System
- Added a new notification domain, including entities, services, handlers, and repositories to manage notifications effectively. - Implemented CRUD operations for notifications, allowing for creation, retrieval, updating, and deletion of notifications via the API. - Enhanced API documentation with Swagger comments for new notification endpoints, ensuring clarity for API consumers. - Updated routes to include notification management, improving administrative capabilities within the web panel. - Introduced validation for notification requests and responses, ensuring data integrity and proper error handling. - Updated the go.mod file to include the latest version of the go-redis library, ensuring compatibility with the notification service.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
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)"`
|
||||
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,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// SearchForm represents the form for searching notifications
|
||||
type SearchForm struct {
|
||||
Search *string `query:"q" valid:"optional"`
|
||||
}
|
||||
Reference in New Issue
Block a user