spreadsheet

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FIELD_KEY_ are used in field mapping
	// They must map the eventDTO field names.
	FIELD_KEY_START             = "start"
	FIELD_KEY_END               = "end"
	FIELD_KEY_TITLE             = "title"
	FIELD_KEY_DESCRIPTION       = "description"
	FIELD_KEY_LOCATION          = "location"
	FIELD_KEY_LAST_UPDATED      = "lastupdated"
	FIELD_KEY_LAST_CHECKED      = "lastchecked"
	FIELD_KEY_LAST_RESULT       = "lastresult"
	FIELD_KEY_DISCORD_EVENT_ID  = "discordeventid"
	FIELD_KEY_CALENDAR_EVENT_ID = "calendareventid"
)

Variables

View Source
var ErrEmptyEvent = errors.New("empty event")

ErrEmptyEvent indicates an event with no field

View Source
var ErrEmptyFilter = errors.New("should contain one of 'equalsto', 'startswith', 'notequalsto', 'and' or 'or'")
View Source
var ErrFilteredOut = errors.New("rejected by filters")

ErrFilteredOut indicates the event has not fulfilled filter conditions.

View Source
var ErrIncompleteEvent = errors.New("incomplete event")

ErrIncompleteEvent signals that the event definitions lacks some mandatory fields.

View Source
var ErrInvalidA1Column = errors.New("invalid A1 column")

Functions

func A1ColumnDecodeHook

func A1ColumnDecodeHook(from reflect.Type, to reflect.Type, value any) (any, error)

Types

type A1Column

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

A1Column is a column reference represented in the A1 notation

func MustParseA1Column

func MustParseA1Column(input string) A1Column

MustParseA1Column parses a column definition. It panics if the value is invalud.

func (A1Column) GoString

func (a A1Column) GoString() string

GoString implements fmt.GoStringer.

func (A1Column) Index

func (a A1Column) Index() uint

func (A1Column) LogValue

func (a A1Column) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (A1Column) MarshalText

func (a A1Column) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (A1Column) String

func (a A1Column) String() string

String implements fmt.Stringer.

func (*A1Column) UnmarshalText

func (a *A1Column) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Columns

type Columns struct {
	Title           *A1Column `validate:"required"`
	Description     *A1Column `validate:"required"`
	Location        *A1Column `validate:"required"`
	Start           *A1Column `validate:"required"`
	End             *A1Column `validate:"required"`
	CalendarEventId *A1Column `validate:"required"`
	DiscordEventId  *A1Column `validate:"required"`
	LastChecked     *A1Column
	LastUpdated     *A1Column
	LastResult      *A1Column
	CustomFields    map[string]A1Column `mapstructure:",remain"`
}

Columns maps field names to column indices. As indices are zero-based, pointer are used so that missing mappings shows as nil.

type Config

type Config struct {
	// SpreadsheetId is the spreadsheet identifier
	SpreadsheetId string `mapstructure:"id" validate:"required"`

	// SheetTitle is the title of sheet of the spreadsheet that contains the event definitions.
	SheetTitle string `mapstructure:"sheet" validate:"required"`

	// StartingRow indicates at which row (1-based) to start looking for event definitions.
	// It defaults to 1 (first row of the sheet).
	StartingRow uint `validate:"omitempty,min=1"`

	// EndingRow indicates at which row (1-based) to stop looking for event definitions.
	// It defaults to 100.
	EndingRow uint `validate:"omitempty,min=1,gtfield=StartingRow"`

	// Columns maps field names to column indices inside the named range.
	Columns Columns `validate:"required"`

	// Filters defines conditions to select which events should be processed.
	Filters EventFilterDef
}

Config holds the configuration to read and update the spreadsheet that contains the event definitions.

func (Config) NewRepository

func (c Config) NewRepository(ctx context.Context, serviceAccountFile string) (*Repository, error)

NewRepository creates a Repository from the configuration, using the serviceAccountFile for authentication. It validates the configuration and checks if the spreadsheet and named ranges are available.

type DateSerial

type DateSerial = float64

A DateSerial represents a wallclock timestamp by a real number of days since 1899-12-30 00:00:00. This is how Google API handles timestamp .

type DateSerialConverter

type DateSerialConverter struct {
	Location *time.Location
}

A DateSerialConverter helps converting between time.Time and DateSerial in a given location.

func NewDateSerialConverter

func NewDateSerialConverter(location *time.Location) *DateSerialConverter

NewDateSerialConverter creates a new DateSerialConverter with the given Location.

func (*DateSerialConverter) FromTime

func (c *DateSerialConverter) FromTime(value time.Time) DateSerial

IntoTime converts a DateSerial into a time.Time in the target time zone.

func (*DateSerialConverter) IntoTime

func (c *DateSerialConverter) IntoTime(value DateSerial) time.Time

IntoTime converts a DateSerial into a time.Time in the target time zone.

type Event

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

An Event describes an scheduled event.

func (Event) CalendarEventId

func (e Event) CalendarEventId() string

func (Event) Description

func (e Event) Description() string

func (Event) DiscordEventId

func (e Event) DiscordEventId() string

func (Event) End

func (e Event) End() *time.Time

func (*Event) HasErrors

func (e *Event) HasErrors() bool

func (Event) IsFullDay

func (e Event) IsFullDay() bool

func (Event) IsInThePast

func (e Event) IsInThePast() bool

func (Event) Location

func (e Event) Location() string

func (Event) LogValue

func (e Event) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (*Event) ReportError

func (e *Event) ReportError(err error)

func (*Event) SetCalendarEventId

func (e *Event) SetCalendarEventId(id string)

func (*Event) SetDiscordEventId

func (e *Event) SetDiscordEventId(id string)

func (Event) Start

func (e Event) Start() *time.Time

func (Event) Title

func (e Event) Title() string

func (*Event) Updated

func (e *Event) Updated() bool

type EventFilterDef

type EventFilterDef map[string]ValueFilterDef

EventFilterDef defines a set of condition to apply on the fields of an event.

func (EventFilterDef) Create

func (d EventFilterDef) Create() (Filter, error)

type Filter

type Filter interface {
	// Accept must returns an error whenever the value is rejecteds.
	Accept(value any) error
}

A Filter indicates whether a value should be accepted.

type Repository

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

Repository allows to read and to update events from and to the spreadsheet.

func (*Repository) ReadEvents

func (r *Repository) ReadEvents() ([]Event, error)

ReadEvents extract all events from the designated named zone of the spreadsheets. Each row is read in turn, mapped into an event and validated. Incomplete events are ignored.

func (*Repository) UpdateEvent

func (r *Repository) UpdateEvent(event *Event) error

UpdateEvent stores the Discord scheduled event identifier of the given event into the spreadsheet. It also updates the metadata fields LastChecked, LastUpdated and LastResult if they are mapped.

type ValueFilterDef

type ValueFilterDef struct {
	EqualsTo    *any
	NotEqualsTo *any
	StartsWith  *string          `validate:"omitempty,min=1"`
	And         []ValueFilterDef `validate:"omitempty,min=1"`
	Or          []ValueFilterDef `validate:"omitempty,min=1"`
}

ValueFilterDef defines a condition on a single value.

func (ValueFilterDef) Create

func (d ValueFilterDef) Create() (Filter, error)

Jump to

Keyboard shortcuts

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