资产增加标签的功能
This commit is contained in:
@ -114,3 +114,11 @@ func AssetTcpingEndpoint(c echo.Context) (err error) {
|
||||
model.UpdateAssetById(&asset, item.ID)
|
||||
return Success(c, active)
|
||||
}
|
||||
|
||||
func AssetTagsEndpoint(c echo.Context) (err error) {
|
||||
var items []string
|
||||
if items, err = model.FindAssetTags(); err != nil {
|
||||
return err
|
||||
}
|
||||
return Success(c, items)
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ func SetupRoutes() *echo.Echo {
|
||||
assets.GET("/:id", AssetGetEndpoint)
|
||||
}
|
||||
|
||||
e.GET("/tags", AssetTagsEndpoint)
|
||||
|
||||
commands := e.Group("/commands")
|
||||
{
|
||||
commands.GET("/paging", CommandPagingEndpoint)
|
||||
@ -94,6 +96,16 @@ func SetupRoutes() *echo.Echo {
|
||||
sessions.GET("/:id", SessionGetEndpoint)
|
||||
}
|
||||
|
||||
//tags := e.Group("/tags")
|
||||
//{
|
||||
// tags.POST("", TagAllEndpoint)
|
||||
// tags.GET("/paging", TagPagingEndpoint)
|
||||
// tags.POST("", TagCreateEndpoint)
|
||||
// tags.PUT("/:id", TagUpdateEndpoint)
|
||||
// tags.DELETE("/:id", TagDeleteEndpoint)
|
||||
// tags.GET("/:id", TagGetEndpoint)
|
||||
//}
|
||||
|
||||
e.GET("/properties", PropertyGetEndpoint)
|
||||
e.PUT("/properties", PropertyUpdateEndpoint)
|
||||
|
||||
|
@ -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