114 lines
4.7 KiB
Go
114 lines
4.7 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"
|
|
)
|
|
|
|
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")
|
|
ErrPermissionAlreadyExists = errors.New("permission already exist")
|
|
ErrUpdateRole = errors.New("failed to update role")
|
|
ErrRoleNotFound = errors.New("role not found")
|
|
ErrDeleteRole = errors.New("failed to delete role")
|
|
ErrPermissionNotFound = errors.New("permission not found")
|
|
)
|
|
|
|
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"`
|
|
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"`
|
|
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"`
|
|
// ClientID string `json:"client_id"`
|
|
Client pkgdto.IdNameResponse `json:"client"`
|
|
Permissions []RolePermissionsResponse `json:"permissions,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"`
|
|
}
|