session

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package session provides business logic for session management.

Sessions group related observations during coding work and track when work started and ended. This service implements the core session lifecycle operations: start, end, get, list, and current.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

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

Service provides session management operations.

func NewService

func NewService(repo domain.SessionRepository) *Service

NewService creates a new session service with the given repository.

func (*Service) Duration

func (s *Service) Duration(session *domain.Session) time.Duration

Duration returns the duration of a session.

For active sessions, returns duration from start to now. For ended sessions, returns duration from start to end.

func (*Service) End

func (s *Service) End(ctx context.Context, id, summary string) error

End marks a session as completed with an optional summary.

Business rules:

  • Can only end active sessions (EndedAt is null)
  • Summary is optional (empty string is valid)
  • Sets EndedAt to current time

Returns ErrSessionEnded if the session has already ended.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id string) (*domain.Session, error)

Get retrieves a session by its ID.

Returns ErrNotFound if the session does not exist.

func (*Service) GetCurrent

func (s *Service) GetCurrent(ctx context.Context, project string) (*domain.Session, error)

GetCurrent retrieves the most recent active session for a project.

An active session is one where EndedAt is null. Returns ErrNotFound if no active session exists for the project.

func (*Service) IsActive

func (s *Service) IsActive(session *domain.Session) bool

IsActive checks if a session is currently active.

A session is active if EndedAt is null.

func (*Service) List

func (s *Service) List(ctx context.Context, project string) ([]*domain.Session, error)

List retrieves sessions for a project, ordered by most recent first.

If project is empty, returns all sessions.

func (*Service) Start

func (s *Service) Start(ctx context.Context, id, project, directory string) (*domain.Session, error)

Start creates a new coding session.

Business rules:

  • ID: If empty, generates a UUID
  • Project: Required, must not be empty
  • Directory: Required, must not be empty
  • StartedAt: Set to current time

Returns an error if project or directory is empty.

Jump to

Keyboard shortcuts

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