44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"axolotl/models"
|
|
"axolotl/store"
|
|
)
|
|
|
|
type NodeService interface {
|
|
Create(title, content, dueDate string, tags []string, rels map[models.RelType][]string) (*models.Node, error)
|
|
Update(node *models.Node) error
|
|
Delete(id string) error
|
|
GetByID(id string) (*models.Node, error)
|
|
List(opts ...ListOption) ([]*models.Node, error)
|
|
Exists(id string) (bool, error)
|
|
CanClose(id string) (bool, []string, error)
|
|
}
|
|
|
|
func InitNodeService(path string) error {
|
|
return store.InitSQLiteStore(path)
|
|
}
|
|
|
|
func GetNodeService(cfg Config) (NodeService, error) {
|
|
st, err := store.FindAndOpenSQLiteStore()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &nodeServiceImpl{store: st, userID: cfg.GetUser()}, nil
|
|
}
|
|
|
|
type listFilter struct {
|
|
tagPrefixes []string
|
|
relPrefixes []*models.Rel
|
|
}
|
|
|
|
type ListOption func(*listFilter)
|
|
|
|
func WithTags(prefixes ...string) ListOption {
|
|
return func(f *listFilter) { f.tagPrefixes = append(f.tagPrefixes, prefixes...) }
|
|
}
|
|
|
|
func WithRels(prefixes ...*models.Rel) ListOption {
|
|
return func(f *listFilter) { f.relPrefixes = append(f.relPrefixes, prefixes...) }
|
|
}
|