ref(create_note): use vault store for template path resolution

This commit is contained in:
Kristian Borgwarth 2026-04-06 12:37:40 +02:00
parent ffc3435d1e
commit 45ff7c84c4
4 changed files with 8 additions and 2 deletions

View file

@ -36,6 +36,7 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an
slug := frontmatter.Slugify(cmd.Title) slug := frontmatter.Slugify(cmd.Title)
templatePath := store.GetVaultStore().GetTemplatePath(cmd.TemplateName) templatePath := store.GetVaultStore().GetTemplatePath(cmd.TemplateName)
notePath := store.GetVaultStore().Config.VaultPath() + "/" + cmd.Directory + "/" + slug + ".md"
data, err := template.RenderTemplate(templatePath, cmd.Title, slug) data, err := template.RenderTemplate(templatePath, cmd.Title, slug)
if err != nil { if err != nil {
@ -82,7 +83,7 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an
tagModels = append(tagModels, dbTags...) tagModels = append(tagModels, dbTags...)
note := models.CreateNote(cmd.Directory, cmd.Title, slug) note := models.CreateNote(notePath, cmd.Title, slug)
if err = noteRepo.Upsert(ctx, note); err != nil { if err = noteRepo.Upsert(ctx, note); err != nil {
return nil, err return nil, err

BIN
dendrite

Binary file not shown.

View file

@ -18,7 +18,8 @@ func TestCreateNoteHandler_NoTemplate_CreatesNoteFileAndReturnsPath(t *testing.T
notePath := filepath.Join(t.TempDir(), "my-note.md") notePath := filepath.Join(t.TempDir(), "my-note.md")
params, _ := json.Marshal(map[string]any{ params, _ := json.Marshal(map[string]any{
"title": "My Note", "title": "My Note",
"path": notePath, "templateName": "",
"directory": "",
}) })
// Act // Act

View file

@ -5,11 +5,13 @@ import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"os" "os"
"path"
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/KristianJBorgwarth/dendrite.daemon/core/rpc" "github.com/KristianJBorgwarth/dendrite.daemon/core/rpc"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence" "github.com/KristianJBorgwarth/dendrite.daemon/persistence"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/store"
_ "modernc.org/sqlite" _ "modernc.org/sqlite"
) )
@ -17,6 +19,7 @@ type DBFixture struct {
DB *sql.DB DB *sql.DB
DBPath string DBPath string
TestContext context.Context TestContext context.Context
VaultStore *store.VaultStore
} }
func NewDBFixture() *DBFixture { func NewDBFixture() *DBFixture {
@ -35,6 +38,7 @@ func NewDBFixture() *DBFixture {
DB: dbContext.DB, DB: dbContext.DB,
DBPath: dbPath, DBPath: dbPath,
TestContext: context.Background(), TestContext: context.Background(),
VaultStore: store.NewVaultStore(vaultPath, path.Join(vaultPath, "templates")),
} }
} }