fix(database): make function more coherent with the rest
Some checks failed
Gitea Build Check / Build (push) Failing after 29s

This commit is contained in:
SoXX 2024-08-11 00:24:02 +02:00
parent 46e6cdfa52
commit 9fe2d0edc3
3 changed files with 19 additions and 19 deletions

View File

@ -8,10 +8,10 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagType) error { func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagType) (models.Tag, error) {
if client == nil { if client == nil {
return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} return models.Tag{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
} }
tag := models.Tag{ tag := models.Tag{
@ -22,12 +22,12 @@ func CreateTag(ctx context.Context, tagName models.TagName, tagType models.TagTy
result := client.WithContext(ctx).Create(&tag) result := client.WithContext(ctx).Create(&tag)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return &otterError.Database{Reason: otterError.DuplicateKey} return models.Tag{}, &otterError.Database{Reason: otterError.DuplicateKey}
} }
return result.Error return models.Tag{}, result.Error
} }
return nil return tag, nil
} }
func CreateTagInBatch(ctx context.Context, tags []models.Tag, batchSize int) error { func CreateTagInBatch(ctx context.Context, tags []models.Tag, batchSize int) error {

View File

@ -8,25 +8,25 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
func CreateTagAlias(ctx context.Context, tagAliasName models.TagAliasName, tagName models.TagName) error { func CreateTagAlias(ctx context.Context, tagAliasName models.TagAliasName, tagName models.TagName) (models.TagAlias, error) {
if client == nil { if client == nil {
return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} return models.TagAlias{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
} }
tag := models.TagAlias{ tagAlias := models.TagAlias{
Name: tagAliasName, Name: tagAliasName,
TagID: tagName, TagID: tagName,
} }
result := client.WithContext(ctx).Create(&tag) result := client.WithContext(ctx).Create(&tagAlias)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return &otterError.Database{Reason: otterError.DuplicateKey} return models.TagAlias{}, &otterError.Database{Reason: otterError.DuplicateKey}
} }
return result.Error return models.TagAlias{}, result.Error
} }
return nil return tagAlias, nil
} }
func CreateTagAliasInBatch(ctx context.Context, tagsAliases []models.TagAlias, batchSize int) error { func CreateTagAliasInBatch(ctx context.Context, tagsAliases []models.TagAlias, batchSize int) error {

View File

@ -8,25 +8,25 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
func CreateTagGroup(ctx context.Context, tagGroupName models.TagGroupName, tagName models.TagName) error { func CreateTagGroup(ctx context.Context, tagGroupName models.TagGroupName, tagName models.TagName) (models.TagGroup, error) {
if client == nil { if client == nil {
return &otterError.Database{Reason: otterError.DatabaseIsNotConnected} return models.TagGroup{}, &otterError.Database{Reason: otterError.DatabaseIsNotConnected}
} }
tag := models.TagGroup{ tagGroup := models.TagGroup{
Name: tagGroupName, Name: tagGroupName,
TagID: tagName, TagID: tagName,
} }
result := client.WithContext(ctx).Create(&tag) result := client.WithContext(ctx).Create(&tagGroup)
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrDuplicatedKey) { if errors.Is(result.Error, gorm.ErrDuplicatedKey) {
return &otterError.Database{Reason: otterError.DuplicateKey} return models.TagGroup{}, &otterError.Database{Reason: otterError.DuplicateKey}
} }
return result.Error return models.TagGroup{}, result.Error
} }
return nil return tagGroup, nil
} }
func CreateTagGroupInBatch(ctx context.Context, tagsGroups []models.TagGroup, batchSize int) error { func CreateTagGroupInBatch(ctx context.Context, tagsGroups []models.TagGroup, batchSize int) error {