ref(create_note): use vault store for template path resolution
This commit is contained in:
parent
ffc3435d1e
commit
45ff7c84c4
4 changed files with 8 additions and 2 deletions
|
|
@ -36,6 +36,7 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an
|
|||
slug := frontmatter.Slugify(cmd.Title)
|
||||
|
||||
templatePath := store.GetVaultStore().GetTemplatePath(cmd.TemplateName)
|
||||
notePath := store.GetVaultStore().Config.VaultPath() + "/" + cmd.Directory + "/" + slug + ".md"
|
||||
|
||||
data, err := template.RenderTemplate(templatePath, cmd.Title, slug)
|
||||
if err != nil {
|
||||
|
|
@ -82,7 +83,7 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an
|
|||
|
||||
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 {
|
||||
return nil, err
|
||||
|
|
|
|||
BIN
dendrite
BIN
dendrite
Binary file not shown.
|
|
@ -18,7 +18,8 @@ func TestCreateNoteHandler_NoTemplate_CreatesNoteFileAndReturnsPath(t *testing.T
|
|||
notePath := filepath.Join(t.TempDir(), "my-note.md")
|
||||
params, _ := json.Marshal(map[string]any{
|
||||
"title": "My Note",
|
||||
"path": notePath,
|
||||
"templateName": "",
|
||||
"directory": "",
|
||||
})
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@ import (
|
|||
"database/sql"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/rpc"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/store"
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
|
|
@ -17,6 +19,7 @@ type DBFixture struct {
|
|||
DB *sql.DB
|
||||
DBPath string
|
||||
TestContext context.Context
|
||||
VaultStore *store.VaultStore
|
||||
}
|
||||
|
||||
func NewDBFixture() *DBFixture {
|
||||
|
|
@ -35,6 +38,7 @@ func NewDBFixture() *DBFixture {
|
|||
DB: dbContext.DB,
|
||||
DBPath: dbPath,
|
||||
TestContext: context.Background(),
|
||||
VaultStore: store.NewVaultStore(vaultPath, path.Join(vaultPath, "templates")),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue