Files
tm_back/internal/notification/entity.go
T
n.nakhostin a06dc5097e 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.
2025-09-17 16:01:49 +03:30

111 lines
3.4 KiB
Go

package notification
import (
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
)
// NotificationType represents the type of notification
type NotificationType string
const (
NotificationTypeInfo NotificationType = "info"
NotificationTypeWarning NotificationType = "warning"
NotificationTypeAlert NotificationType = "alert"
NotificationTypeReject NotificationType = "reject"
)
// NotificationPriority represents the priority level of notification
type NotificationPriority string
const (
NotificationPriorityLow NotificationPriority = "low"
NotificationPriorityMedium NotificationPriority = "medium"
NotificationPriorityImportant NotificationPriority = "important"
)
// DeliveryChannel represents the delivery channel for notification
type DeliveryChannel string
const (
DeliveryChannelPush DeliveryChannel = "push"
DeliveryChannelEmail DeliveryChannel = "email"
)
// DeliveryStatus represents the delivery status of notification
type NotificationStatus string
const (
DeliveryStatusPending NotificationStatus = "pending"
DeliveryStatusSent NotificationStatus = "sent"
DeliveryStatusFailed NotificationStatus = "failed"
)
// TargetAudienceType represents the type of target audience
// Supported audience types:
// - all_users: All users in the system
// - specific_users: Specific users by their IDs
// - all_role: All users with a specific role (e.g., all admins)
// - specific_role: Users with a specific role, optionally filtered by tender
// - specific_company: All users belonging to a specific company
// - all_companies: All users from all companies
// - specific_customer: All users belonging to a specific customer
// - all_customers: All users from all customers
type TargetAudienceType string
const (
TargetAudienceAllUsers TargetAudienceType = "all_users"
TargetAudienceSpecificUsers TargetAudienceType = "specific_users"
TargetAudienceAllRole TargetAudienceType = "all_role"
TargetAudienceSpecificRole TargetAudienceType = "specific_role"
TargetAudienceAllCompanies TargetAudienceType = "all_companies"
TargetAudienceSpecificCompany TargetAudienceType = "specific_company"
TargetAudienceAllCustomers TargetAudienceType = "all_customers"
TargetAudienceSpecificCustomer TargetAudienceType = "specific_customer"
)
// Notification represents a notification entity
type Notification struct {
mongo.Model `bson:",inline"`
Recipient []string `bson:"recipients"`
Tender bson.ObjectID `bson:"tender"`
Channels []DeliveryChannel `bson:"channels"`
Type NotificationType `bson:"type"`
Priority NotificationPriority `bson:"priority"`
Status NotificationStatus `bson:"status"`
Target TargetAudienceType `bson:"target"`
Title string `bson:"title"`
Description string `bson:"description"`
Link *string `bson:"link"`
Schedule Schedule `bson:"schedule"`
}
type Schedule struct {
Time int64 `bson:"time"`
}
func (n *Notification) SetID(id string) {
n.ID, _ = bson.ObjectIDFromHex(id)
}
func (n *Notification) GetID() string {
return n.ID.Hex()
}
func (n *Notification) SetCreatedAt(timestamp int64) {
n.CreatedAt = timestamp
}
func (n *Notification) SetUpdatedAt(timestamp int64) {
n.UpdatedAt = timestamp
}
func (n *Notification) GetCreatedAt() int64 {
return n.CreatedAt
}
func (n *Notification) GetUpdatedAt() int64 {
return n.UpdatedAt
}