From fe339e722ff2a9350ae780b31c0749e05d55cea6 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 7 Jul 2024 12:35:46 +0800 Subject: [PATCH] :sparkles: Allow other words appear in tag --- pkg/internal/models/categories.go | 2 +- pkg/internal/services/categories.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/internal/models/categories.go b/pkg/internal/models/categories.go index 31c5867..30605f7 100644 --- a/pkg/internal/models/categories.go +++ b/pkg/internal/models/categories.go @@ -3,7 +3,7 @@ package models type Tag struct { BaseModel - Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum"` + Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase"` Name string `json:"name"` Description string `json:"description"` Posts []Post `json:"posts" gorm:"many2many:post_tags"` diff --git a/pkg/internal/services/categories.go b/pkg/internal/services/categories.go index 4216e84..8c81c56 100644 --- a/pkg/internal/services/categories.go +++ b/pkg/internal/services/categories.go @@ -2,6 +2,7 @@ package services import ( "errors" + "strings" "git.solsynth.dev/hydrogen/interactive/pkg/internal/database" "git.solsynth.dev/hydrogen/interactive/pkg/internal/models" @@ -61,6 +62,7 @@ func DeleteCategory(category models.Category) error { } func GetTagOrCreate(alias, name string) (models.Tag, error) { + alias = strings.ToLower(alias) var tag models.Tag if err := database.C.Where(models.Category{Alias: alias}).First(&tag).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) {