Merge pull request #23 from KristianJBorgwarth/feat/update-note

feat(update_note): add note update on save
This commit is contained in:
Kristian 2026-04-12 23:14:00 +02:00 committed by GitHub
commit 3c8996dc09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 1 deletions

View file

@ -46,6 +46,8 @@ func (h *SaveNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (any,
return nil, err
}
slog.Debug("Parsed file", "path", cmd.Path, "slug", file.Slug, "title", file.Title, "tags", file.FrontMatter.Tags, "links", file.ExtractedLinks)
tx, err := h.uow.Begin()
if err != nil {
return nil, err
@ -69,6 +71,10 @@ func (h *SaveNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (any,
slog.Debug("Failed to delete existing note metadata", "noteID", note.ID(), "error", err)
return nil, err
}
if err = h.noteService.UpdateNote(ctx, tx, note.ID(), file.Path, file.Title, file.Slug); err != nil {
slog.Debug("Failed to update existing note", "noteID", note.ID(), "error", err)
return nil, err
}
}
tagModels, err := h.tagService.CreateTags(ctx, tx, file.FrontMatter.Tags)

View file

@ -11,6 +11,7 @@ import (
type INoteService interface {
CreateNote(ctx context.Context, dbCtx persistence.IDbContext, path, title, slug string) (*models.Note, error)
DeleteNoteMetaData(ctx context.Context, dbCtx persistence.IDbContext, noteID string) error
UpdateNote(ctx context.Context, dbCtx persistence.IDbContext, noteID, path, title, slug string) error
}
type noteService struct {
@ -36,6 +37,13 @@ func (s *noteService) CreateNote(ctx context.Context, dbCtx persistence.IDbConte
return note, nil
}
func (s *noteService) UpdateNote(ctx context.Context, dbCtx persistence.IDbContext, noteID, path, title, slug string) error {
if err := s.noteRepo.Update(ctx, dbCtx, noteID, path, title, slug); err != nil {
return err
}
return nil
}
func (s *noteService) DeleteNoteMetaData(ctx context.Context, dbCtx persistence.IDbContext, noteID string) error {
if err := s.linkRepo.Delete(ctx, dbCtx, noteID); err != nil {
return err

BIN
dendrite

Binary file not shown.

View file

@ -11,6 +11,7 @@ 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)
}
@ -32,6 +33,19 @@ func (r *noteRepository) Insert(ctx context.Context, dbContext persistence.IDbCo
return err
}
func (r *noteRepository) Update(ctx context.Context, dbContext persistence.IDbContext, noteID, path, title, slug string) error {
query := `
UPDATE note
SET path = ?, title = ?, slug = ?, updated_at = datetime('now')
WHERE id = ?;
`
_, err := dbContext.ExecContext(ctx, query, path, title, slug, noteID)
if err != nil {
return err
}
return nil
}
func (r *noteRepository) GetBySlug(ctx context.Context, dbContext persistence.IDbContext, 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)