notification

package
v5.5.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReplaceGlobals

func ReplaceGlobals(repository Repository) func()

ReplaceGlobals affects a new repository to the global repository singleton

func ReplaceHandlerGlobals added in v5.3.6

func ReplaceHandlerGlobals(handler *Handler) func()

ReplaceHandlerGlobals affects a new repository to the global notification handler singleton

Types

type BaseNotification added in v5.3.6

type BaseNotification struct {
	Notification `json:"-"`
	Id           int64  `json:"id"`
	IsRead       bool   `json:"isRead"`
	Type         string `json:"type"`
	Persistent   bool   `json:"persistent"` // is notification saved in db or not ?
}

BaseNotification data structure represents a basic notification and her current state

func NewBaseNotification added in v5.3.6

func NewBaseNotification(id int64, isRead bool, persistent bool) BaseNotification

NewBaseNotification returns a new instance of a BaseNotification

func (BaseNotification) Equals added in v5.3.6

func (n BaseNotification) Equals(notification Notification) bool

Equals returns true if the two notifications are equals

func (BaseNotification) IsPersistent added in v5.3.6

func (n BaseNotification) IsPersistent() bool

IsPersistent returns whether the notification is persistent (saved to a database)

func (BaseNotification) NewInstance added in v5.3.6

func (n BaseNotification) NewInstance(id int64, data []byte, isRead bool) (Notification, error)

NewInstance returns a new instance of a BaseNotification

func (BaseNotification) SetId added in v5.3.6

func (n BaseNotification) SetId(id int64) Notification

SetId set the notification ID

func (BaseNotification) SetPersistent added in v5.3.6

func (n BaseNotification) SetPersistent(persistent bool) Notification

SetPersistent sets whether the notification is persistent (saved to a database)

func (BaseNotification) ToBytes added in v5.3.6

func (n BaseNotification) ToBytes() ([]byte, error)

ToBytes convert a notification in a json byte slice to be sent through any required channel

type Handler added in v5.3.6

type Handler struct {
	// contains filtered or unexported fields
}

func H added in v5.3.6

func H() *Handler

H is used to access the global notification handler singleton

func NewHandler added in v5.3.6

func NewHandler(notificationLifetime time.Duration) *Handler

NewHandler returns a pointer to a new instance of Handler

func (*Handler) GetNotificationByType added in v5.3.6

func (h *Handler) GetNotificationByType(notificationType string) (notif Notification, ok bool)

GetNotificationByType gets notification interface by its type

func (*Handler) RegisterNotificationType added in v5.3.6

func (h *Handler) RegisterNotificationType(notification Notification)

RegisterNotificationType register a new notification type

func (*Handler) UnregisterNotificationType added in v5.3.6

func (h *Handler) UnregisterNotificationType(notification Notification)

UnregisterNotificationType unregister a notification type

type MockNotification

type MockNotification struct {
	BaseNotification
	CreationDate time.Time              `json:"creationDate"`
	Groups       []int64                `json:"groups"`
	Level        string                 `json:"level"`
	Title        string                 `json:"title"`
	SubTitle     string                 `json:"subtitle"`
	Description  string                 `json:"description"`
	Target       string                 `json:"target"`
	Context      map[string]interface{} `json:"context,omitempty"`
}

MockNotification is an implementation of a notification main type

func NewMockNotification

func NewMockNotification(id int64, level string, title string, subTitle string, description string, creationDate time.Time,
	groups []int64, context map[string]interface{}) *MockNotification

NewMockNotification renders a new MockNotification instance

func (MockNotification) Equals added in v5.3.6

func (n MockNotification) Equals(notification Notification) bool

Equals returns true if the two notifications are equals

func (MockNotification) IsPersistent added in v5.3.6

func (n MockNotification) IsPersistent() bool

IsPersistent returns whether the notification is persistent (saved to a database)

func (MockNotification) NewInstance added in v5.3.6

func (n MockNotification) NewInstance(id int64, data []byte, isRead bool) (Notification, error)

NewInstance returns a new instance of a MockNotification

func (MockNotification) SetId added in v5.3.6

func (n MockNotification) SetId(id int64) Notification

SetId set the notification ID

func (MockNotification) SetPersistent added in v5.3.6

func (n MockNotification) SetPersistent(persistent bool) Notification

SetPersistent sets whether the notification is persistent (saved to a database)

func (MockNotification) ToBytes

func (n MockNotification) ToBytes() ([]byte, error)

ToBytes convert a notification in a json byte slice to be sent though any required channel

type Notification

type Notification interface {
	ToBytes() ([]byte, error)
	NewInstance(id int64, data []byte, isRead bool) (Notification, error)
	Equals(notification Notification) bool
	SetId(id int64) Notification
	SetPersistent(persistent bool) Notification
	IsPersistent() bool
}

Notification is a general interface for all notifications types

type PostgresRepository

type PostgresRepository struct {
	// contains filtered or unexported fields
}

PostgresRepository is a repository containing the Fact definition based on a PSQL database and implementing the repository interface

func (*PostgresRepository) CleanExpired added in v5.3.6

func (r *PostgresRepository) CleanExpired(lifetime time.Duration) (int64, error)

CleanExpired deletes all notifications older than the given lifetime

func (*PostgresRepository) Create

func (r *PostgresRepository) Create(notif Notification, userLogin string) (int64, error)

Create creates a new Notification definition in the repository

func (*PostgresRepository) Delete

func (r *PostgresRepository) Delete(id int64, userLogin string) error

Delete deletes a notification from the repository by its id

func (*PostgresRepository) Get

func (r *PostgresRepository) Get(id int64, userLogin string) (Notification, error)

Get returns a notification by its ID

func (*PostgresRepository) GetAll

func (r *PostgresRepository) GetAll(queryOptionnal dbutils.DBQueryOptionnal, userLogin string) ([]Notification, error)

GetAll returns all notifications from the repository

func (*PostgresRepository) UpdateRead

func (r *PostgresRepository) UpdateRead(id int64, status bool, userLogin string) error

UpdateRead updates a notification status by changing the isRead state to true once it has been read

type Repository

type Repository interface {
	Create(notif Notification, userLogin string) (int64, error)
	Get(id int64, userLogin string) (Notification, error)
	GetAll(queryOptionnal dbutils.DBQueryOptionnal, userLogin string) ([]Notification, error)
	Delete(id int64, userLogin string) error
	UpdateRead(id int64, state bool, userLogin string) error
	CleanExpired(lifetime time.Duration) (int64, error)
}

Repository is a storage interface which can be implemented by multiple backend (in-memory map, sql database, in-memory cache, file system, ...) It allows standard CRUD operation on facts

func NewPostgresRepository

func NewPostgresRepository(dbClient *sqlx.DB) Repository

NewPostgresRepository returns a new instance of PostgresRepository

func R

func R() Repository

R is used to access the global repository singleton

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL