usermngmt/model/permission_request.go

86 lines
1.4 KiB
Go

package model
import (
"errors"
"git.selly.red/Selly-Modules/mongodb"
)
// PermissionCreateOptions ...
type PermissionCreateOptions struct {
Name string
Code string
RoleID string
Desc string
}
// PermissionUpdateOptions ...
type PermissionUpdateOptions struct {
Name string
Code string
RoleID string
Desc string
}
// PermissionAllQuery ...
type PermissionAllQuery struct {
Page int64
Limit int64
Sort interface{}
RoleID string
}
// Validate ...
func (co PermissionCreateOptions) Validate() error {
// Name
if co.Name == "" {
return errors.New("no name data")
}
// Code
if co.Code == "" {
return errors.New("no code data")
}
// RoleID
if co.RoleID == "" {
return errors.New("no role id data")
}
if _, isValid := mongodb.NewIDFromString(co.RoleID); !isValid {
return errors.New("invalid role id data")
}
// Desc
if co.Desc == "" {
return errors.New("no desc data")
}
return nil
}
// Validate ...
func (co PermissionUpdateOptions) Validate() error {
// Name
if co.Name == "" {
return errors.New("no name data")
}
// Code
if co.Code == "" {
return errors.New("no code data")
}
// RoleID
if co.RoleID == "" {
return errors.New("no role id data")
}
if _, isValid := mongodb.NewIDFromString(co.RoleID); !isValid {
return errors.New("invalid role id data")
}
// Desc
if co.Desc == "" {
return errors.New("no desc data")
}
return nil
}