forked from cloudreve/Cloudreve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag.go
53 lines (46 loc) · 1.32 KB
/
tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package model
import (
"github.com/HFO4/cloudreve/pkg/util"
"github.com/jinzhu/gorm"
)
// Tag 用户自定义标签
type Tag struct {
gorm.Model
Name string // 标签名
Icon string // 图标标识
Color string // 图标颜色
Type int // 标签类型(文件分类/目录直达)
Expression string `gorm:"type:text"` // 搜索表表达式/直达路径
UserID uint // 创建者ID
}
const (
// FileTagType 文件分类标签
FileTagType = iota
// DirectoryLinkType 目录快捷方式标签
DirectoryLinkType
)
// Create 创建标签记录
func (tag *Tag) Create() (uint, error) {
if err := DB.Create(tag).Error; err != nil {
util.Log().Warning("无法插入离线下载记录, %s", err)
return 0, err
}
return tag.ID, nil
}
// DeleteTagByID 根据给定ID和用户ID删除标签
func DeleteTagByID(id, uid uint) error {
result := DB.Where("id = ? and user_id = ?", id, uid).Delete(&Tag{})
return result.Error
}
// GetTagsByUID 根据用户ID查找标签
func GetTagsByUID(uid uint) ([]Tag, error) {
var tag []Tag
result := DB.Where("user_id = ?", uid).Find(&tag)
return tag, result.Error
}
// GetTagsByID 根据ID查找标签
func GetTagsByID(id, uid uint) (*Tag, error) {
var tag Tag
result := DB.Where("user_id = ? and id = ?", uid, id).First(&tag)
return &tag, result.Error
}