64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"errors"
|
|
"fusenapi/utils/auth"
|
|
"fusenapi/utils/basic"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"context"
|
|
|
|
"fusenapi/server/ldap-admin/internal/svc"
|
|
"fusenapi/server/ldap-admin/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetMenuDetailLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetMenuDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuDetailLogic {
|
|
return &GetMenuDetailLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
// 处理进入前逻辑w,r
|
|
// func (l *GetMenuDetailLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
|
// }
|
|
|
|
func (l *GetMenuDetailLogic) GetMenuDetail(req *types.GetMenuDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
if req.Id <= 0 {
|
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "参数id无效")
|
|
}
|
|
menu, err := l.svcCtx.AllModels.LdapMenus.FindOne(l.ctx, req.Id)
|
|
if err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "该菜单信息不存在")
|
|
}
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "查询菜单详情失败")
|
|
}
|
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetMenuDetailRsp{
|
|
Id: menu.Id,
|
|
Name: *menu.Name,
|
|
Title: *menu.Title,
|
|
Icon: *menu.Icon,
|
|
Path: *menu.Path,
|
|
Sort: *menu.Sort,
|
|
ParentId: *menu.ParentId,
|
|
Status: *menu.Status,
|
|
})
|
|
}
|
|
|
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
|
// func (l *GetMenuDetailLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
|
// }
|