backend/pkg/permission/domain/entity/permission.go

67 lines
1.8 KiB
Go

package entity
import (
"time"
"go.mongodb.org/mongo-driver/v2/bson"
)
// PermissionType 權限類型
type PermissionType int
const (
PermissionTypeAPI PermissionType = 1 // API 權限
PermissionTypeMenu PermissionType = 2 // 選單權限
)
// Permission 權限實體
type Permission struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
ParentID *bson.ObjectID `bson:"parent_id,omitempty" json:"parent_id"`
Name string `bson:"name" json:"name"`
HTTPMethod string `bson:"http_method" json:"http_method"`
HTTPPath string `bson:"http_path" json:"http_path"`
Status int `bson:"status" json:"status"`
Type PermissionType `bson:"type" json:"type"`
CreateTime time.Time `bson:"create_time" json:"create_time"`
UpdateTime time.Time `bson:"update_time" json:"update_time"`
}
// CollectionName 返回集合名稱
func (p *Permission) CollectionName() string {
return "permissions"
}
//// StatusActive 權限啟用狀態
//const StatusActive = 1
//
//// IsActive 檢查權限是否啟用
//func (p *Permission) IsActive() bool {
// return p.Status == StatusActive
//}
//
//
//// Validate 驗證權限數據
//func (p *Permission) Validate() error {
// if p.Name == "" {
// return mongo.WriteError{Code: 400, Message: "permission name is required"}
// }
// if p.Type == PermissionTypeAPI {
// if p.HTTPMethod == "" {
// return mongo.WriteError{Code: 400, Message: "http_method is required for API permission"}
// }
// if p.HTTPPath == "" {
// return mongo.WriteError{Code: 400, Message: "http_path is required for API permission"}
// }
// }
// return nil
//}
//
//// GetKey 獲取權限標識
//func (p *Permission) GetKey() string {
// if p.Type == PermissionTypeAPI {
// return p.HTTPMethod + ":" + p.HTTPPath
// }
// return p.Name
//}