Documentation ¶
Index ¶
- func NewMemoryStore() *crud.MemoryStore[NewNotification, Notification, Filters]
- func NewSettingsMemoryStore() *crud.MemoryStore[NewSettings, Settings, SettingsFilters]
- func Router(storer Storer, settingsStorer SettingsStorer, authService auth.Service) func(r chi.Router)
- type Authorizer
- func (a *Authorizer) Create(ctx context.Context, notification *NewNotification) (*Notification, error)
- func (a *Authorizer) Delete(ctx context.Context, id string) error
- func (a *Authorizer) Find(ctx context.Context, params *crud.FindParams[Filters]) ([]*Notification, int, error)
- func (a *Authorizer) FindByID(ctx context.Context, id string) (*Notification, error)
- func (a *Authorizer) Update(ctx context.Context, notification *Notification) (*Notification, error)
- type Filters
- type FindResponse
- type Link
- type Mailer
- type NewNotification
- type NewSettings
- type Notification
- type Notifier
- type Service
- type Settings
- type SettingsAuthorizer
- func (a *SettingsAuthorizer) Create(ctx context.Context, settings *NewSettings) (*Settings, error)
- func (a *SettingsAuthorizer) Delete(ctx context.Context, id string) error
- func (a *SettingsAuthorizer) Find(ctx context.Context, params *crud.FindParams[SettingsFilters]) ([]*Settings, int, error)
- func (a *SettingsAuthorizer) FindByID(ctx context.Context, id string) (*Settings, error)
- func (a *SettingsAuthorizer) Update(ctx context.Context, settings *Settings) (*Settings, error)
- type SettingsFilters
- type SettingsSqlStore
- type SettingsStorer
- type SqlStore
- type Storer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMemoryStore ¶
func NewMemoryStore() *crud.MemoryStore[NewNotification, Notification, Filters]
NewMemoryStore returns a new in memory store.
func NewSettingsMemoryStore ¶
func NewSettingsMemoryStore() *crud.MemoryStore[NewSettings, Settings, SettingsFilters]
NewMemoryStore returns a new in memory store.
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 NewNotification ¶
type NewSettings ¶
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 Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) SettingsStore ¶
func (s *Service) SettingsStore() SettingsStorer
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 ¶
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 ¶
func (a *SettingsAuthorizer) Find(ctx context.Context, params *crud.FindParams[SettingsFilters]) ([]*Settings, int, error)
Find is allowed by
- normal and moderator can only retrieve their own settings
- an admin
- internally
type SettingsFilters ¶
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 SettingsStorer ¶
type SettingsStorer = crud.Storer[NewSettings, Settings, SettingsFilters]
type SqlStore ¶
type SqlStore struct { *crud.SqlStore[NewNotification, Notification, Filters] // contains filtered or unexported fields }
func NewSqlStore ¶
NewSqlStore returns a new sql store for notifications.
type Storer ¶
type Storer = crud.Storer[NewNotification, Notification, Filters]
Click to show internal directories.
Click to hide internal directories.