diff --git a/cmd/main.go b/cmd/main.go index 8839763..f2373cd 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -3,8 +3,8 @@ package main import ( "log/slog" "os" - - "github.com/KristianJBorgwarth/dendrite.daemon/core/handlers" + "github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/note" + "github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/vault" "github.com/KristianJBorgwarth/dendrite.daemon/core/logging" "github.com/KristianJBorgwarth/dendrite.daemon/core/server" _ "modernc.org/sqlite" @@ -14,8 +14,8 @@ func main() { logging.Init() server := server.NewServer() - server.RegisterHandler("initialize", handlers.NewInitializeHandler()) - server.RegisterHandler("create_note", handlers.NewCreateNoteHandler()) + server.RegisterHandler("initialize", vault.NewInitializeHandler()) + server.RegisterHandler("create_note", note.NewCreateNoteHandler()) if err := server.Run(os.Stdin, os.Stdout); err != nil { slog.Error("server error", "error", err) diff --git a/core/handlers/create_note_handler.go b/core/handlers/note/create_note_handler.go similarity index 91% rename from core/handlers/create_note_handler.go rename to core/handlers/note/create_note_handler.go index ca8d8ce..3155912 100644 --- a/core/handlers/create_note_handler.go +++ b/core/handlers/note/create_note_handler.go @@ -1,4 +1,4 @@ -package handlers +package note import ( "context" @@ -69,7 +69,7 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an return nil, err } - if err = tagRepo.Upsert(ctx, tagModels); err != nil { + if err = tagRepo.Insert(ctx, tagModels); err != nil { return nil, err } @@ -77,11 +77,11 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an note := models.CreateNote(notePath, cmd.Title, template.Slug) - if err = noteRepo.Upsert(ctx, note); err != nil { + if err = noteRepo.Insert(ctx, note); err != nil { return nil, err } - if err = tagRepo.UpsertNoteTags(ctx, note.ID(), utils.Select(tagModels, func(t *models.Tag) string { return t.ID() })); err != nil { + if err = tagRepo.InsertNoteTags(ctx, note.ID(), utils.Select(tagModels, func(t *models.Tag) string { return t.ID() })); err != nil { return nil, err } diff --git a/core/handlers/note/doc.go b/core/handlers/note/doc.go new file mode 100644 index 0000000..77ae882 --- /dev/null +++ b/core/handlers/note/doc.go @@ -0,0 +1,2 @@ +// Package note provides the handlers for note commands +package note diff --git a/core/handlers/save_note.go b/core/handlers/note/save_note.go similarity index 97% rename from core/handlers/save_note.go rename to core/handlers/note/save_note.go index 6e6c19c..c7cae9b 100644 --- a/core/handlers/save_note.go +++ b/core/handlers/note/save_note.go @@ -1,4 +1,4 @@ -package handlers +package note import ( "context" diff --git a/core/handlers/vault/doc.go b/core/handlers/vault/doc.go new file mode 100644 index 0000000..7d3c68a --- /dev/null +++ b/core/handlers/vault/doc.go @@ -0,0 +1,2 @@ +// Package vault provides handlers for vault commands +package vault diff --git a/core/handlers/initialize_handler.go b/core/handlers/vault/initialize_handler.go similarity index 97% rename from core/handlers/initialize_handler.go rename to core/handlers/vault/initialize_handler.go index 90be2d8..4fc6ba6 100644 --- a/core/handlers/initialize_handler.go +++ b/core/handlers/vault/initialize_handler.go @@ -1,4 +1,4 @@ -package handlers +package vault import ( "context" diff --git a/dendrite b/dendrite index 1c028af..6edcfb9 100755 Binary files a/dendrite and b/dendrite differ diff --git a/persistence/repositories/note_repository.go b/persistence/repositories/note_repository.go index e7fc96e..6aa8a3c 100644 --- a/persistence/repositories/note_repository.go +++ b/persistence/repositories/note_repository.go @@ -8,7 +8,7 @@ import ( ) type NoteRepository interface { - Upsert(ctx context.Context, note *models.Note) error + Insert(ctx context.Context, note *models.Note) error } type noteRepository struct { @@ -19,7 +19,7 @@ func NewNoteRepository(tx *sql.Tx) NoteRepository { return ¬eRepository{Transaction: tx} } -func (r *noteRepository) Upsert(ctx context.Context, note *models.Note) error { +func (r *noteRepository) Insert(ctx context.Context, note *models.Note) error { query := ` INSERT INTO note (id, title, path, slug, created_at, updated_at) VALUES (?, ?, ?, ?, datetime('now'), datetime('now')) diff --git a/persistence/repositories/tag_repository.go b/persistence/repositories/tag_repository.go index e73663c..47c69cd 100644 --- a/persistence/repositories/tag_repository.go +++ b/persistence/repositories/tag_repository.go @@ -9,8 +9,8 @@ import ( ) type ITagRepository interface { - Upsert(ctx context.Context, tags []*models.Tag) error - UpsertNoteTags(ctx context.Context, noteID string, tagIDs []string) error + Insert(ctx context.Context, tags []*models.Tag) error + InsertNoteTags(ctx context.Context, noteID string, tagIDs []string) error GetByNames(ctx context.Context, names []string) ([]*models.Tag, error) } @@ -22,7 +22,7 @@ func NewTagRepository(tx *sql.Tx) ITagRepository { return &tagRepository{Transaction: tx} } -func (r *tagRepository) Upsert(ctx context.Context, tags []*models.Tag) error { +func (r *tagRepository) Insert(ctx context.Context, tags []*models.Tag) error { if len(tags) == 0 { return nil } @@ -41,7 +41,7 @@ func (r *tagRepository) Upsert(ctx context.Context, tags []*models.Tag) error { return err } -func (r *tagRepository) UpsertNoteTags(ctx context.Context ,noteID string, tagIDs []string) error { +func (r *tagRepository) InsertNoteTags(ctx context.Context ,noteID string, tagIDs []string) error { if len(tagIDs) == 0 { return nil } diff --git a/test/test_integration/create_note_handler_test.go b/test/test_integration/create_note_handler_test.go index c964129..b58017a 100644 --- a/test/test_integration/create_note_handler_test.go +++ b/test/test_integration/create_note_handler_test.go @@ -6,14 +6,14 @@ import ( "path/filepath" "testing" - "github.com/KristianJBorgwarth/dendrite.daemon/core/handlers" + "github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/note" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestCreateNoteHandler_NoTemplate_CreatesNoteFileAndReturnsPath(t *testing.T) { // Arrange - handler := handlers.NewCreateNoteHandler() + handler := note.NewCreateNoteHandler() vaultPath := Fixture.VaultStore.Config.VaultPath() notePath := filepath.Join(vaultPath, "my-note.md") @@ -40,7 +40,7 @@ func TestCreateNoteHandler_NoTemplate_CreatesNoteFileAndReturnsPath(t *testing.T func TestCreateNoteHandler_WithTemplate_CreatesNoteFileWithTagsAndReturnsPath(t *testing.T) { // Arrange - handler := handlers.NewCreateNoteHandler() + handler := note.NewCreateNoteHandler() vaultPath := Fixture.VaultStore.Config.VaultPath() templateDir := Fixture.VaultStore.Config.TemplateDirectory() @@ -89,7 +89,7 @@ func TestCreateNoteHandler_WithTemplate_CreatesNoteFileWithTagsAndReturnsPath(t func TestCreateNoteHandler_DuplicateSlug_Upserts(t *testing.T) { // Arrange - handler := handlers.NewCreateNoteHandler() + handler := note.NewCreateNoteHandler() vaultPath := Fixture.VaultStore.Config.VaultPath() subDir := "dup-dir" @@ -123,7 +123,7 @@ func TestCreateNoteHandler_DuplicateSlug_Upserts(t *testing.T) { func TestCreateNoteHandler_InvalidJSON_ReturnsError(t *testing.T) { // Arrange - handler := handlers.NewCreateNoteHandler() + handler := note.NewCreateNoteHandler() // Act _, err := handler.Handle(Fixture.TestContext, json.RawMessage(`{invalid json}`)) @@ -134,7 +134,7 @@ func TestCreateNoteHandler_InvalidJSON_ReturnsError(t *testing.T) { func TestCreateNoteHandler_NonExistentTemplateName_ReturnsError(t *testing.T) { // Arrange - handler := handlers.NewCreateNoteHandler() + handler := note.NewCreateNoteHandler() params, _ := json.Marshal(map[string]any{ "title": "Ghost Note",