2021-11-10 02:54:49 +00:00
|
|
|
package model
|
2021-11-10 01:44:22 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/Selly-Modules/logger"
|
|
|
|
)
|
|
|
|
|
2021-11-10 04:01:39 +00:00
|
|
|
// UserCreateOptions ...
|
|
|
|
type UserCreateOptions struct {
|
2021-11-17 06:32:29 +00:00
|
|
|
Name string
|
|
|
|
Phone string
|
|
|
|
Email string
|
|
|
|
Password string
|
|
|
|
Status string
|
|
|
|
RoleID string
|
|
|
|
RequireToChangePassword bool
|
|
|
|
Other interface{}
|
2021-11-10 01:44:22 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 04:01:39 +00:00
|
|
|
// UserUpdateOptions ...
|
|
|
|
type UserUpdateOptions struct {
|
2021-11-10 01:44:22 +00:00
|
|
|
Name string
|
|
|
|
Phone string
|
|
|
|
Email string
|
|
|
|
RoleID string
|
2021-11-12 05:16:38 +00:00
|
|
|
Other interface{}
|
2021-11-10 01:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ChangePasswordOptions ...
|
|
|
|
type ChangePasswordOptions struct {
|
|
|
|
OldPassword string
|
|
|
|
NewPassword string
|
|
|
|
}
|
|
|
|
|
2021-11-10 04:01:39 +00:00
|
|
|
// UserAllQuery ...
|
|
|
|
type UserAllQuery struct {
|
2021-11-10 01:44:22 +00:00
|
|
|
Page int64
|
|
|
|
Limit int64
|
|
|
|
Keyword string
|
|
|
|
RoleID string
|
|
|
|
Status string
|
2021-11-16 07:26:50 +00:00
|
|
|
Sort interface{}
|
2021-11-19 04:00:18 +00:00
|
|
|
Other map[string]interface{} // query fields in other object
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserCountQuery ...
|
|
|
|
type UserCountQuery struct {
|
|
|
|
RoleID string
|
|
|
|
Other map[string]interface{} // query fields in other object
|
2021-11-10 01:44:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate ...
|
2021-11-10 04:01:39 +00:00
|
|
|
func (co UserCreateOptions) Validate() error {
|
2021-11-10 01:44:22 +00:00
|
|
|
// Name
|
|
|
|
if co.Name == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Create: no name data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": co,
|
|
|
|
})
|
|
|
|
return errors.New("no name data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Phone
|
|
|
|
if co.Phone == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Create: no phone data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": co,
|
|
|
|
})
|
|
|
|
return errors.New("no phone data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Email
|
|
|
|
if co.Email == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Create: no email data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": co,
|
|
|
|
})
|
|
|
|
return errors.New("no email data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Password
|
|
|
|
if co.Password == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Create: no password data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": co,
|
|
|
|
})
|
|
|
|
return errors.New("no password data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status
|
|
|
|
if co.Status == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Create: no status data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": co,
|
|
|
|
})
|
|
|
|
return errors.New("no status data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// RoleID
|
|
|
|
if co.RoleID == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Create: no roleID data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": co,
|
|
|
|
})
|
|
|
|
return errors.New("no role id data")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate ...
|
2021-11-10 04:01:39 +00:00
|
|
|
func (uo UserUpdateOptions) Validate() error {
|
2021-11-10 01:44:22 +00:00
|
|
|
// Name
|
|
|
|
if uo.Name == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Update: no name data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": uo,
|
|
|
|
})
|
|
|
|
return errors.New("no name data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Phone
|
|
|
|
if uo.Phone == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Update: no phone data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": uo,
|
|
|
|
})
|
|
|
|
return errors.New("no phone data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Email
|
|
|
|
if uo.Email == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Update: no email data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": uo,
|
|
|
|
})
|
|
|
|
return errors.New("no email data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// RoleID
|
|
|
|
if uo.RoleID == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - Update: no roleID data", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": uo,
|
|
|
|
})
|
|
|
|
return errors.New("no role id data")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate ...
|
|
|
|
func (co ChangePasswordOptions) Validate() error {
|
|
|
|
// OldPassword, NewPassword
|
|
|
|
if co.OldPassword == "" || co.NewPassword == "" {
|
2021-11-10 07:50:43 +00:00
|
|
|
logger.Error("usermngmt - User - ChangePassword: old or new password cannot be empty", logger.LogData{
|
2021-11-10 01:44:22 +00:00
|
|
|
"payload": co,
|
|
|
|
})
|
|
|
|
return errors.New("old or new password cannot be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|