作者 tangxuhui

添加gateway 收藏菜单模块

package allied_creation_user
import (
"encoding/json"
"fmt"
"strconv"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
)
// FavoriteMenusUpadate 更新我喜欢菜单列表
func (gateway HttplibAlliedCreationUser) FavoriteMenusUpadate(param ReqFavoriteMenusUpdate) (*DataFavoriteMenusUpdate, error) {
url := gateway.baseUrL + "/user/" + strconv.FormatInt(param.UserId, 10) + "/favorite-menus"
method := "put"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:更新我喜欢菜单列表。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求更新我喜欢菜单列表失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取更新我喜欢菜单列表失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:更新我喜欢菜单列表。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析更新我喜欢菜单列表:%w", err)
}
var data DataFavoriteMenusUpdate
err = gateway.GetResponseData(result, &data)
return &data, err
}
// FavoriteMenusRemove 移除我收藏的菜单
func (gateway HttplibAlliedCreationUser) FavoriteMenusRemove(param ReqFavoriteMenusRemove) (*DataFavoriteMenusRemove, error) {
url := gateway.baseUrL + "/user/" + strconv.FormatInt(param.UserId, 10) + "/favorite-menus/" + param.MenuCode
method := "delete"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:移除我收藏的菜单。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求移除我收藏的菜单失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取移除我收藏的菜单失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:移除我收藏的菜单。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析移除我收藏的菜单:%w", err)
}
var data DataFavoriteMenusRemove
err = gateway.GetResponseData(result, &data)
return &data, err
}
// FavoriteMenusGet 获取我收藏的菜单
func (gateway HttplibAlliedCreationUser) FavoriteMenusGet(param ReqFavoriteMenusGet) (*DataFavoriteMenusGet, error) {
url := gateway.baseUrL + "/user/" + strconv.FormatInt(param.UserId, 10) + "/favorite-menus"
method := "get"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向用户模块请求数据:获取我收藏的菜单。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求获取我收藏的菜单失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取获取我收藏的菜单失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:获取我收藏的菜单。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析获取我收藏的菜单:%w", err)
}
var data DataFavoriteMenusGet
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
package allied_creation_user
//更新我喜欢菜单列表
type (
ReqFavoriteMenusUpdate struct {
UserId int64
}
DataFavoriteMenusUpdate struct {
}
)
//移除我收藏的菜单
type (
ReqFavoriteMenusRemove struct {
UserId int64
MenuCode string
}
DataFavoriteMenusRemove struct {
}
)
//获取我收藏的菜单
type (
ReqFavoriteMenusGet struct {
UserId int64
}
DataFavoriteMenusGet struct {
}
)
... ...