diff --git a/core/handlers/create_note_handler.go b/core/handlers/create_note_handler.go index da50500..b7fffea 100644 --- a/core/handlers/create_note_handler.go +++ b/core/handlers/create_note_handler.go @@ -7,7 +7,6 @@ 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" ) @@ -55,15 +54,9 @@ func (h *CreateNoteHandler) Handle(ctx context.Context, raw json.RawMessage) (an tagRepo := repositories.NewTagRepository(tx) noteRepo := repositories.NewNoteRepository(tx) - tagModels := make([]models.Tag, len(tags)) - for i, tag := range tags { - - id, err := uuid.NewV7() - if err != nil { - return nil, err - } - - tagModels[i] = *models.NewTag(id.String(), tag) + tagModels, err := models.NewTags(tags) + if err != nil { + return nil, err } if err = tagRepo.Upsert(ctx, tagModels); err != nil { diff --git a/core/models/tag.go b/core/models/tag.go index 00c0648..4e01507 100644 --- a/core/models/tag.go +++ b/core/models/tag.go @@ -1,5 +1,6 @@ package models +import "github.com/google/uuid" type Tag struct { id string @@ -13,6 +14,20 @@ func NewTag(id string, name string) *Tag { } } +func NewTags(tags []string) ([]*Tag, error) { + + tagModels := make([]*Tag, len(tags)) + for i, tag := range tags { + id, err := uuid.NewV7() + if err != nil { + return nil, err + } + tagModels[i] = NewTag(id.String(), tag) + } + + return tagModels, nil +} + func (t *Tag) ID() string { return t.id } diff --git a/persistence/repositories/tag_repository.go b/persistence/repositories/tag_repository.go index 89a8357..7d1c095 100644 --- a/persistence/repositories/tag_repository.go +++ b/persistence/repositories/tag_repository.go @@ -9,7 +9,7 @@ import ( ) type ITagRepository interface { - Upsert(ctx context.Context, tags []models.Tag) error + Upsert(ctx context.Context, tags []*models.Tag) error } type tagRepository struct { @@ -20,7 +20,7 @@ func NewTagRepository(tx *sql.Tx) ITagRepository { return &tagRepository{Transaction: tx} } -func (r *tagRepository) Upsert(ctx context.Context, tags []models.Tag) error { +func (r *tagRepository) Upsert(ctx context.Context, tags []*models.Tag) error { if len(tags) == 0 { return nil }