app

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package app provides events service with business logic handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App represents an events application.

func NewApp

func NewApp(logger Logger, storage Storage, config map[string]any) (*App, error)

NewApp creates a new events application after arguments validation.

It uses the provided logger and storage to log and store events.

func (*App) CreateEvent

func (a *App) CreateEvent(ctx context.Context, input *dto.CreateEventInput) (*types.Event, error)

CreateEvent is trying to build an Event object and save it in the storage. Returns *Event, nil on success, nil and error otherwise.

func (*App) DeleteEvent

func (a *App) DeleteEvent(ctx context.Context, id string) error

DeleteEvent is trying to delete the Event with the given ID from the storage. Returns nil on success and error otherwise.

func (*App) GetAllUserEvents

func (a *App) GetAllUserEvents(ctx context.Context, userID string) ([]*types.Event, error)

GetAllUserEvents is trying to get all events for a given user ID from the storage.

func (*App) GetEvent

func (a *App) GetEvent(ctx context.Context, id string) (*types.Event, error)

GetEvent is trying to get the Event with the given ID from the storage. Returns nil on success and error otherwise.

func (*App) GetEventsForPeriod

func (a *App) GetEventsForPeriod(ctx context.Context, input *dto.DateRangeInput) ([]*types.Event, error)

GetEventsForPeriod is trying to get all events for a given period from the storage. Returns []*Event, nil on success and nil, error otherwise.

NOTE: time borders are not casted unlike in ListEvents.

func (*App) ListEvents

func (a *App) ListEvents(ctx context.Context, input *dto.DateFilterInput) ([]*types.Event, error)

ListEvents is trying to get all events for a given user ID from the storage.

period is the period of time to get events for, stratring from the given date. Accepted values are Day, Week and Month.

Returns []*Event, nil on success and nil, error otherwise.

NOTE: period is casted to the the start of the corresponding calendar period.

func (*App) UpdateEvent

func (a *App) UpdateEvent(ctx context.Context, input *dto.UpdateEventInput) (*types.Event, error)

UpdateEvent is trying to get the existing Event from the storage, update it and save back. Returns *Event, nil on success, nil and error otherwise.

type Logger

type Logger interface {
	// Info logs a message with level Info on the standard logger.
	Info(ctx context.Context, msg string, args ...any)
	// Debug logs a message with level Debug on the standard logger.
	Debug(ctx context.Context, msg string, args ...any)
	// Warn logs a message with level Warn on the standard logger.
	Warn(ctx context.Context, msg string, args ...any)
	// Error logs a message with level Error on the standard logger.
	Error(ctx context.Context, msg string, args ...any)
}

Logger represents an interface of logger visible to the app.

type Storage

type Storage interface {
	// Connect establishes a connection to the storage backend.
	Connect(ctx context.Context) error

	// CreateEvent creates a new event in the storage.
	// Returns the created event or an error if the operation fails.
	CreateEvent(ctx context.Context, event *types.Event) (*types.Event, error)

	// UpdateEvent updates an existing event by ID with the provided data.
	// Returns the updated event or an error if the operation fails.
	UpdateEvent(ctx context.Context, id uuid.UUID, data *types.EventData) (*types.Event, error)

	// DeleteEvent deletes an event by ID.
	// Returns an error if the operation fails.
	DeleteEvent(ctx context.Context, id uuid.UUID) error

	// GetEvent retrieves an event by ID.
	// Returns the event or an error if not found or the operation fails.
	GetEvent(ctx context.Context, id uuid.UUID) (*types.Event, error)

	// GetAllUserEvents retrieves all events for a given user ID.
	// Returns a slice of events or an error if not found or the operation fails.
	GetAllUserEvents(ctx context.Context, userID string) ([]*types.Event, error)

	// GetEventsForDay retrieves events for a specific day, optionally filtered by user ID.
	// Returns a slice of events or an error if not found or the operation fails.
	GetEventsForDay(ctx context.Context, date time.Time, userID *string) ([]*types.Event, error)

	// GetEventsForWeek retrieves events for a specific week, optionally filtered by user ID.
	// Returns a slice of events or an error if not found or the operation fails.
	GetEventsForWeek(ctx context.Context, date time.Time, userID *string) ([]*types.Event, error)

	// GetEventsForMonth retrieves events for a specific month, optionally filtered by user ID.
	// Returns a slice of events or an error if not found or the operation fails.
	GetEventsForMonth(ctx context.Context, date time.Time, userID *string) ([]*types.Event, error)

	// GetEventsForPeriod retrieves events for a given period, optionally filtered by user ID.
	// Returns a slice of events or an error if not found or the operation fails.
	GetEventsForPeriod(ctx context.Context, dateStart, dateEnd time.Time, userID *string) ([]*types.Event, error)
}

Storage represents a universal storage interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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