feat: authsession service
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// Package listusersessions implements the trusted internal read use case for
|
||||
// listing all sessions of one user.
|
||||
package listusersessions
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"galaxy/authsession/internal/ports"
|
||||
"galaxy/authsession/internal/service/shared"
|
||||
)
|
||||
|
||||
// Input describes one trusted internal list-user-sessions request.
|
||||
type Input struct {
|
||||
// UserID identifies the owner whose sessions should be listed.
|
||||
UserID string
|
||||
}
|
||||
|
||||
// Result describes one trusted internal list-user-sessions response.
|
||||
type Result struct {
|
||||
// Sessions stores the frozen internal read-model DTO slice.
|
||||
Sessions []shared.Session
|
||||
}
|
||||
|
||||
// Service executes the trusted internal list-user-sessions use case.
|
||||
type Service struct {
|
||||
sessionStore ports.SessionStore
|
||||
}
|
||||
|
||||
// New returns a list-user-sessions service wired to sessionStore.
|
||||
func New(sessionStore ports.SessionStore) (*Service, error) {
|
||||
if sessionStore == nil {
|
||||
return nil, fmt.Errorf("listusersessions: session store must not be nil")
|
||||
}
|
||||
|
||||
return &Service{sessionStore: sessionStore}, nil
|
||||
}
|
||||
|
||||
// Execute loads all source-of-truth sessions for one user and projects them
|
||||
// into the frozen internal read DTO shape.
|
||||
func (s *Service) Execute(ctx context.Context, input Input) (Result, error) {
|
||||
userID, err := shared.ParseUserID(input.UserID)
|
||||
if err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
|
||||
records, err := s.sessionStore.ListByUserID(ctx, userID)
|
||||
if err != nil {
|
||||
return Result{}, shared.ServiceUnavailable(err)
|
||||
}
|
||||
|
||||
sessions, err := shared.ToSessions(records)
|
||||
if err != nil {
|
||||
return Result{}, shared.InternalError(err)
|
||||
}
|
||||
|
||||
return Result{Sessions: sessions}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user