实现category service基础接口
This commit is contained in:
59
gateway/internal/logic/getcategorylogic.go
Normal file
59
gateway/internal/logic/getcategorylogic.go
Normal file
@ -0,0 +1,59 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"godemo/category/category"
|
||||
"godemo/gateway/internal/svc"
|
||||
"godemo/gateway/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetCategoryLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetCategoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCategoryLogic {
|
||||
return &GetCategoryLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetCategoryLogic) GetCategory(req *types.GetCategoryReq) (resp *types.CategoryDetailResp, err error) {
|
||||
rpcResp, err := l.svcCtx.CategoryRpc.GetCategory(l.ctx, &category.GetCategoryRequest{
|
||||
Id: req.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 转换主分类的时间
|
||||
createdAtStr := time.Unix(rpcResp.Category.CreatedAt, 0).Format(time.RFC3339)
|
||||
updatedAtStr := ""
|
||||
if rpcResp.Category.UpdatedAt != 0 {
|
||||
updatedAtStr = time.Unix(rpcResp.Category.UpdatedAt, 0).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
resp = &types.CategoryDetailResp{
|
||||
CategoryDetail: types.CategoryDetail{
|
||||
BaseCategory: types.BaseCategory{
|
||||
ID: rpcResp.Category.Id,
|
||||
Name: rpcResp.Category.Name,
|
||||
Alias: rpcResp.Category.Alias,
|
||||
Description: rpcResp.Category.Description,
|
||||
ParentID: rpcResp.Category.ParentId,
|
||||
SystemID: rpcResp.Category.SystemId,
|
||||
CreatedAt: createdAtStr,
|
||||
UpdatedAt: updatedAtStr,
|
||||
},
|
||||
Parent: nil,
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user