dendrite.nvim/core/services/note_service.go
Kristian c1feac0812
feat(rebuild_guard): only build index on init if empty index (#30)
* feat(persistence): added build-flag and repo funcs

* feat(init_handler): note count check to avoid unnecessary rebuilds

* ref(build_flag): remove build flag is redundant

* build
2026-04-23 20:38:37 +02:00

62 lines
1.9 KiB
Go

package services
import (
"context"
"github.com/KristianJBorgwarth/dendrite.daemon/core/models"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
)
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
GetNoteCount(ctx context.Context) (int, error)
}
type noteService struct {
tagRepo repositories.ITagRepository
linkRepo repositories.ILinkRepository
noteRepo repositories.INoteRepository
}
func NewNoteService(
tagRepo repositories.ITagRepository,
linkRepo repositories.ILinkRepository,
noteRepo repositories.INoteRepository,
) INoteService {
return &noteService{tagRepo, linkRepo, noteRepo}
}
func (s *noteService) CreateNote(ctx context.Context, dbCtx persistence.IDbContext, path, title, slug string) (*models.Note, error) {
note := models.CreateNote(path, title, slug)
if err := s.noteRepo.Insert(ctx, dbCtx, note); err != nil {
return nil, err
}
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
}
if err := s.tagRepo.DeleteNoteTags(ctx, dbCtx, noteID); err != nil {
return err
}
return nil
}
func (s *noteService) GetNoteCount(ctx context.Context) (int, error) {
return s.noteRepo.GetNoteCount(ctx)
}