chore(sln): small improvements to repo structure and naming
This commit is contained in:
parent
25098f0778
commit
c872cf8b57
10 changed files with 26 additions and 22 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
2
core/handlers/note/doc.go
Normal file
2
core/handlers/note/doc.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// Package note provides the handlers for note commands
|
||||
package note
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package handlers
|
||||
package note
|
||||
|
||||
import (
|
||||
"context"
|
||||
2
core/handlers/vault/doc.go
Normal file
2
core/handlers/vault/doc.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// Package vault provides handlers for vault commands
|
||||
package vault
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package handlers
|
||||
package vault
|
||||
|
||||
import (
|
||||
"context"
|
||||
BIN
dendrite
BIN
dendrite
Binary file not shown.
|
|
@ -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'))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue