diff --git a/core/handlers/note/save_note.go b/core/handlers/note/save_note.go index 871ab60..cdd4e1e 100644 --- a/core/handlers/note/save_note.go +++ b/core/handlers/note/save_note.go @@ -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) diff --git a/core/services/note_service.go b/core/services/note_service.go index ae5dd99..654876e 100644 --- a/core/services/note_service.go +++ b/core/services/note_service.go @@ -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 { @@ -28,7 +29,7 @@ func NewNoteService( } func (s *noteService) CreateNote(ctx context.Context, dbCtx persistence.IDbContext, path, title, slug string) (*models.Note, error) { - note:= models.CreateNote(path, title, slug) + note := models.CreateNote(path, title, slug) if err := s.noteRepo.Insert(ctx, dbCtx, note); err != nil { return nil, err } @@ -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 diff --git a/dendrite b/dendrite index fbe9e89..e18dbe4 100755 Binary files a/dendrite and b/dendrite differ diff --git a/persistence/repositories/note_repository.go b/persistence/repositories/note_repository.go index 1ec7dcd..9b7d1cc 100644 --- a/persistence/repositories/note_repository.go +++ b/persistence/repositories/note_repository.go @@ -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)