usermngmt/action.go

110 lines
2.5 KiB
Go
Raw Permalink Normal View History

2021-11-10 01:44:22 +00:00
package usermngmt
2021-11-10 02:54:49 +00:00
import (
2021-11-11 08:16:17 +00:00
"github.com/Selly-Modules/usermngmt/cache"
2021-11-10 04:01:39 +00:00
"github.com/Selly-Modules/usermngmt/model"
2021-11-10 09:06:33 +00:00
"github.com/Selly-Modules/usermngmt/permission"
2021-11-10 04:42:23 +00:00
"github.com/Selly-Modules/usermngmt/role"
"github.com/Selly-Modules/usermngmt/user"
2021-11-10 02:54:49 +00:00
)
2021-11-10 01:44:22 +00:00
2021-11-10 05:07:58 +00:00
//
// User
//
// user methods
// CreateUser ...
func (s Service) CreateUser(payload model.UserCreateOptions) error {
2021-11-10 04:42:23 +00:00
return user.Create(payload)
2021-11-10 01:44:22 +00:00
}
2021-11-10 05:07:58 +00:00
// UpdateUser ...
func (s Service) UpdateUser(userID string, payload model.UserUpdateOptions) error {
2021-11-10 04:42:23 +00:00
return user.UpdateByUserID(userID, payload)
2021-11-10 01:44:22 +00:00
}
// ChangeUserPassword ...
2021-11-10 02:54:49 +00:00
func (s Service) ChangeUserPassword(userID string, payload model.ChangePasswordOptions) error {
2021-11-10 04:42:23 +00:00
return user.ChangeUserPassword(userID, payload)
2021-11-10 01:44:22 +00:00
}
2021-11-10 04:42:23 +00:00
// ChangeUserStatus ...
2021-11-10 01:44:22 +00:00
func (s Service) ChangeUserStatus(userID, newStatus string) error {
2021-11-10 04:42:23 +00:00
return user.ChangeUserStatus(userID, newStatus)
2021-11-10 01:44:22 +00:00
}
2021-11-10 09:53:31 +00:00
// GetAllUsers ...
func (s Service) GetAllUsers(query model.UserAllQuery) model.UserAll {
2021-11-10 04:42:23 +00:00
return user.All(query)
2021-11-10 01:44:22 +00:00
}
2021-11-10 07:50:43 +00:00
// ChangeAllUsersStatus ...
func (s Service) ChangeAllUsersStatus(roleID, status string) error {
return user.ChangeAllUsersStatus(roleID, status)
}
2021-11-10 09:06:33 +00:00
// LoginWithEmailAndPassword ...
func (s Service) LoginWithEmailAndPassword(email, password string) (model.User, error) {
return user.LoginWithEmailAndPassword(email, password)
}
2021-11-10 10:02:16 +00:00
// HasPermission ...
func (s Service) HasPermission(userID, permission string) bool {
return user.HasPermission(userID, permission)
2021-11-10 09:53:31 +00:00
}
2021-11-10 05:07:58 +00:00
//
// Role
//
// role methods
// CreateRole ...
func (s Service) CreateRole(payload model.RoleCreateOptions) error {
2021-11-11 08:16:17 +00:00
if err := role.Create(payload); err != nil {
return err
2021-11-11 03:20:08 +00:00
}
2021-11-11 08:16:17 +00:00
cache.Roles()
return nil
2021-11-10 01:44:22 +00:00
}
2021-11-10 07:50:43 +00:00
// UpdateRole ...
func (s Service) UpdateRole(roleID string, payload model.RoleUpdateOptions) error {
return role.Update(roleID, payload)
}
2021-11-10 08:00:36 +00:00
// GetAllRoles ...
func (s Service) GetAllRoles(query model.RoleAllQuery) model.RoleAll {
2021-11-10 07:50:43 +00:00
return role.All(query)
}
2021-11-10 09:06:33 +00:00
//
// Permission
//
// permission methods
// CreatePermission ...
func (s Service) CreatePermission(payload model.PermissionCreateOptions) error {
2021-11-11 08:16:17 +00:00
if err := permission.Create(payload); err != nil {
return err
2021-11-11 03:20:08 +00:00
}
2021-11-11 08:16:17 +00:00
cache.Roles()
return nil
2021-11-10 09:06:33 +00:00
}
// UpdatePermission ...
func (s Service) UpdatePermission(permissionID string, payload model.PermissionUpdateOptions) error {
2021-11-11 08:16:17 +00:00
if err := permission.Update(permissionID, payload); err != nil {
return err
2021-11-11 03:20:08 +00:00
}
2021-11-11 08:16:17 +00:00
cache.Roles()
return nil
2021-11-10 09:06:33 +00:00
}
// GetAllPermissions ...
func (s Service) GetAllPermissions(query model.PermissionAllQuery) model.PermissionAll {
return permission.All(query)
}