feat: authsession service

This commit is contained in:
Ilia Denisov
2026-04-08 16:23:07 +02:00
committed by GitHub
parent 28f04916af
commit 86a68ed9d0
174 changed files with 31732 additions and 112 deletions
@@ -0,0 +1,65 @@
// Package getsession implements the trusted internal read use case for one
// device session.
package getsession
import (
"context"
"errors"
"fmt"
"galaxy/authsession/internal/ports"
"galaxy/authsession/internal/service/shared"
)
// Input describes one trusted internal get-session request.
type Input struct {
// DeviceSessionID identifies the session that should be read.
DeviceSessionID string
}
// Result describes one trusted internal get-session response.
type Result struct {
// Session stores the frozen internal read-model DTO.
Session shared.Session
}
// Service executes the trusted internal get-session use case against the
// configured ports.
type Service struct {
sessionStore ports.SessionStore
}
// New returns a get-session service wired to sessionStore.
func New(sessionStore ports.SessionStore) (*Service, error) {
if sessionStore == nil {
return nil, fmt.Errorf("getsession: session store must not be nil")
}
return &Service{sessionStore: sessionStore}, nil
}
// Execute loads one source-of-truth session and projects it into the frozen
// internal read DTO shape.
func (s *Service) Execute(ctx context.Context, input Input) (Result, error) {
deviceSessionID, err := shared.ParseDeviceSessionID(input.DeviceSessionID)
if err != nil {
return Result{}, err
}
record, err := s.sessionStore.Get(ctx, deviceSessionID)
if err != nil {
switch {
case errors.Is(err, ports.ErrNotFound):
return Result{}, shared.SessionNotFound()
default:
return Result{}, shared.ServiceUnavailable(err)
}
}
session, err := shared.ToSession(record)
if err != nil {
return Result{}, shared.InternalError(err)
}
return Result{Session: session}, nil
}