notification

package
v0.0.2-rc-ci Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMemoryStore

NewMemoryStore returns a new in memory store.

func NewSettingsMemoryStore

func NewSettingsMemoryStore() *crud.MemoryStore[NewSettings, Settings, SettingsFilters]

NewMemoryStore returns a new in memory store.

func Router

func Router(storer Storer, settingsStorer SettingsStorer, authService auth.Service) func(r chi.Router)

Router returns a new http router that handles crud requests for notifications and notification settings.

Types

type Authorizer

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

func NewAuthorizer

func NewAuthorizer(store Storer) *Authorizer

NewAuthorizer wraps the given store with authorization methods.

func (*Authorizer) Create

func (a *Authorizer) Create(ctx context.Context, notification *NewNotification) (*Notification, error)

Create is allowed by

  • an admin
  • a moderator
  • internally

func (*Authorizer) Delete

func (a *Authorizer) Delete(ctx context.Context, id string) error

Delete is allowed by

  • the user owning the notification
  • an admin
  • internally

func (*Authorizer) Find

func (a *Authorizer) Find(ctx context.Context, params *crud.FindParams[Filters]) ([]*Notification, int, error)

Find is allowed by

  • normal and moderator for notifications that are owned
  • an admin
  • internally

func (*Authorizer) FindByID

func (a *Authorizer) FindByID(ctx context.Context, id string) (*Notification, error)

FindByID is allowed by

  • the user owning the notification
  • an admin
  • internally

func (*Authorizer) Update

func (a *Authorizer) Update(ctx context.Context, notification *Notification) (*Notification, error)

Update is allowed by

  • the user owning the notification
  • an admin
  • internally

type Filters

type Filters struct {
	ID      *string `json:"id,omitempty" db:"id"`
	UserID  *string `json:"userId,omitempty" db:"user_id"`
	Subject *string `json:"subject,omitempty" db:"subject"`
	Message *string `json:"message,omitempty" db:"message"`
	Viewed  *bool   `json:"viewed,omitempty" db:"viewed"`
}

FindFilters defines for notifications.

type FindResponse

type FindResponse[Model any] struct {
	// in:body
	Model *Model
}
type Link struct {
	Title string `json:"title"`
	URL   string `json:"url"`
}

type Mailer

type Mailer interface {
	Send(email, subject, body string) error
}

type NewNotification

type NewNotification struct {
	UserID    string `json:"userId"`
	Subject   string `json:"subject"`
	Message   string `json:"message"`
	LinkTitle string `json:"linkTitle"`
	LinkURL   string `json:"linkUrl"`
}

type NewSettings

type NewSettings struct {
	UserID string `json:"userId" db:"user_id"`
	Email  bool   `json:"email" db:"email"`
}

type Notification

type Notification struct {
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
	UserID    string    `json:"userId" db:"user_id"`
	Subject   string    `json:"subject"`
	Message   string    `json:"message"`
	LinkTitle string    `json:"linkTitle" db:"link_title"`
	LinkURL   string    `json:"linkUrl" db:"link_url"`
	Viewed    bool      `json:"viewed"`
}

func NotifictaionFromNewNotification

func NotifictaionFromNewNotification(n *NewNotification, id string) *Notification

func (Notification) Identifier

func (n Notification) Identifier() string

type Notifier

type Notifier interface {
	Notify(ctx context.Context, userID string, subject string, message string, link Link) error
}

type Service

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

func NewService

func NewService(mailer Mailer, store Storer, settingsStore SettingsStorer, user user.Storer) *Service

func (*Service) ConsumeOperation

func (s *Service) ConsumeOperation(op oqueue.Operation) error

func (*Service) Notify

func (s *Service) Notify(ctx context.Context, userID string, subject string, message string, link Link) error

func (*Service) SettingsStore

func (s *Service) SettingsStore() SettingsStorer

func (*Service) Store

func (s *Service) Store() Storer

type Settings

type Settings struct {
	UserID string `json:"userId" db:"user_id"`
	Email  bool   `json:"email" db:"email"`
}

TODO: ensure this is deleted, when the user gets deleted.

func SettingsFromNewSettings

func SettingsFromNewSettings(n *NewSettings, id string) *Settings

func (Settings) Identifier

func (n Settings) Identifier() string

type SettingsAuthorizer

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

func NewSettingsAuthorizer

func NewSettingsAuthorizer(store SettingsStorer) *SettingsAuthorizer

NewSettingsAuthorizer wraps the given store with authorization methods.

func (*SettingsAuthorizer) Create

func (a *SettingsAuthorizer) Create(ctx context.Context, settings *NewSettings) (*Settings, error)

Create is allowed by

  • the user owning the settings
  • an admin
  • internally

func (*SettingsAuthorizer) Delete

func (a *SettingsAuthorizer) Delete(ctx context.Context, id string) error

Delete is allowed by

  • the user owning the settings
  • an admin
  • internally

func (*SettingsAuthorizer) Find

Find is allowed by

  • normal and moderator can only retrieve their own settings
  • an admin
  • internally

func (*SettingsAuthorizer) FindByID

func (a *SettingsAuthorizer) FindByID(ctx context.Context, id string) (*Settings, error)

FindByID is allowed by

  • the user owning the settings
  • an admin
  • internally

func (*SettingsAuthorizer) Update

func (a *SettingsAuthorizer) Update(ctx context.Context, settings *Settings) (*Settings, error)

Update is allowed by

  • the user owning the settings
  • an admin
  • internally

type SettingsFilters

type SettingsFilters struct {
	UserID *string `json:"userId,omitempty" db:"user_id"`
	Email  *bool   `json:"email,omitempty" db:"email"`
}

type SettingsSqlStore

type SettingsSqlStore struct {
	*crud.SqlStore[NewSettings, Settings, SettingsFilters]
	// contains filtered or unexported fields
}

func NewSettingsSqlStore

func NewSettingsSqlStore(db *sqlx.DB, migrationService dbmigration.Service) (*SettingsSqlStore, error)

NewSqlStore returns a new sql db event store.

type SqlStore

type SqlStore struct {
	*crud.SqlStore[NewNotification, Notification, Filters]
	// contains filtered or unexported fields
}

func NewSqlStore

func NewSqlStore(db *sqlx.DB, migrationService dbmigration.Service) (*SqlStore, error)

NewSqlStore returns a new sql store for notifications.

Jump to

Keyboard shortcuts

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