feat(tag_repo): updated tag repository
This commit is contained in:
parent
2471f5546a
commit
d716086db1
4 changed files with 13 additions and 7 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
if err = tagRepo.Upsert(ctx, tags); err != nil {
|
||||
tagModels[i] = *models.NewTag(id.String(), tag)
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
go.mod
2
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue