revent

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: 21 Imported by: 0

Documentation

Overview

package revent implement repeating events with a very flexible interval type.

Example intervals are:

  • every day
  • every second day
  • every monday
  • every second tuesday
  • every first monday of a month
  • every second tuesday of a month
  • every first monday of every second month

This gives three categories of intervals:

  • DayInterval: every [1..7] day, starting at [date]
  • WeekInterval: every [1..] [weekday] of week
  • MonthInterval: every [1..4] [weekday] a month

Index

Constants

View Source
const (
	IntervalDay   = IntervalType("day")
	IntervalWeek  = IntervalType("week")
	IntervalMonth = IntervalType("month")
)
View Source
const (
	OrderAsc  = SortOrder("ASC")
	OrderDesc = SortOrder("DESC")
)

Possible values for SortOrder.

Variables

This section is empty.

Functions

func GenerateEvents

func GenerateEvents(repeatingEvent *RepeatingEvent, existingEvents []*event.Event, start, end time.Time) ([]*event.NewEvent, error)

func ID

func ID(id string) string

ID returns a repeating event id in the form of:

revent:<id>

func NewMemoryStore

NewMemoryStore returns a new in memory store.

func ParseID

func ParseID(id string) (string, bool)

ParseID parses a repeating event id. The second return value indicates if the given id is a valid repeating event id.

func Router

func Router(service Service, authService auth.Service) func(chi.Router)

Router returns a new http router that handles crud RepeatingEvent requests for a given RepeatingEvent service.

Types

type CreateOperation

type CreateOperation struct {
	RepeatingEvent *RepeatingEvent
	// contains filtered or unexported fields
}

func NewCreateOperation

func NewCreateOperation(repeatingEvent *RepeatingEvent, userID string) CreateOperation

func (CreateOperation) UserID

func (o CreateOperation) UserID() string

type DeleteOperation

type DeleteOperation struct {
	ID string
	// contains filtered or unexported fields
}

func NewDeleteOperation

func NewDeleteOperation(id string, userID string) DeleteOperation

func (DeleteOperation) UserID

func (o DeleteOperation) UserID() string

type ExpiredNotifier

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

func NewExpiredNotifier

func NewExpiredNotifier(expiredStore ExpiredStorer, reventStore Storer, eventStore event.Storer, notifier notification.Notifier) *ExpiredNotifier

func (*ExpiredNotifier) ConsumeOperation

func (e *ExpiredNotifier) ConsumeOperation(op oqueue.Operation) error

func (*ExpiredNotifier) NotifyAction

func (e *ExpiredNotifier) NotifyAction(ctx context.Context) error

type ExpiredState

type ExpiredState struct {
	RepeatingEventID string `db:"repeating_event_id"`
}

func (ExpiredState) Identifier

func (e ExpiredState) Identifier() string

type ExpiredStateFilter

type ExpiredStateFilter struct{}

type ExpiredStateSqlStore

type ExpiredStateSqlStore struct {
	*crud.SqlStore[ExpiredState, ExpiredState, ExpiredStateFilter]
	// contains filtered or unexported fields
}

func NewExpiredStateSqlStore

func NewExpiredStateSqlStore(db *sqlx.DB, migrationService dbmigration.Service) (*ExpiredStateSqlStore, error)

type FindFilters

type FindFilters struct {
	ID          *string    `json:"id,omitempty"`
	Deactivated *bool      `json:"deactivated,omitempty"`
	Published   *bool      `json:"published,omitempty"`
	Parent      *string    `json:"parent,omitempty"`
	Name        *string    `json:"name,omitempty"`
	Organizers  []string   `json:"organizers,omitempty"`
	Location    *string    `json:"location,omitempty"`
	Location2   *string    `json:"location2,omitempty"`
	Description *string    `json:"description,omitempty"`
	Start       *time.Time `json:"start,omitempty"`
	End         *time.Time `json:"end,omitempty"`
	Tags        []string   `json:"tags,omitempty"`
	OwnedBy     []string   `json:"ownedBy,omitempty"`
}

FindFilters defines the possible filters for the find method.

type Interval

type Interval struct {
	// Type changes the meaning od Interval an WeekDay.
	Type IntervalType `json:"type" db:"type"`
	// Interval used for day, week and month
	Interval int `json:"interval" db:"interval"`
	// WeekDay is a week day, with a range of 0 (sunday) to 7 (saturday).
	WeekDay time.Weekday `json:"weekDay" db:"weekDay"`
}

func (*Interval) GenerateDates

func (i *Interval) GenerateDates(start time.Time, end time.Time) ([]time.Time, error)

