mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Add tag type and tag alias.
This commit is contained in:
@@ -6,19 +6,30 @@ type Tag struct {
|
||||
gorm.Model
|
||||
Name string `gorm:"unique"`
|
||||
Description string
|
||||
AliasOf *uint `gorm:"default:NULL"` // Foreign key for aliasing, can be NULL
|
||||
Type string
|
||||
Resources []Resource `gorm:"many2many:resource_tags;"`
|
||||
Aliases []Tag `gorm:"foreignKey:AliasOf;references:ID"`
|
||||
}
|
||||
|
||||
type TagView struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
Aliases []string `json:"aliases"`
|
||||
}
|
||||
|
||||
func (t *Tag) ToView() *TagView {
|
||||
aliases := make([]string, 0, len(t.Aliases))
|
||||
for _, alias := range t.Aliases {
|
||||
aliases = append(aliases, alias.Name)
|
||||
}
|
||||
return &TagView{
|
||||
ID: t.ID,
|
||||
Name: t.Name,
|
||||
Description: t.Description,
|
||||
Type: t.Type,
|
||||
Aliases: aliases,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user