notification

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 7 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

Types

type FrontNotification

type FrontNotification struct {
	Notification
	IsRead bool
}

FrontNotification data structure represente the notification and her current state

type MockNotification

type MockNotification struct {
	ID           int64                  `json:"id"`
	Type         string                 `json:"type"`
	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"`
	Context      map[string]interface{} `json:"context,omitempty"`
}

MockNotification is an implementation of a notification main type

func NewMockNotification

func NewMockNotification(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) 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)
}

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) Create

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

Create creates a new Notification definition in the repository

func (*PostgresRepository) Delete

func (r *PostgresRepository) Delete(id int64) error

Delete deletes a notification from the repository by its id

func (*PostgresRepository) Get

Get returns a notification by it's ID

func (*PostgresRepository) GetAll added in v4.2.0

func (r *PostgresRepository) GetAll(queryOptionnal dbutils.DBQueryOptionnal) ([]FrontNotification, error)

GetByRoles returns all notifications related to a certain list of roles

func (*PostgresRepository) UpdateRead

func (r *PostgresRepository) UpdateRead(id int64, status bool) 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) (int64, error)
	Get(id int64) *FrontNotification
	GetAll(queryOptionnal dbutils.DBQueryOptionnal) ([]FrontNotification, error)
	Delete(id int64) error
	UpdateRead(id int64, state bool) 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