40 lines
980 B
Go
40 lines
980 B
Go
package entity
|
|
|
|
// UserRole 使用者角色實體
|
|
type UserRole struct {
|
|
ID int64 `gorm:"column:id;primaryKey" json:"id"`
|
|
Brand string `gorm:"column:brand;size:50;index" json:"brand"`
|
|
UID string `gorm:"column:uid;uniqueIndex;size:32" json:"uid"`
|
|
RoleID string `gorm:"column:role_id;index;size:32" json:"role_id"`
|
|
Status Status `gorm:"column:status;index" json:"status"`
|
|
|
|
TimeStamp
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (UserRole) TableName() string {
|
|
return "user_role"
|
|
}
|
|
|
|
// IsActive 是否啟用
|
|
func (ur *UserRole) IsActive() bool {
|
|
return ur.Status.IsActive()
|
|
}
|
|
|
|
// Validate 驗證資料
|
|
func (ur *UserRole) Validate() error {
|
|
if ur.UID == "" {
|
|
return ErrInvalidData("user uid is required")
|
|
}
|
|
if ur.RoleID == "" {
|
|
return ErrInvalidData("role_id is required")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// RoleUserCount 角色使用者數量統計
|
|
type RoleUserCount struct {
|
|
RoleID string `gorm:"column:role_id" json:"role_id"`
|
|
Count int `gorm:"column:count" json:"count"`
|
|
}
|