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/logger"
|
|
|
|
"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 == "" {
|
|
|
|
logger.Error("usermngmt - Permission - Create: no name data", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.Validate",
|
|
|
|
Message: "usermngmt - Permission - Create: no name data",
|
|
|
|
Data: co,
|
2021-11-10 09:06:33 +00:00
|
|
|
})
|
|
|
|
return errors.New("no name data")
|
|
|
|
}
|
|
|
|
|
2021-11-12 05:16:38 +00:00
|
|
|
// Code
|
|
|
|
if co.Code == "" {
|
|
|
|
logger.Error("usermngmt - Permission - Create: no code data", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.Validate",
|
|
|
|
Message: "usermngmt - Permission - Create: no code data",
|
|
|
|
Data: co,
|
2021-11-12 05:16:38 +00:00
|
|
|
})
|
|
|
|
return errors.New("no code data")
|
|
|
|
}
|
|
|
|
|
2021-11-10 09:06:33 +00:00
|
|
|
// RoleID
|
|
|
|
if co.RoleID == "" {
|
|
|
|
logger.Error("usermngmt - Permission - Create: no roleID data", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.Validate",
|
|
|
|
Message: "usermngmt - Permission - Create: no roleID data",
|
|
|
|
Data: co,
|
2021-11-10 09:06:33 +00:00
|
|
|
})
|
|
|
|
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 == "" {
|
|
|
|
logger.Error("usermngmt - Permission - Create: no desc data", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.Validate",
|
|
|
|
Message: "usermngmt - Permission - Create: no desc data",
|
|
|
|
Data: co,
|
2021-11-10 09:06:33 +00:00
|
|
|
})
|
|
|
|
return errors.New("no desc data")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate ...
|
|
|
|
func (co PermissionUpdateOptions) Validate() error {
|
|
|
|
// Name
|
|
|
|
if co.Name == "" {
|
|
|
|
logger.Error("usermngmt - Permission - Update: no name data", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.Validate",
|
|
|
|
Message: "usermngmt - Permission - Update: no name data",
|
|
|
|
Data: co,
|
2021-11-10 09:06:33 +00:00
|
|
|
})
|
|
|
|
return errors.New("no name data")
|
|
|
|
}
|
|
|
|
|
2021-11-12 05:16:38 +00:00
|
|
|
// Code
|
|
|
|
if co.Code == "" {
|
|
|
|
logger.Error("usermngmt - Permission - Update: no code data", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.Validate",
|
|
|
|
Message: "usermngmt - Permission - Update: no code data",
|
|
|
|
Data: co,
|
2021-11-12 05:16:38 +00:00
|
|
|
})
|
|
|
|
return errors.New("no code data")
|
|
|
|
}
|
|
|
|
|
2021-11-10 09:06:33 +00:00
|
|
|
// RoleID
|
|
|
|
if co.RoleID == "" {
|
|
|
|
logger.Error("usermngmt - Permission - Update: no roleID data", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.Validate",
|
|
|
|
Message: "usermngmt - Permission - Update: no roleID data",
|
|
|
|
Data: co,
|
2021-11-10 09:06:33 +00:00
|
|
|
})
|
|
|
|
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 == "" {
|
|
|
|
logger.Error("usermngmt - Permission - Update: no desc data", logger.LogData{
|
2022-10-05 10:59:08 +00:00
|
|
|
Source: "usermngmt.Validate",
|
|
|
|
Message: "usermngmt - Permission - Update: no desc data",
|
|
|
|
Data: co,
|
2021-11-10 09:06:33 +00:00
|
|
|
})
|
|
|
|
return errors.New("no desc data")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|