Documentation
¶
Index ¶
- Constants
- Variables
- func IsValidSeverity(s string) bool
- func IsValidType(t string) bool
- type ID
- type ListFilter
- type Notification
- func (n *Notification) ActorID() *shared.ID
- func (n *Notification) Audience() string
- func (n *Notification) AudienceID() *shared.ID
- func (n *Notification) Body() string
- func (n *Notification) CreatedAt() time.Time
- func (n *Notification) ID() ID
- func (n *Notification) IsRead() bool
- func (n *Notification) NotificationType() string
- func (n *Notification) ResourceID() *shared.ID
- func (n *Notification) ResourceType() string
- func (n *Notification) Severity() string
- func (n *Notification) TenantID() shared.ID
- func (n *Notification) Title() string
- func (n *Notification) URL() string
- type NotificationParams
- type Preferences
- func (p *Preferences) EmailDigest() string
- func (p *Preferences) InAppEnabled() bool
- func (p *Preferences) IsSeverityAllowed(severity string) bool
- func (p *Preferences) IsTypeMuted(notifType string) bool
- func (p *Preferences) MinSeverity() string
- func (p *Preferences) MutedTypes() []string
- func (p *Preferences) TenantID() shared.ID
- func (p *Preferences) UpdatedAt() time.Time
- func (p *Preferences) UserID() shared.ID
- type PreferencesParams
- type Repository
Constants ¶
const ( AudienceAll = "all" AudienceGroup = "group" AudienceUser = "user" )
Audience constants
const ( SeverityCritical = "critical" SeverityHigh = "high" SeverityMedium = "medium" SeverityLow = "low" SeverityInfo = "info" )
Severity constants
const ( TypeFindingNew = "finding_new" TypeFindingAssigned = "finding_assigned" TypeFindingStatusChange = "finding_status_change" TypeFindingComment = "finding_comment" TypeFindingMention = "finding_mention" TypeScanStarted = "scan_started" TypeScanCompleted = "scan_completed" TypeScanFailed = "scan_failed" TypeAssetDiscovered = "asset_discovered" TypeMemberInvited = "member_invited" TypeMemberJoined = "member_joined" TypeRoleChanged = "role_changed" TypeSLABreach = "sla_breach" TypeSystemAlert = "system_alert" )
Notification types
Variables ¶
var (
ErrNotificationNotFound = fmt.Errorf("%w: notification not found", shared.ErrNotFound)
)
Functions ¶
func IsValidSeverity ¶ added in v0.1.2
IsValidSeverity checks if a string is a valid severity value.
func IsValidType ¶ added in v0.1.2
IsValidType checks if a string is a valid notification type.
Types ¶
type ListFilter ¶ added in v0.1.2
ListFilter contains filter parameters for listing notifications.
type Notification ¶ added in v0.1.2
type Notification struct {
// contains filtered or unexported fields
}
Notification represents an in-app notification.
func NewNotification ¶ added in v0.1.2
func NewNotification(params NotificationParams) *Notification
NewNotification creates a new notification.
func Reconstitute ¶
func Reconstitute( id ID, tenantID shared.ID, audience string, audienceID *shared.ID, notificationType string, title string, body string, severity string, resourceType string, resourceID *shared.ID, url string, actorID *shared.ID, createdAt time.Time, isRead bool, ) *Notification
Reconstitute recreates a notification from persistence.
func (*Notification) ActorID ¶ added in v0.1.2
func (n *Notification) ActorID() *shared.ID
func (*Notification) Audience ¶ added in v0.1.2
func (n *Notification) Audience() string
func (*Notification) AudienceID ¶ added in v0.1.2
func (n *Notification) AudienceID() *shared.ID
func (*Notification) Body ¶ added in v0.1.2
func (n *Notification) Body() string
func (*Notification) CreatedAt ¶ added in v0.1.2
func (n *Notification) CreatedAt() time.Time
func (*Notification) IsRead ¶ added in v0.1.2
func (n *Notification) IsRead() bool
func (*Notification) NotificationType ¶ added in v0.1.2
func (n *Notification) NotificationType() string
func (*Notification) ResourceID ¶ added in v0.1.2
func (n *Notification) ResourceID() *shared.ID
func (*Notification) ResourceType ¶ added in v0.1.2
func (n *Notification) ResourceType() string
func (*Notification) Severity ¶ added in v0.1.2
func (n *Notification) Severity() string
func (*Notification) TenantID ¶ added in v0.1.2
func (n *Notification) TenantID() shared.ID
func (*Notification) Title ¶ added in v0.1.2
func (n *Notification) Title() string
func (*Notification) URL ¶ added in v0.1.2
func (n *Notification) URL() string
type NotificationParams ¶ added in v0.1.2
type NotificationParams struct {
TenantID shared.ID
Audience string
AudienceID *shared.ID
NotificationType string
Title string
Body string
Severity string
ResourceType string
ResourceID *shared.ID
URL string
ActorID *shared.ID
}
NotificationParams contains parameters for creating a new notification.
type Preferences ¶ added in v0.1.2
type Preferences struct {
// contains filtered or unexported fields
}
Preferences represents user notification preferences.
func DefaultPreferences ¶ added in v0.1.2
func DefaultPreferences(tenantID, userID shared.ID) *Preferences
DefaultPreferences returns default preferences.
func ReconstitutePref ¶ added in v0.1.2
func ReconstitutePref( tenantID shared.ID, userID shared.ID, inAppEnabled bool, emailDigest string, mutedTypes []string, minSeverity string, updatedAt time.Time, ) *Preferences
ReconstitutePref recreates preferences from persistence.
func (*Preferences) EmailDigest ¶ added in v0.1.2
func (p *Preferences) EmailDigest() string
func (*Preferences) InAppEnabled ¶ added in v0.1.2
func (p *Preferences) InAppEnabled() bool
func (*Preferences) IsSeverityAllowed ¶ added in v0.1.2
func (p *Preferences) IsSeverityAllowed(severity string) bool
IsSeverityAllowed checks if a severity meets the minimum threshold.
func (*Preferences) IsTypeMuted ¶ added in v0.1.2
func (p *Preferences) IsTypeMuted(notifType string) bool
IsTypeMuted checks if a notification type is muted.
func (*Preferences) MinSeverity ¶ added in v0.1.2
func (p *Preferences) MinSeverity() string
func (*Preferences) MutedTypes ¶ added in v0.1.2
func (p *Preferences) MutedTypes() []string
func (*Preferences) UpdatedAt ¶ added in v0.1.2
func (p *Preferences) UpdatedAt() time.Time
func (*Preferences) UserID ¶ added in v0.1.2
func (p *Preferences) UserID() shared.ID
type PreferencesParams ¶ added in v0.1.2
type PreferencesParams struct {
InAppEnabled bool
EmailDigest string
MutedTypes []string
MinSeverity string
}
PreferencesParams contains parameters for creating/updating preferences.
type Repository ¶ added in v0.1.2
type Repository interface {
// Create inserts a new notification.
Create(ctx context.Context, n *Notification) error
// List returns notifications visible to a user (with audience filtering and read status).
// Group membership is resolved via subquery internally, eliminating an extra DB roundtrip.
List(ctx context.Context, tenantID, userID shared.ID, filter ListFilter, page pagination.Pagination) (pagination.Result[*Notification], error)
// UnreadCount returns the number of unread notifications for a user.
// Group membership is resolved via subquery internally, eliminating an extra DB roundtrip.
UnreadCount(ctx context.Context, tenantID, userID shared.ID) (int, error)
// MarkAsRead marks a single notification as read for a user.
MarkAsRead(ctx context.Context, tenantID shared.ID, notificationID ID, userID shared.ID) error
// MarkAllAsRead updates the watermark timestamp for a user.
MarkAllAsRead(ctx context.Context, tenantID, userID shared.ID) error
// DeleteOlderThan removes notifications older than the given duration.
DeleteOlderThan(ctx context.Context, age time.Duration) (int64, error)
// GetPreferences returns notification preferences for a user.
GetPreferences(ctx context.Context, tenantID, userID shared.ID) (*Preferences, error)
// UpsertPreferences creates or updates notification preferences.
UpsertPreferences(ctx context.Context, tenantID, userID shared.ID, params PreferencesParams) (*Preferences, error)
}
Repository defines the interface for user notification persistence.