feat(goto): added goto_note_handler

This commit is contained in:
Kristian Borgwarth 2026-04-14 18:26:38 +02:00
parent 7e45dd493f
commit f8ba52e62e
5 changed files with 19 additions and 11 deletions

View file

@ -22,7 +22,7 @@ func main() {
uow := repositories.NewUnitOfWork();
linkRepo := repositories.NewLinkRepository(*persistence.NewReadContext())
tagRepo := repositories.NewTagRepository()
noteRepo := repositories.NewNoteRepository()
noteRepo := repositories.NewNoteRepository(*persistence.NewReadContext())
tagService := services.NewTagService(tagRepo)
linkService := services.NewLinkService(linkRepo)
noteService := services.NewNoteService(tagRepo, linkRepo, noteRepo)

View file

@ -1,6 +1,10 @@
package note
import "github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
import (
"context"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
)
type gotoNoteCommand struct {
Slug string `json:"slug"`
@ -10,13 +14,14 @@ type gotoNoteResult struct {
Path string `json:"path"`
}
type GotoNoteHandler struct{
type GotoNoteHandler struct {
noteRepo repositories.INoteRepository
}
func(h *GotoNoteHandler) Handle(command gotoNoteCommand) (gotoNoteResult, error) {
note, err := h.noteRepo.GetBySlug(command.Slug)
func (h *GotoNoteHandler) Handle(ctx context.Context, command gotoNoteCommand) (gotoNoteResult, error) {
note, err := h.noteRepo.GetBySlug(ctx, command.Slug)
if err != nil {
return gotoNoteResult{}, err
}
return gotoNoteResult{Path: note.Path()}, nil
}

View file

@ -54,7 +54,7 @@ func (h *SaveNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (any,
}
defer h.uow.Rollback()
note, err := h.noteRepo.GetBySlug(ctx, tx, file.Slug)
note, err := h.noteRepo.GetBySlug(ctx, file.Slug)
if err != nil {
slog.Debug("Failed to get note by slug", "slug", file.Slug, "error", err)
return nil, err

View file

@ -12,10 +12,12 @@ import (
type INoteRepository interface {
Insert(ctx context.Context, dbContext persistence.IDbContext, note *models.Note) error
Update(ctx context.Context, dbContext persistence.IDbContext, noteID, path, title, slug string) error
GetBySlug(ctx context.Context, dbContext persistence.IDbContext, slug string) (*models.Note, error)
GetBySlug(ctx context.Context, slug string) (*models.Note, error)
}
type noteRepository struct{}
type noteRepository struct{
readDBContext persistence.ReadContext
}
func NewNoteRepository(persistence.ReadContext) INoteRepository {
return &noteRepository{}
@ -46,9 +48,9 @@ func (r *noteRepository) Update(ctx context.Context, dbContext persistence.IDbCo
return nil
}
func (r *noteRepository) GetBySlug(ctx context.Context, dbContext persistence.IDbContext, slug string) (*models.Note, error) {
func (r *noteRepository) GetBySlug(ctx context.Context, slug string) (*models.Note, error) {
query := `SELECT id, title, path, slug, created_at, updated_at FROM note WHERE slug = ?`
row := dbContext.QueryRowContext(ctx, query, slug)
row := r.readDBContext.QueryRowContext(ctx, query, slug)
var id, title, path, createdAt, updatedAt string
err := row.Scan(&id, &title, &path, &slug, &createdAt, &updatedAt)

View file

@ -8,6 +8,7 @@ import (
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/note"
"github.com/KristianJBorgwarth/dendrite.daemon/core/services"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -17,7 +18,7 @@ func newCreateNoteHandler() *note.CreateNoteHandler {
return note.NewCreateNoteHandler(
repositories.NewUnitOfWork(),
services.NewTagService(repositories.NewTagRepository()),
repositories.NewNoteRepository(),
repositories.NewNoteRepository(*persistence.NewReadContext()),
)
}