From d716086db180e1704cf9c861ad4af3f4be0e4869 Mon Sep 17 00:00:00 2001 From: Kristian Borgwarth <10348902@pm.me> Date: Fri, 3 Apr 2026 12:38:07 +0200 Subject: [PATCH] feat(tag_repo): updated tag repository --- core/handlers/create_note_handler.go | 12 +++++++++--- core/models/tag.go | 5 ++--- go.mod | 2 +- persistence/repositories/tag_repository.go | 1 + 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/handlers/create_note_handler.go b/core/handlers/create_note_handler.go index 7990a1f..da50500 100644 --- a/core/handlers/create_note_handler.go +++ b/core/handlers/create_note_handler.go @@ -7,6 +7,7 @@ import ( "github.com/KristianJBorgwarth/dendrite.daemon/core/frontmatter" "github.com/KristianJBorgwarth/dendrite.daemon/core/models" "github.com/KristianJBorgwarth/dendrite.daemon/core/template" + "github.com/KristianJBorgwarth/dendrite.daemon/core/utilities" "github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories" "github.com/google/uuid" ) @@ -56,10 +57,16 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an tagModels := make([]models.Tag, len(tags)) for i, tag := range tags { - tagModels[i] = models.NewTag(uuidv7.New(), tag) + + id, err := uuid.NewV7() + if err != nil { + return nil, err + } + + tagModels[i] = *models.NewTag(id.String(), tag) } - if err = tagRepo.Upsert(ctx, tags); err != nil { + if err = tagRepo.Upsert(ctx, tagModels); err != nil { return nil, err } @@ -67,7 +74,6 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an return nil, err } - h.uow.FileStore.Stage(cmd.Path, data) if err = h.uow.Commit(); err != nil { diff --git a/core/models/tag.go b/core/models/tag.go index 814441e..00c0648 100644 --- a/core/models/tag.go +++ b/core/models/tag.go @@ -1,15 +1,14 @@ package models -import "github.com/google/uuid" type Tag struct { id string name string } -func NewTag(id uuid.UUID, name string) *Tag { +func NewTag(id string, name string) *Tag { return &Tag{ - id: id.String(), + id: id, name: name, } } diff --git a/go.mod b/go.mod index 1254b4e..c43cce8 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/KristianJBorgwarth/dendrite.daemon go 1.26 require ( + github.com/google/uuid v1.6.0 github.com/stretchr/testify v1.11.1 modernc.org/sqlite v1.47.0 ) @@ -10,7 +11,6 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/ncruces/go-strftime v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/persistence/repositories/tag_repository.go b/persistence/repositories/tag_repository.go index f922ee3..89a8357 100644 --- a/persistence/repositories/tag_repository.go +++ b/persistence/repositories/tag_repository.go @@ -39,6 +39,7 @@ func (r *tagRepository) Upsert(ctx context.Context, tags []models.Tag) error { return err } + func (r *tagRepository) UpsertNoteTags(noteID int64, tagIDs []int64) error { if len(tagIDs) == 0 { return nil