package entity import ( "backend/pkg/permission/domain/permission" "go.mongodb.org/mongo-driver/v2/bson" ) // Permission 權限實體 (MongoDB) 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,omitempty" json:"http_method,omitempty"` HTTPPath string `bson:"http_path,omitempty" json:"http_path,omitempty"` State permission.RecordState `bson:"status" json:"status"` // 本筆資料的週期 Type permission.Type `bson:"type" json:"type"` permission.TimeStamp `bson:",inline"` } // CollectionName 集合名稱 func (p *Permission) CollectionName() string { return "permission" } //// IsActive 是否啟用 //func (p *Permission) IsActive() bool { // return p.Status.IsActive() //} //IsActive //// IsParent 是否為父權限 //func (p *Permission) IsParent() bool { // return p.ParentID.IsZero() //} // //// IsAPIPermission 是否為 API 權限 //func (p *Permission) IsAPIPermission() bool { // return p.HTTPPath != "" && p.HTTPMethod != "" //} // //// Validate 驗證資料 //func (p *Permission) Validate() error { // if p.Name == "" { // return ErrInvalidData("permission name is required") // } // // API 權限必須有 path 和 method // if (p.HTTPPath != "" && p.HTTPMethod == "") || (p.HTTPPath == "" && p.HTTPMethod != "") { // return ErrInvalidData("permission http_path and http_method must be both set or both empty") // } // return nil //}