usermngmt/model/user_request.go

146 lines
2.7 KiB
Go
Raw Permalink Normal View History

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-10 01:44:22 +00:00
Name string
Phone string
Email string
Password string
Status string
RoleID string
Other string
}
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
Other string
}
// 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
}
// 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 == "" {
logger.Error("usermngmt - Create: no Name data", logger.LogData{
"payload": co,
})
return errors.New("no name data")
}
// Phone
if co.Phone == "" {
logger.Error("usermngmt - Create: no phone data", logger.LogData{
"payload": co,
})
return errors.New("no phone data")
}
// Email
if co.Email == "" {
logger.Error("usermngmt - Create: no email data", logger.LogData{
"payload": co,
})
return errors.New("no email data")
}
// Password
if co.Password == "" {
logger.Error("usermngmt - Create: no password data", logger.LogData{
"payload": co,
})
return errors.New("no password data")
}
// Status
if co.Status == "" {
logger.Error("usermngmt - Create: no status data", logger.LogData{
"payload": co,
})
return errors.New("no status data")
}
// RoleID
if co.RoleID == "" {
logger.Error("usermngmt - Create: no roleID data", logger.LogData{
"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 == "" {
logger.Error("usermngmt - Update: no name data", logger.LogData{
"payload": uo,
})
return errors.New("no name data")
}
// Phone
if uo.Phone == "" {
logger.Error("usermngmt - Update: no phone data", logger.LogData{
"payload": uo,
})
return errors.New("no phone data")
}
// Email
if uo.Email == "" {
logger.Error("usermngmt - Update: no email data", logger.LogData{
"payload": uo,
})
return errors.New("no email data")
}
// RoleID
if uo.RoleID == "" {
logger.Error("usermngmt - Update: no roleID data", logger.LogData{
"payload": uo,
})
return errors.New("no role id data")
}
return nil
}
// Validate ...
func (co ChangePasswordOptions) Validate() error {
// OldPassword, NewPassword
if co.OldPassword == "" || co.NewPassword == "" {
logger.Error("usermngmt - ChangePassword: old or new password cannot be empty", logger.LogData{
"payload": co,
})
return errors.New("old or new password cannot be empty")
}
return nil
}