refactor: bind NodeService to a user and expose User() on the interface
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,12 +3,19 @@ package service
|
||||
import (
|
||||
"axolotl/models"
|
||||
"axolotl/store"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// NodeService is the single entry point for all node operations.
|
||||
// All data-model integrity rules are enforced here; callers cannot produce
|
||||
// invalid state by interacting with this interface alone.
|
||||
//
|
||||
// Every NodeService instance is bound to a specific user (see User()).
|
||||
// GetNodeService returns an error when no user is configured.
|
||||
type NodeService interface {
|
||||
// User returns the name/ID of the user this service instance acts on behalf of.
|
||||
User() string
|
||||
|
||||
// Query
|
||||
GetByID(id string) (*models.Node, error)
|
||||
List(filter ListFilter) ([]*models.Node, error)
|
||||
@@ -69,9 +76,13 @@ func InitNodeService(path string) error {
|
||||
}
|
||||
|
||||
func GetNodeService(cfg Config) (NodeService, error) {
|
||||
user := cfg.GetUser()
|
||||
if user == "" {
|
||||
return nil, fmt.Errorf("no user configured: run 'ax user set <username>' first")
|
||||
}
|
||||
st, err := store.FindAndOpenSQLiteStore()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &nodeServiceImpl{store: st, userID: cfg.GetUser()}, nil
|
||||
return &nodeServiceImpl{store: st, userID: user}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user