wms-be/modules/role/dto/role_dto.go

148 lines
6.3 KiB
Go

package dto
import (
"errors"
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
)
const (
// Failed
MESSAGE_FAILED_GET_DATA_FROM_BODY = "failed get data from body"
MESSAGE_FAILED_REGISTER_ROLE = "failed create user"
MESSAGE_FAILED_GET_LIST_ROLE = "failed get list user"
MESSAGE_FAILED_TOKEN_NOT_VALID = "token not valid"
MESSAGE_FAILED_TOKEN_NOT_FOUND = "token not found"
MESSAGE_FAILED_GET_ROLE = "failed get role"
MESSAGE_FAILED_LOGIN = "failed login"
MESSAGE_FAILED_UPDATE_ROLE = "failed update role"
MESSAGE_FAILED_DELETE_ROLE = "failed delete role"
MESSAGE_FAILED_PROSES_REQUEST = "failed proses request"
MESSAGE_FAILED_DENIED_ACCESS = "denied access"
MESSAGE_FAILED_VERIFY_EMAIL = "failed verify email"
MESSAGE_FAILED_ASSIGN_ROLE = "failed assign role to user"
MESSAGE_FAILED_REMOVE_ROLE = "failed remove role from user"
MESSAGE_FAILED_ASSIGN_PERMISSION = "failed assign permission to role"
// Success
MESSAGE_SUCCESS_REGISTER_ROLE = "success create role"
MESSAGE_SUCCESS_GET_LIST_ROLE = "success get list role"
MESSAGE_SUCCESS_GET_ROLE = "success get role"
MESSAGE_SUCCESS_LOGIN = "success login"
MESSAGE_SUCCESS_UPDATE_ROLE = "success update role"
MESSAGE_SUCCESS_DELETE_ROLE = "success delete role"
MESSAGE_SEND_VERIFICATION_EMAIL_SUCCESS = "success send verification email"
MESSAGE_SUCCESS_VERIFY_EMAIL = "success verify email"
MESSAGE_SUCCESS_ASSIGN_ROLE = "success assign role to user"
MESSAGE_SUCCESS_REMOVE_ROLE = "success remove role from user"
MESSAGE_SUCCESS_ASSIGN_PERMISSION = "success assign permission to role"
MESSAGE_SUCCESS_REMOVE_PERMISSION = "success remove permission from role"
MESSAGE_SUCCESS_ASSIGN_MENU = "success assign menu to role"
MESSAGE_SUCCESS_REMOVE_MENU = "success remove menu from role"
MESSAGE_FAILED_ASSIGN_MENU = "failed assign menu to role"
MESSAGE_FAILED_REMOVE_MENU = "failed remove menu from role"
)
var (
ErrCreateRole = errors.New("failed to create role")
ErrGetRoleById = errors.New("failed to get role by id")
ErrGetRoleByName = errors.New("failed to get role by name")
ErrRoleAlreadyExists = errors.New("role already exist")
ErrMenuAlreadyExists = errors.New("menu already exist")
ErrPermissionAlreadyExists = errors.New("permission already exist")
ErrUpdateRole = errors.New("failed to update role")
ErrDeleteRole = errors.New("failed to delete role")
ErrRoleNotFound = errors.New("role not found")
ErrMenuNotFound = errors.New("menu not found")
ErrPermissionNotFound = errors.New("permission not found")
ErrAssignRoleToUser = errors.New("failed to assign role to user")
ErrRemoveRoleFromUser = errors.New("failed to remove role from user")
ErrAssignPermissionToRole = errors.New("failed to assign permission to role")
ErrRemovePermissionFromRole = errors.New("failed to remove permission from role")
ErrAssignMenuToRole = errors.New("failed to assign menu to role")
ErrRemoveMenuFromRole = errors.New("failed to remove menu from role")
)
type RoleCreateRequest struct {
Name string `json:"name" binding:"required"`
Description string `json:"description" binding:"omitempty"`
IconUrl string `json:"icon_url" binding:"omitempty"`
Type string `json:"type" binding:"omitempty"`
HomeUrl string `json:"home_url" binding:"omitempty"`
Level int `json:"level" binding:"omitempty"`
ClientID string `json:"client_id" binding:"required,uuid4"`
RoleMenus []string `json:"role_menus" binding:"omitempty"`
RolePermissions []string `json:"role_permissions" binding:"omitempty"`
UserRoles []string `json:"user_roles" binding:"omitempty"`
Users []string `json:"users" binding:"omitempty"`
Permissions []string `json:"permissions" binding:"omitempty"`
}
type RoleUpdateRequest struct {
Name string `json:"name" binding:"omitempty"`
Description string `json:"description" binding:"omitempty"`
IconUrl string `json:"icon_url" binding:"omitempty"`
Type string `json:"type" binding:"omitempty"`
HomeUrl string `json:"home_url" binding:"omitempty"`
ClientID string `json:"client_id" binding:"omitempty,uuid4"`
Level int `json:"level" binding:"omitempty"`
Permissions []string `json:"permissions" binding:"omitempty"`
}
type RoleResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
IconUrl string `json:"icon_url"`
Type string `json:"type"`
HomeUrl string `json:"home_url"`
Level int `json:"level"`
// ClientID string `json:"client_id"`
Client pkgdto.IdNameResponse `json:"client"`
Permissions []RolePermissionsResponse `json:"permissions,omitempty"`
Menus []RoleMenuResponse `json:"menus,omitempty"`
}
type RoleMenuResponse struct {
ID string `json:"id"`
Name string `json:"name"`
IconUrl string `json:"icon_url"`
Url string `json:"url"`
Sequence int `json:"sequence"`
Parent *RoleMenuResponse `json:"parent,omitempty"`
}
type RolePermissionsResponse struct {
ID string `json:"id"`
Name string `json:"name"`
}
type AssignRoleRequest struct {
// UserID string `json:"user_id" binding:"required,uuid4"`
RoleID []string `json:"role_ids" binding:"required,dive,uuid4"`
}
type RemoveRoleRequest struct {
// UserID string `json:"user_id" binding:"required,uuid4"`
RoleID []string `json:"role_ids" binding:"required,dive,uuid4"`
}
type AssignPermissionRequest struct {
// RoleID string `json:"role_id" binding:"required,uuid4"`
PermissionID []string `json:"permission_ids" binding:"required,dive,uuid4"`
}
type RemovePermissionRequest struct {
// RoleID string `json:"role_id" binding:"required,uuid4"`
PermissionID []string `json:"permission_ids" binding:"required,dive,uuid4"`
}
type AssignMenuRequest struct {
MenuID []string `json:"menu_ids" binding:"required,dive,uuid4"`
}
type RemoveMenuRequest struct {
MenuID []string `json:"menu_ids" binding:"required,dive,uuid4"`
}