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 ¶
- type Service
- func (s *Service) Duration(session *domain.Session) time.Duration
- func (s *Service) End(ctx context.Context, id, summary string) error
- func (s *Service) Get(ctx context.Context, id string) (*domain.Session, error)
- func (s *Service) GetCurrent(ctx context.Context, project string) (*domain.Session, error)
- func (s *Service) IsActive(session *domain.Session) bool
- func (s *Service) List(ctx context.Context, project string) ([]*domain.Session, error)
- func (s *Service) Start(ctx context.Context, id, project, directory string) (*domain.Session, error)
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 ¶
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 ¶
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 ¶
Get retrieves a session by its ID.
Returns ErrNotFound if the session does not exist.
func (*Service) GetCurrent ¶
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 ¶
IsActive checks if a session is currently active.
A session is active if EndedAt is null.
func (*Service) List ¶
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.