资产增加标签的功能

This commit is contained in:
dushixiang
2021-01-04 21:29:37 +08:00
parent 5457f8f4dd
commit c362d9b98a
8 changed files with 94 additions and 31 deletions

View File

@ -3,6 +3,7 @@ package model
import (
"next-terminal/pkg/global"
"next-terminal/pkg/utils"
"strings"
)
type Asset struct {
@ -20,6 +21,7 @@ type Asset struct {
Description string `json:"description"`
Active bool `json:"active"`
Created utils.JsonTime `json:"created"`
Tags string `json:"tags"`
}
func (r *Asset) TableName() string {
@ -84,3 +86,24 @@ func CountAsset() (total int64, err error) {
err = global.DB.Find(&Asset{}).Count(&total).Error
return
}
func FindAssetTags() (o []string, err error) {
var assets []Asset
err = global.DB.Not("tags = ?", "").Find(&assets).Error
if err != nil {
return nil, err
}
o = make([]string, 0)
for i := range assets {
if len(assets[i].Tags) == 0 {
continue
}
split := strings.Split(assets[i].Tags, ",")
o = append(o, split...)
}
return o, nil
}