Documentation
¶
Overview ¶
Package app provides events service with business logic handling.
Index ¶
- type App
- func (a *App) CreateEvent(ctx context.Context, input *dto.CreateEventInput) (*types.Event, error)
- func (a *App) DeleteEvent(ctx context.Context, id string) error
- func (a *App) GetAllUserEvents(ctx context.Context, userID string) ([]*types.Event, error)
- func (a *App) GetEvent(ctx context.Context, id string) (*types.Event, error)
- func (a *App) GetEventsForPeriod(ctx context.Context, input *dto.DateRangeInput) ([]*types.Event, error)
- func (a *App) ListEvents(ctx context.Context, input *dto.DateFilterInput) ([]*types.Event, error)
- func (a *App) UpdateEvent(ctx context.Context, input *dto.UpdateEventInput) (*types.Event, error)
- type Logger
- type Storage
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 ¶
NewApp creates a new events application after arguments validation.
It uses the provided logger and storage to log and store events.
func (*App) CreateEvent ¶
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 ¶
DeleteEvent is trying to delete the Event with the given ID from the storage. Returns nil on success and error otherwise.
func (*App) GetAllUserEvents ¶
GetAllUserEvents is trying to get all events for a given user ID from the storage.
func (*App) GetEvent ¶
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 ¶
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 ¶
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.