2025-09-28 01:53:09 +00:00
|
|
|
package request
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-30 13:34:56 +00:00
|
|
|
"netidhub-saas-be/app/database/entity"
|
|
|
|
|
"netidhub-saas-be/utils/paginator"
|
2025-09-28 01:53:09 +00:00
|
|
|
"strconv"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type MasterMenusGeneric interface {
|
|
|
|
|
ToEntity()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MasterMenusQueryRequest struct {
|
|
|
|
|
Name *string `json:"name"`
|
|
|
|
|
Description *string `json:"description"`
|
|
|
|
|
ModuleId *int `json:"moduleId"`
|
|
|
|
|
ParentMenuId *int `json:"parentMenuId"`
|
|
|
|
|
StatusId *int `json:"statusId"`
|
|
|
|
|
Pagination *paginator.Pagination `json:"pagination"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MasterMenusCreateRequest struct {
|
|
|
|
|
Name string `json:"name" validate:"required"`
|
|
|
|
|
Description string `json:"description" validate:"required"`
|
2026-01-18 19:58:10 +00:00
|
|
|
ModuleId *int `json:"moduleId,omitempty"`
|
2025-09-28 01:53:09 +00:00
|
|
|
Group string `json:"group" validate:"required"`
|
|
|
|
|
StatusId int `json:"statusId" validate:"required"`
|
2026-01-18 19:58:10 +00:00
|
|
|
ParentMenuId *int `json:"parentMenuId,omitempty"`
|
|
|
|
|
Icon *string `json:"icon,omitempty"`
|
2025-09-28 01:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (req MasterMenusCreateRequest) ToEntity() *entity.MasterMenus {
|
2026-01-18 19:58:10 +00:00
|
|
|
moduleId := 0
|
|
|
|
|
if req.ModuleId != nil {
|
|
|
|
|
moduleId = *req.ModuleId
|
|
|
|
|
}
|
2025-09-28 01:53:09 +00:00
|
|
|
return &entity.MasterMenus{
|
|
|
|
|
Name: req.Name,
|
|
|
|
|
Description: req.Description,
|
2026-01-18 19:58:10 +00:00
|
|
|
ModuleId: moduleId,
|
2025-09-28 01:53:09 +00:00
|
|
|
ParentMenuId: req.ParentMenuId,
|
|
|
|
|
Icon: req.Icon,
|
|
|
|
|
Group: req.Group,
|
|
|
|
|
StatusId: req.StatusId,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MasterMenusUpdateRequest struct {
|
|
|
|
|
ID uint `json:"id" validate:"required"`
|
|
|
|
|
Name string `json:"name" validate:"required"`
|
|
|
|
|
Description string `json:"description" validate:"required"`
|
2026-01-18 19:58:10 +00:00
|
|
|
ModuleId *int `json:"moduleId,omitempty"`
|
2025-09-28 01:53:09 +00:00
|
|
|
Group string `json:"group" validate:"required"`
|
|
|
|
|
StatusId int `json:"statusId" validate:"required"`
|
2026-01-18 19:58:10 +00:00
|
|
|
ParentMenuId *int `json:"parentMenuId,omitempty"`
|
|
|
|
|
Icon *string `json:"icon,omitempty"`
|
2025-09-28 01:53:09 +00:00
|
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (req MasterMenusUpdateRequest) ToEntity() *entity.MasterMenus {
|
2026-01-18 19:58:10 +00:00
|
|
|
moduleId := 0
|
|
|
|
|
if req.ModuleId != nil {
|
|
|
|
|
moduleId = *req.ModuleId
|
|
|
|
|
}
|
2025-09-28 01:53:09 +00:00
|
|
|
return &entity.MasterMenus{
|
|
|
|
|
ID: req.ID,
|
|
|
|
|
Name: req.Name,
|
|
|
|
|
Description: req.Description,
|
2026-01-18 19:58:10 +00:00
|
|
|
ModuleId: moduleId,
|
2025-09-28 01:53:09 +00:00
|
|
|
ParentMenuId: req.ParentMenuId,
|
|
|
|
|
Icon: req.Icon,
|
|
|
|
|
Group: req.Group,
|
|
|
|
|
StatusId: req.StatusId,
|
|
|
|
|
UpdatedAt: time.Now(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MasterMenusQueryRequestContext struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
ModuleId string `json:"moduleId"`
|
|
|
|
|
ParentMenuId string `json:"parentMenuId"`
|
|
|
|
|
StatusId string `json:"statusId"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (req MasterMenusQueryRequestContext) ToParamRequest() MasterMenusQueryRequest {
|
|
|
|
|
var request MasterMenusQueryRequest
|
|
|
|
|
|
|
|
|
|
if name := req.Name; name != "" {
|
|
|
|
|
request.Name = &name
|
|
|
|
|
}
|
|
|
|
|
if description := req.Description; description != "" {
|
|
|
|
|
request.Description = &description
|
|
|
|
|
}
|
|
|
|
|
if moduleIdStr := req.ModuleId; moduleIdStr != "" {
|
|
|
|
|
moduleId, err := strconv.Atoi(moduleIdStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
request.ModuleId = &moduleId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if parentMenuIdStr := req.ParentMenuId; parentMenuIdStr != "" {
|
|
|
|
|
parentMenuId, err := strconv.Atoi(parentMenuIdStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
request.ParentMenuId = &parentMenuId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if statusIdStr := req.StatusId; statusIdStr != "" {
|
|
|
|
|
statusId, err := strconv.Atoi(statusIdStr)
|
|
|
|
|
if err == nil {
|
|
|
|
|
request.StatusId = &statusId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return request
|
|
|
|
|
}
|