usermngmt/action.go

183 lines
4.3 KiB
Go
Raw Normal View History

2021-11-10 01:44:22 +00:00
package usermngmt
2021-11-10 02:54:49 +00:00
import (
2022-10-10 03:46:33 +00:00
"git.selly.red/Selly-Modules/usermngmt/cache"
"git.selly.red/Selly-Modules/usermngmt/model"
"git.selly.red/Selly-Modules/usermngmt/permission"
"git.selly.red/Selly-Modules/usermngmt/role"
"git.selly.red/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 ...
2021-11-16 04:11:04 +00:00
func (s Service) CreateUser(payload model.UserCreateOptions) (id string, err error) {
2021-11-10 04:42:23 +00:00
return user.Create(payload)
2021-11-10 01:44:22 +00:00
}
2021-11-19 02:59:33 +00:00
// FindUser ...
func (s Service) FindUser(userID string) (model.User, error) {
return user.FindUser(userID)
}
2021-12-01 07:34:52 +00:00
// FindUserByEmail ...
func (s Service) FindUserByEmail(email string) (model.User, error) {
return user.FindUserByEmail(email)
}
// GetHashedPassword ...
func (s Service) GetHashedPassword(userID string) (string, error) {
return user.GetHashedPassword(userID)
}
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-12-01 10:51:44 +00:00
// ResetUserPassword ...
func (s Service) ResetUserPassword(userID string, password string) error {
return user.ResetUserPassword(userID, password)
}
// ResetAndRequireToChangeUserPassword ...
func (s Service) ResetAndRequireToChangeUserPassword(userID string, password string) error {
return user.ResetAndRequireToChangeUserPassword(userID, password)
}
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
}
2022-03-25 07:16:52 +00:00
// GetUsersByPermission ...
func (s Service) GetUsersByPermission(query model.UserByPermissionQuery) model.UserAll {
return user.GetUsersByPermission(query)
}
2021-11-19 04:00:18 +00:00
// CountAllUsers ...
func (s Service) CountAllUsers(query model.UserCountQuery) int64 {
return user.Count(query)
}
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-17 06:32:29 +00:00
// UpdateUserAvatar ...
2021-11-22 10:35:21 +00:00
func (s Service) UpdateUserAvatar(userID string, avatar interface{}) error {
2021-11-17 06:32:29 +00:00
return user.UpdateAvatar(userID, avatar)
}
// DeleteUser ...
func (s Service) DeleteUser(userID string) error {
return user.Delete(userID)
}
2021-11-10 05:07:58 +00:00
//
// Role
//
// role methods
// CreateRole ...
2021-11-16 04:11:04 +00:00
func (s Service) CreateRole(payload model.RoleCreateOptions) (id string, err error) {
id, err = role.Create(payload)
if err != nil {
return
2021-11-11 03:20:08 +00:00
}
2021-11-16 04:11:04 +00:00
2021-11-11 08:16:17 +00:00
cache.Roles()
2021-11-16 04:11:04 +00:00
return
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
2021-11-19 06:50:24 +00:00
// FindRole ...
func (s Service) FindRole(roleID string) (model.Role, error) {
return role.FindRole(roleID)
}
2021-11-10 09:06:33 +00:00
//
// Permission
//
// permission methods
// CreatePermission ...
2021-11-16 04:11:04 +00:00
func (s Service) CreatePermission(payload model.PermissionCreateOptions) (id string, err error) {
id, err = permission.Create(payload)
if err != nil {
return
2021-11-11 03:20:08 +00:00
}
2021-11-16 05:16:06 +00:00
2021-11-11 08:16:17 +00:00
cache.Roles()
2021-11-16 04:11:04 +00:00
return
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
}
2021-11-16 08:34:56 +00:00
// DeletePermission ...
func (s Service) DeletePermission(permissionID string) error {
if err := permission.Delete(permissionID); err != nil {
return err
}
cache.Roles()
return nil
}
2023-04-05 10:54:05 +00:00
// FindAndDeletePermission ...
func (s Service) FindAndDeletePermission(permissionID string) (*model.Permission, error) {
p, err := permission.FindByIDAndDelete(permissionID)
if err != nil {
return nil, err
}
cache.Roles()
return p, nil
}
2021-11-10 09:06:33 +00:00
// GetAllPermissions ...
func (s Service) GetAllPermissions(query model.PermissionAllQuery) model.PermissionAll {
return permission.All(query)
}