Allow other words appear in tag

This commit is contained in:
LittleSheep 2024-07-07 12:35:46 +08:00
parent 4fa351b923
commit fe339e722f
2 changed files with 3 additions and 1 deletions

View File

@ -3,7 +3,7 @@ package models
type Tag struct { type Tag struct {
BaseModel BaseModel
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum"` Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Posts []Post `json:"posts" gorm:"many2many:post_tags"` Posts []Post `json:"posts" gorm:"many2many:post_tags"`

View File

@ -2,6 +2,7 @@ package services
import ( import (
"errors" "errors"
"strings"
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database" "git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models" "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) { func GetTagOrCreate(alias, name string) (models.Tag, error) {
alias = strings.ToLower(alias)
var tag models.Tag var tag models.Tag
if err := database.C.Where(models.Category{Alias: alias}).First(&tag).Error; err != nil { if err := database.C.Where(models.Category{Alias: alias}).First(&tag).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {