From 66f03daf833bee32077f6dcfdf42695d491cbc2b Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Sun, 22 Mar 2026 22:09:16 +0100 Subject: [PATCH 1/6] chore(rename): renamte init.go -> initialize.go --- core/handlers/{init.go => initialize.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/handlers/{init.go => initialize.go} (100%) diff --git a/core/handlers/init.go b/core/handlers/initialize.go similarity index 100% rename from core/handlers/init.go rename to core/handlers/initialize.go From 843b840583b22c77a485eefe1134f46bed2b20a0 Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Sun, 22 Mar 2026 23:00:21 +0100 Subject: [PATCH 2/6] feat(create_note): setup note --- core/handlers/create_note.go | 26 +++++++++++++++++++++ persistence/repositories/doc.go | 3 --- persistence/repositories/note_repository.go | 12 ++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 core/handlers/create_note.go create mode 100644 persistence/repositories/note_repository.go diff --git a/core/handlers/create_note.go b/core/handlers/create_note.go new file mode 100644 index 0000000..3cf25b6 --- /dev/null +++ b/core/handlers/create_note.go @@ -0,0 +1,26 @@ +package handlers + +import ( + "encoding/json" + + "github.com/KristianJBorgwarth/dendrite.daemon/core/rpc" +) + +type createNoteCommand struct { + Title string `json:"title"` + TemplatePath string `json:"templatePath"` + Path string `json:"path"` + Vars map[string]string `json:"vars"` +} + +type CreateNoteHandler struct{ + repository NoteRepository +} + +func (h CreateNoteHandler) Handle(params []byte) (any, *rpc.Error) { + var cmd createNoteCommand + if err := json.Unmarshal(params, &cmd); err != nil { + return nil, &rpc.Error{Code: -32602, Message: "invalid params"} + } + +} diff --git a/persistence/repositories/doc.go b/persistence/repositories/doc.go index 0660717..aa98412 100644 --- a/persistence/repositories/doc.go +++ b/persistence/repositories/doc.go @@ -1,6 +1,3 @@ // Package repositories provides an interface for accessing dendrite index and configuration package repositories - - - diff --git a/persistence/repositories/note_repository.go b/persistence/repositories/note_repository.go new file mode 100644 index 0000000..36cc6a7 --- /dev/null +++ b/persistence/repositories/note_repository.go @@ -0,0 +1,12 @@ +package repositories + +import "database/sql" + +type NoteRepository interface { + CreateNote(title string, path string, slug string) error +} + +type noteRepository struct { + db *sql.DB +} + From 722b1dbbe7455edc1facf43ffed2b20f12eda933 Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Sun, 22 Mar 2026 23:02:31 +0100 Subject: [PATCH 3/6] feat(create_note): minimal handler --- core/handlers/create_note.go | 10 +++++++++- persistence/repositories/note_repository.go | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/handlers/create_note.go b/core/handlers/create_note.go index 3cf25b6..26fb406 100644 --- a/core/handlers/create_note.go +++ b/core/handlers/create_note.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/KristianJBorgwarth/dendrite.daemon/core/rpc" + "github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories" ) type createNoteCommand struct { @@ -14,7 +15,7 @@ type createNoteCommand struct { } type CreateNoteHandler struct{ - repository NoteRepository + repository repositories.NoteRepository } func (h CreateNoteHandler) Handle(params []byte) (any, *rpc.Error) { @@ -23,4 +24,11 @@ func (h CreateNoteHandler) Handle(params []byte) (any, *rpc.Error) { return nil, &rpc.Error{Code: -32602, Message: "invalid params"} } + err := h.repository.Upsert(cmd.Title, cmd.TemplatePath, cmd.Path) + + if err != nil { + return nil, &rpc.Error{Code: -1, Message: err.Error()} + } + + return map[string]any{"status": "ok"}, nil } diff --git a/persistence/repositories/note_repository.go b/persistence/repositories/note_repository.go index 36cc6a7..b90bda5 100644 --- a/persistence/repositories/note_repository.go +++ b/persistence/repositories/note_repository.go @@ -3,7 +3,7 @@ package repositories import "database/sql" type NoteRepository interface { - CreateNote(title string, path string, slug string) error + Upsert(title string, path string, slug string) error } type noteRepository struct { From da4f5e2feb700a1e18b455eb35cbc15775184e33 Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Mon, 23 Mar 2026 22:32:20 +0100 Subject: [PATCH 4/6] tag repo --- core/handlers/create_note.go | 2 +- core/handlers/initialize.go | 32 ++-------------------- core/template/doc.go | 2 ++ persistence/repositories/tag_repository.go | 17 ++++++++++++ 4 files changed, 22 insertions(+), 31 deletions(-) create mode 100644 core/template/doc.go create mode 100644 persistence/repositories/tag_repository.go diff --git a/core/handlers/create_note.go b/core/handlers/create_note.go index 26fb406..df71e3e 100644 --- a/core/handlers/create_note.go +++ b/core/handlers/create_note.go @@ -24,7 +24,7 @@ func (h CreateNoteHandler) Handle(params []byte) (any, *rpc.Error) { return nil, &rpc.Error{Code: -32602, Message: "invalid params"} } - err := h.repository.Upsert(cmd.Title, cmd.TemplatePath, cmd.Path) + err := h.repository.Upsert(cmd.Title, cmd.Path, cmd.Path) if err != nil { return nil, &rpc.Error{Code: -1, Message: err.Error()} diff --git a/core/handlers/initialize.go b/core/handlers/initialize.go index bf35334..c6cf01f 100644 --- a/core/handlers/initialize.go +++ b/core/handlers/initialize.go @@ -2,25 +2,12 @@ package handlers import ( "encoding/json" - "github.com/KristianJBorgwarth/dendrite.daemon/config" "github.com/KristianJBorgwarth/dendrite.daemon/core/rpc" "github.com/KristianJBorgwarth/dendrite.daemon/persistence" ) type initializeCommand struct { VaultPath string `json:"vaultPath"` - TemplateDir string `json:"templateDir"` - - ScratchNote struct { - Dir string `json:"dir"` - TemplateName string `json:"templateName"` - } `json:"scratchNote"` - - DailyNote struct { - Dir string `json:"dir"` - TemplateName string `json:"templateName"` - FilenameFormat string `json:"filenameFormat"` - } `json:"dailyNote"` } type InitializeHandler struct{} @@ -35,23 +22,8 @@ func (h InitializeHandler) Handle(raw json.RawMessage) (any, *rpc.Error) { } } - cfg := &config.Config{ - VaultPath: params.VaultPath, - TemplateDir: params.TemplateDir, - ScratchNote: config.ScratchConfig{ - Dir: params.ScratchNote.Dir, - TemplateName: params.ScratchNote.TemplateName, - }, - DailyNote: config.DailyConfig{ - Dir: params.DailyNote.Dir, - TemplateName: params.DailyNote.TemplateName, - FilenameFormat: params.DailyNote.FilenameFormat, - }, - } - cfg.SetDefaults() - - err := persistence.InitializeIndex(cfg.VaultPath) + err := persistence.InitializeIndex(params.VaultPath) if err != nil { return nil, &rpc.Error{ Code: -1, @@ -59,6 +31,6 @@ func (h InitializeHandler) Handle(raw json.RawMessage) (any, *rpc.Error) { } } - return cfg, nil + return nil, nil } diff --git a/core/template/doc.go b/core/template/doc.go new file mode 100644 index 0000000..66c2031 --- /dev/null +++ b/core/template/doc.go @@ -0,0 +1,2 @@ +// Package template provides implementations for generating notes from templates +package template diff --git a/persistence/repositories/tag_repository.go b/persistence/repositories/tag_repository.go new file mode 100644 index 0000000..ea07afc --- /dev/null +++ b/persistence/repositories/tag_repository.go @@ -0,0 +1,17 @@ + +package repositories + +import "database/sql" + +type TagRepository interface { + Upsert(title string, path string, slug string) error +} + +type tagRepository struct { + db *sql.DB +} + +func NewTagRepository(db *sql.DB) TagRepository { + return &tagRepository{db: db} +} + From 4708accc02a85bbb041b8f0e0be67c2a525e0d1f Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Tue, 24 Mar 2026 21:36:17 +0100 Subject: [PATCH 5/6] feat(persistence): note / tag repository --- persistence/repositories/note_repository.go | 16 ++++++++++++++++ persistence/repositories/tag_repository.go | 13 ++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/persistence/repositories/note_repository.go b/persistence/repositories/note_repository.go index b90bda5..6832f41 100644 --- a/persistence/repositories/note_repository.go +++ b/persistence/repositories/note_repository.go @@ -10,3 +10,19 @@ type noteRepository struct { db *sql.DB } +func NewNoteRepository(db *sql.DB) NoteRepository { + return ¬eRepository{db: db} +} + + +func (r *noteRepository) Upsert(title string, path string, slug string) error { + query := ` + INSERT INTO notes (title, path, slug) + VALUES ($1, $2, $3) + ON CONFLICT (slug) DO UPDATE + SET title = EXCLUDED.title, + path = EXCLUDED.path; + ` + _, err := r.db.Exec(query, title, path, slug) + return err +} diff --git a/persistence/repositories/tag_repository.go b/persistence/repositories/tag_repository.go index ea07afc..c198560 100644 --- a/persistence/repositories/tag_repository.go +++ b/persistence/repositories/tag_repository.go @@ -4,7 +4,7 @@ package repositories import "database/sql" type TagRepository interface { - Upsert(title string, path string, slug string) error + Upsert(title string, path string) error } type tagRepository struct { @@ -15,3 +15,14 @@ func NewTagRepository(db *sql.DB) TagRepository { return &tagRepository{db: db} } +func (r *tagRepository) Upsert(title string, path string) error { + query := ` + INSERT INTO tags (title, path) + VALUES ($1, $2) + ON CONFLICT (slug) DO UPDATE + SET title = EXCLUDED.title, + path = EXCLUDED.path; + ` + _, err := r.db.Exec(query, title, path) + return err +} From ec8de90d2322bb9af0cff0db62d82d7770f17375 Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Tue, 24 Mar 2026 22:10:00 +0100 Subject: [PATCH 6/6] ref(models): change property accessability --- core/models/links.go | 26 +++++++++++++++++++--- core/models/note.go | 48 +++++++++++++++++++++++++++++++++++------ core/models/note_tag.go | 19 ++++++++++++++-- core/models/tag.go | 19 ++++++++++++++-- 4 files changed, 98 insertions(+), 14 deletions(-) diff --git a/core/models/links.go b/core/models/links.go index 412cd0f..538a2d8 100644 --- a/core/models/links.go +++ b/core/models/links.go @@ -1,7 +1,27 @@ package models type Link struct { - FromNoteID int - ToNoteID int - Raw string + fromNoteID int + toNoteID int + raw string +} + +func NewLink(fromNoteID, toNoteID int, raw string) *Link { + return &Link{ + fromNoteID: fromNoteID, + toNoteID: toNoteID, + raw: raw, + } +} + +func (l *Link) FromNoteID() int { + return l.fromNoteID +} + +func (l *Link) ToNoteID() int { + return l.toNoteID +} + +func (l *Link) Raw() string { + return l.raw } diff --git a/core/models/note.go b/core/models/note.go index 4d478b9..c95b71b 100644 --- a/core/models/note.go +++ b/core/models/note.go @@ -1,11 +1,45 @@ - package models type Note struct { - ID int - Path string - Title string - Slug string - CreatedAt string - UpdatedAt string + id int + path string + title string + slug string + createdAt string + updatedAt string +} + +func NewNote(id int, path, title, slug, createdAt, updatedAt string) *Note { + return &Note{ + id: id, + path: path, + title: title, + slug: slug, + createdAt: createdAt, + updatedAt: updatedAt, + } +} + +func (n *Note) ID() int { + return n.id +} + +func (n *Note) Path() string { + return n.path +} + +func (n *Note) Title() string { + return n.title +} + +func (n *Note) Slug() string { + return n.slug +} + +func (n *Note) CreatedAt() string { + return n.createdAt +} + +func (n *Note) UpdatedAt() string { + return n.updatedAt } diff --git a/core/models/note_tag.go b/core/models/note_tag.go index a74d771..ec36634 100644 --- a/core/models/note_tag.go +++ b/core/models/note_tag.go @@ -1,6 +1,21 @@ package models type NoteTag struct { - NoteID int - TagID int + noteID int + tagID int +} + +func NewNoteTag(noteID, tagID int) *NoteTag { + return &NoteTag{ + noteID: noteID, + tagID: tagID, + } +} + +func (nt *NoteTag) NoteID() int { + return nt.noteID +} + +func (nt *NoteTag) TagID() int { + return nt.tagID } diff --git a/core/models/tag.go b/core/models/tag.go index 0bc7531..e36d306 100644 --- a/core/models/tag.go +++ b/core/models/tag.go @@ -1,6 +1,21 @@ package models type Tag struct { - ID int - Name string + id int + name string +} + +func NewTag(id int, name string) *Tag { + return &Tag{ + id: id, + name: name, + } +} + +func (t *Tag) ID() int { + return t.id +} + +func (t *Tag) Name() string { + return t.name }