GenerateDates generates a list of dates, in a given date range using the defined interval.

type IntervalType

type IntervalType string

IntervalType defines the type of the interval (day, week or month)

type NewRepeatingEvent

type NewRepeatingEvent struct {
	Name        string     `json:"name"`
	Organizers  []string   `json:"organizers"`
	Location    string     `json:"location"`
	Location2   string     `json:"location2"`
	Description string     `json:"description"`
	Intervals   []Interval `json:"intervals"`
	Start       time.Time  `json:"start"`
	End         time.Time  `json:"end"`
	Tags        []string   `json:"tags"`
	Image       string     `json:"image"`
	OwnedBy     []string   `json:"ownedBy"`
}

func (*NewRepeatingEvent) IsOwned

func (r *NewRepeatingEvent) IsOwned(id string) bool

IsOwned returns true if the id is in the OwnedBy field.

type RepeatingEvent

type RepeatingEvent struct {
	ID          string     `json:"id" db:"id"`
	Deactivated bool       `json:"deactivated" db:"deactivated"`
	Name        string     `json:"name" db:"name"`
	Organizers  []string   `json:"organizers" db:"organizers"`
	Location    string     `json:"location" db:"location"`
	Location2   string     `json:"location2" db:"location2"`
	Description string     `json:"description" db:"description"`
	Intervals   []Interval `json:"intervals" db:"intervals"`
	Start       time.Time  `json:"start" db:"start"`
	End         time.Time  `json:"end" db:"end"`
	Tags        []string   `json:"tags" db:"tags"`
	Image       string     `json:"image" db:"image"`
	OwnedBy     []string   `json:"ownedBy" db:"ownedBy"`
}

func RepeatingEventFromNewRepeatingEvent

func RepeatingEventFromNewRepeatingEvent(newRepeatingEvent *NewRepeatingEvent, id string) *RepeatingEvent

func (RepeatingEvent) Identifier

func (r RepeatingEvent) Identifier() string

func (*RepeatingEvent) IsOwned

func (r *RepeatingEvent) IsOwned(id string) bool

IsOwned returns true if the id is in the OwnedBy field.

type Service

type Service interface {
	Storer

	GenerateEvents(ctx context.Context, id string, start, end time.Time) ([]*event.Event, error)
}

-go:generate go run github.com/petergtz/pegomock/pegomock generate eintopf.info/service/revent Service --output=../../internal/mock/revent_service.go --package=mock --mock-name=RepeatingEventService

func NewAuthorizer

func NewAuthorizer(service Service) Service

NewAuthorizer returns a new role manager limiting access to the provided store.

func NewOperator

func NewOperator(service Service, queue oqueue.Service) Service

func NewService

func NewService(store Storer, eventService event.Storer) Service

NewService returns a new event service.

type SortOrder

type SortOrder string

SortOrder defines the order of sorting.

type SqlStore

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

func NewSqlStore

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

NewSqlStore returns a new sql db RepeatingEvent store.

func (*SqlStore) Create

func (s *SqlStore) Create(ctx context.Context, newRepeatingEvent *NewRepeatingEvent) (*RepeatingEvent, error)

func (*SqlStore) Delete

func (s *SqlStore) Delete(ctx context.Context, id string) error

func (*SqlStore) Find

func (s *SqlStore) Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*RepeatingEvent, int, error)

func (*SqlStore) FindByID

func (s *SqlStore) FindByID(ctx context.Context, id string) (*RepeatingEvent, error)

func (*SqlStore) Update

func (s *SqlStore) Update(ctx context.Context, repeatingEvent *RepeatingEvent) (*RepeatingEvent, error)

type Storer

type Storer interface {
	Create(ctx context.Context, newEvent *NewRepeatingEvent) (*RepeatingEvent, error)
	Update(ctx context.Context, event *RepeatingEvent) (*RepeatingEvent, error)
	Delete(ctx context.Context, id string) error
	FindByID(ctx context.Context, id string) (*RepeatingEvent, error)
	Find(ctx context.Context, params *crud.FindParams[FindFilters]) ([]*RepeatingEvent, int, error)
}

Storer defines a service for CRUD operations on the event model.

type UpdateOperation

type UpdateOperation struct {
	RepeatingEvent *RepeatingEvent
	// contains filtered or unexported fields
}

func NewUpdateOperation

func NewUpdateOperation(repeatingEvent *RepeatingEvent, userID string) UpdateOperation

func (UpdateOperation) UserID

func (o UpdateOperation) UserID() string

Jump to

Keyboard shortcuts

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