/
option.go
49 lines (39 loc) · 1.08 KB
/
option.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
package model
import (
"time"
"github.com/geniusrabbit/gosql/v2"
"gorm.io/gorm"
)
type OptionType string
const (
UndefinedOptionType OptionType = "undefined"
UserOptionType OptionType = "user"
AccountOptionType OptionType = "account"
SystemOptionType OptionType = "system"
)
type Option struct {
Type OptionType `json:"type"`
TargetID uint64 `json:"target_id"`
Name string `json:"name"`
Value gosql.NullableJSON[any] `json:"value" gorm:"type:jsonb"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
DeletedAt gorm.DeletedAt `db:"deleted_at"`
}
func (o *Option) TableName() string { return "option" }
func (o *Option) CreatorUserID() uint64 {
if o != nil && o.Type == UserOptionType {
return o.TargetID
}
return 0
}
func (o *Option) OwnerAccountID() uint64 {
if o != nil && o.Type == AccountOptionType {
return o.TargetID
}
return 0
}
// RBACResourceName returns the name of the resource for the RBAC
func (o *Option) RBACResourceName() string {
return "option"
}