Files
juwan-backend/app/shop/api/internal/logic/shop/helpers.go
T
zetaloop 198c761063 fix: 补全 ShopProfile 和 Post 响应中缺失的后端字段
ShopProfile 补上 allowMultiShop/allowIndependentOrders/dispatchMode,Post 补上 pinned/linkedOrderId。这些字段在 RPC proto、数据库和写入逻辑中均已存在,但 API 响应类型和映射函数遗漏了它们。同时补回 community.api 中 CreateCommentReq 的 PostId 字段定义。
2026-04-23 20:36:44 +08:00

69 lines
1.7 KiB
Go

package shop
import (
"context"
"encoding/json"
"strconv"
"juwan-backend/app/shop/api/internal/types"
"juwan-backend/app/shop/rpc/pb"
"juwan-backend/app/shop/rpc/shopservice"
)
func toShopProfile(in *pb.Shops) *types.ShopProfile {
if in == nil {
return nil
}
var template any
if in.TemplateConfig != "" {
_ = json.Unmarshal([]byte(in.TemplateConfig), &template)
}
if template == nil {
template = map[string]any{}
}
ownerID := strconv.FormatInt(in.OwnerId, 10)
return &types.ShopProfile{
Id: strconv.FormatInt(in.Id, 10),
Owner: types.UserProfile{
Id: ownerID,
Username: "",
Nickname: "",
Avatar: "",
Role: "owner",
VerifiedRoles: []string{"owner"},
VerificationStatus: map[string]string{},
CreatedAt: "",
},
Name: in.Name,
Banner: in.Banner,
Description: in.Description,
Rating: in.Rating,
TotalOrders: in.TotalOrders,
PlayerCount: in.PlayerCount,
CommissionType: in.CommissionType,
CommissionValue: in.CommissionValue,
AllowMultiShop: in.AllowMultiShop,
AllowIndependentOrders: in.AllowIndependentOrders,
DispatchMode: in.DispatchMode,
Announcements: in.Announcements,
TemplateConfig: template,
}
}
func getShopByOwnerID(ctx context.Context, rpc shopservice.ShopService, ownerID int64) (*pb.Shops, error) {
list, err := rpc.SearchShops(ctx, &pb.SearchShopsReq{
Offset: 0,
Limit: 1,
OwnerId: ownerID,
})
if err != nil {
return nil, err
}
if len(list.Shops) == 0 {
return nil, nil
}
return list.Shops[0], nil
}