feat(tag_repo): updated tag repository

This commit is contained in:
Kristian Borgwarth 2026-04-03 12:38:07 +02:00
parent 2471f5546a
commit d716086db1
4 changed files with 13 additions and 7 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/KristianJBorgwarth/dendrite.daemon/core/frontmatter" "github.com/KristianJBorgwarth/dendrite.daemon/core/frontmatter"
"github.com/KristianJBorgwarth/dendrite.daemon/core/models" "github.com/KristianJBorgwarth/dendrite.daemon/core/models"
"github.com/KristianJBorgwarth/dendrite.daemon/core/template" "github.com/KristianJBorgwarth/dendrite.daemon/core/template"
"github.com/KristianJBorgwarth/dendrite.daemon/core/utilities"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories" "github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
"github.com/google/uuid" "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)) tagModels := make([]models.Tag, len(tags))
for i, tag := range 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 return nil, err
} }
@ -67,7 +74,6 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an
return nil, err return nil, err
} }
h.uow.FileStore.Stage(cmd.Path, data) h.uow.FileStore.Stage(cmd.Path, data)
if err = h.uow.Commit(); err != nil { if err = h.uow.Commit(); err != nil {

View file

@ -1,15 +1,14 @@
package models package models
import "github.com/google/uuid"
type Tag struct { type Tag struct {
id string id string
name string name string
} }
func NewTag(id uuid.UUID, name string) *Tag { func NewTag(id string, name string) *Tag {
return &Tag{ return &Tag{
id: id.String(), id: id,
name: name, name: name,
} }
} }

2
go.mod
View file

@ -3,6 +3,7 @@ module github.com/KristianJBorgwarth/dendrite.daemon
go 1.26 go 1.26
require ( require (
github.com/google/uuid v1.6.0
github.com/stretchr/testify v1.11.1 github.com/stretchr/testify v1.11.1
modernc.org/sqlite v1.47.0 modernc.org/sqlite v1.47.0
) )
@ -10,7 +11,6 @@ require (
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.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/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect

View file

@ -39,6 +39,7 @@ func (r *tagRepository) Upsert(ctx context.Context, tags []models.Tag) error {
return err return err
} }
func (r *tagRepository) UpsertNoteTags(noteID int64, tagIDs []int64) error { func (r *tagRepository) UpsertNoteTags(noteID int64, tagIDs []int64) error {
if len(tagIDs) == 0 { if len(tagIDs) == 0 {
return nil return nil