usermngmt/model/permission_request.go

86 lines
1.4 KiB
Go
Raw Permalink Normal View History

2021-11-10 09:06:33 +00:00
package model
import (
"errors"
2022-10-10 03:46:33 +00:00
"git.selly.red/Selly-Modules/mongodb"
2021-11-10 09:06:33 +00:00
)
// PermissionCreateOptions ...
type PermissionCreateOptions struct {
Name string
2021-11-12 05:16:38 +00:00
Code string
2021-11-10 09:06:33 +00:00
RoleID string
Desc string
}
// PermissionUpdateOptions ...
type PermissionUpdateOptions struct {
Name string
2021-11-12 05:16:38 +00:00
Code string
2021-11-10 09:06:33 +00:00
RoleID string
Desc string
}
// PermissionAllQuery ...
type PermissionAllQuery struct {
2021-11-17 03:13:08 +00:00
Page int64
Limit int64
Sort interface{}
RoleID string
2021-11-10 09:06:33 +00:00
}
// Validate ...
func (co PermissionCreateOptions) Validate() error {
// Name
if co.Name == "" {
return errors.New("no name data")
}
2021-11-12 05:16:38 +00:00
// Code
if co.Code == "" {
return errors.New("no code data")
}
2021-11-10 09:06:33 +00:00
// 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")
}
2021-11-12 05:16:38 +00:00
// Code
if co.Code == "" {
return errors.New("no code data")
}
2021-11-10 09:06:33 +00:00
// 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
}