资产增加标签的功能
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ func CreateNewCredential(o *Credential) (err error) {
|
||||
}
|
||||
|
||||
func FindCredentialById(id string) (o Credential, err error) {
|
||||
|
||||
err = global.DB.Where("id = ?", id).First(&o).Error
|
||||
return
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
package model
|
||||
|
||||
import "next-terminal/pkg/global"
|
||||
|
||||
type Tag struct {
|
||||
Tag string `json:"tag"`
|
||||
}
|
||||
|
||||
func (r *Tag) TableName() string {
|
||||
return "tags"
|
||||
}
|
||||
|
||||
func FindAllTag() (o []Property) {
|
||||
if global.DB.Find(&o).Error != nil {
|
||||
return nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func CreateNewTag(o *Tag) (err error) {
|
||||
err = global.DB.Create(o).Error
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user