Documentation
¶
Overview ¶
Package notification defines the core domain models for notifications and user settings. These entities are central to how notifications are created, managed, and delivered.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelPreferences ¶
type ChannelPreferences struct {
Email bool `json:"email"`
Push bool `json:"push"`
InApp bool `json:"in_app"`
SMS bool `json:"sms"`
}
ChannelPreferences defines a user's delivery preferences for a single notification type.
type DeliveryChannel ¶
type DeliveryChannel string
DeliveryChannel represents the medium through which a notification is sent.
const ( ChannelEmail DeliveryChannel = "email" ChannelPush DeliveryChannel = "push" ChannelInApp DeliveryChannel = "in_app" ChannelSMS DeliveryChannel = "sms" )
type Notification ¶
type Notification struct {
ID uuid.UUID `json:"id"`
UserID uuid.UUID `json:"user_id"`
Type NotificationType `json:"type"`
Title string `json:"title"`
Message string `json:"message"`
Data map[string]interface{} `json:"data,omitempty"` // Optional context-specific data (e.g., post_id, actor_id)
Read bool `json:"read"`
CreatedAt time.Time `json:"created_at"`
ReadAt *time.Time `json:"read_at,omitempty"` // Pointer to allow null value
}
Notification represents a single notification message sent to a user. It is an immutable entity once created, though its state (e.g., 'read') can change.
func NewNotification ¶
func NewNotification(userID uuid.UUID, nType NotificationType, title, message string, data map[string]interface{}) (*Notification, error)
NewNotification is a factory function to create a new, valid Notification instance. It ensures all required fields are present and valid before creation.
func (*Notification) MarkAsRead ¶
func (n *Notification) MarkAsRead()
MarkAsRead updates the notification's state to 'read'. This is an idempotent operation.
func (*Notification) MarkAsUnread ¶
func (n *Notification) MarkAsUnread()
MarkAsUnread updates the notification's state to 'unread'.
type NotificationType ¶
type NotificationType string
NotificationType represents the category of a notification. Using a custom type ensures type safety and clarity.
const ( // Social-related notifications NewFollower NotificationType = "new_follower" PostLike NotificationType = "post_like" CommentReply NotificationType = "comment_reply" Mention NotificationType = "mention" // System-related notifications SystemAnnouncement NotificationType = "system_announcement" SecurityAlert NotificationType = "security_alert" FeatureUpdate NotificationType = "feature_update" )
Constants for all supported notification types within the system.
func (NotificationType) IsValid ¶
func (nt NotificationType) IsValid() bool
IsValid checks if the notification type is a defined and supported constant.
type Settings ¶
type Settings struct {
UserID uuid.UUID `json:"user_id"`
Preferences map[NotificationType]ChannelPreferences `json:"preferences"`
UpdatedAt time.Time `json:"updated_at"`
}
Settings is an aggregate root that represents a user's complete notification preferences. This entity controls which notifications are generated and delivered for a specific user.
func NewSettings ¶
NewSettings is a factory function to create a settings object for a new user. It populates the settings with sensible, system-wide defaults.
func (*Settings) CanReceive ¶
func (s *Settings) CanReceive(nType NotificationType, channel DeliveryChannel) bool
CanReceive checks if a user's settings permit a specific notification type to be delivered via a specific channel.
func (*Settings) UpdatePreference ¶
func (s *Settings) UpdatePreference(nType NotificationType, channel DeliveryChannel, enabled bool) error
UpdatePreference changes a user's preference for a specific notification type and channel. It ensures the UpdatedAt timestamp is modified.