dendrite.nvim/core/handlers/vault/initialize_handler.go
Kristian 478f309108
chore(idx_rebuilder): mv to core and use repos (#29)
* ref(index_rebuilder): mv to core

* ref(idx_rebuilder): moved db acc code to repos

* feat(idx_rebuilder): mv idx rebuilder to core and implemented build
2026-04-18 15:57:30 +02:00

45 lines
1.1 KiB
Go

package vault
import (
"context"
"encoding/json"
"github.com/KristianJBorgwarth/dendrite.daemon/core/services"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/store"
)
type initializeCommand struct {
VaultName string `json:"vaultName"`
VaultPath string `json:"vaultPath"`
TemplateDirectory string `json:"templateDirectory"`
}
type InitializeHandler struct {
idxRebuilder services.IIndexRebuilder
}
func NewInitializeHandler(idxR services.IIndexRebuilder) *InitializeHandler {
return &InitializeHandler{idxRebuilder: idxR}
}
func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any, error) {
var cmd initializeCommand
if err := json.Unmarshal(raw, &cmd); err != nil {
return nil, err
}
store := store.NewVaultStore(cmd.VaultName, cmd.VaultPath, cmd.TemplateDirectory)
err := persistence.InitializeDBContext(store.Config.VaultName())
if err != nil {
return nil, err
}
if err = h.idxRebuilder.RebuildIndex(ctx, cmd.VaultPath); err != nil {
return nil, err
}
return nil, nil
}