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 (
|
import (
|
||||||
"axolotl/models"
|
"axolotl/models"
|
||||||
"axolotl/store"
|
"axolotl/store"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NodeService is the single entry point for all node operations.
|
// NodeService is the single entry point for all node operations.
|
||||||
// All data-model integrity rules are enforced here; callers cannot produce
|
// All data-model integrity rules are enforced here; callers cannot produce
|
||||||
// invalid state by interacting with this interface alone.
|
// 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 {
|
type NodeService interface {
|
||||||
|
// User returns the name/ID of the user this service instance acts on behalf of.
|
||||||
|
User() string
|
||||||
|
|
||||||
// Query
|
// Query
|
||||||
GetByID(id string) (*models.Node, error)
|
GetByID(id string) (*models.Node, error)
|
||||||
List(filter ListFilter) ([]*models.Node, error)
|
List(filter ListFilter) ([]*models.Node, error)
|
||||||
@@ -69,9 +76,13 @@ func InitNodeService(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetNodeService(cfg Config) (NodeService, 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()
|
st, err := store.FindAndOpenSQLiteStore()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &nodeServiceImpl{store: st, userID: cfg.GetUser()}, nil
|
return &nodeServiceImpl{store: st, userID: user}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ func mentions(t string) []string {
|
|||||||
return slices.Collect(maps.Keys(seen))
|
return slices.Collect(maps.Keys(seen))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *nodeServiceImpl) User() string { return s.userID }
|
||||||
|
|
||||||
// --- Validation ---
|
// --- Validation ---
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
Reference in New Issue
Block a user