Skip to content

Commit

Permalink
feat(web): add category create with transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
Matrix-X committed Feb 15, 2025
1 parent ea16009 commit 79a1128
Show file tree
Hide file tree
Showing 20 changed files with 203 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .run/make goctl-powerx-apis.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="make goctl-powerx-apis" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile">
<makefile filename="$PROJECT_DIR$/Makefile" target="goctl-powerx-apis" workingDirectory="" arguments="">
<makefile filename="$PROJECT_DIR$/Makefile" target="goctl-powerx-apis" workingDirectory="$PROJECT_DIR$" arguments="">
<envs />
</makefile>
<method v="2" />
Expand Down
4 changes: 4 additions & 0 deletions api/admin/infoOrganization/category.api
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type (
Id int64 `json:"id,optional"`
PId int64 `json:"pId"`
Name string `json:"name"`
Scene string `json:"scene,optional"`
CustomerId int64 `json:"customerId,optional"`
Sort int `json:"sort"`
ViceName string `json:"viceName"`
Description string `json:"description"`
Expand All @@ -64,6 +66,8 @@ type (
ListCategoryTreeRequest {
CategoryPId int `form:"categoryPId,optional"`
NeedChildren bool `form:"needChildren,optional"`
Scene string `form:"scene,optional"`
CustomerId int64 `form:"customerId,optional"`
Names []string `form:"name,optional"`
OrderBy string `form:"orderBy,optional"`
}
Expand Down
134 changes: 67 additions & 67 deletions internal/handler/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package category

import (
customerDomain2 "PowerX/internal/model/crm/customerDomain"
"PowerX/internal/uc/powerx/crm/customerDomain"
"context"

"PowerX/internal/svc"
"PowerX/internal/types"

"github.com/zeromicro/go-zero/core/logx"
)

type CreateCategoryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}

func NewCreateCategoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCategoryLogic {
return &CreateCategoryLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}

func (l *CreateCategoryLogic) CreateCategory(req *types.CreateCategoryRequest) (resp *types.CreateCategoryReply, err error) {
vAuthCustomer := l.ctx.Value(customerDomain.AuthCustomerKey)
authCustomer := vAuthCustomer.(*customerDomain2.Customer)

// Web端创建用户的客户分类
category := TransformCategoryRequestToCategory(req)
category.CustomerId = authCustomer.Id
res, err := l.svcCtx.PowerX.Category.BaseRepository.Create(l.ctx, category)
if err != nil {
return nil, err
}
return &types.CreateCategoryReply{
Category: TransformCategoryToReplyForWeb(res),
}, nil
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package category

import (
"PowerX/internal/logic/admin/mediaResource"
"PowerX/internal/model/infoOrganization"
"context"

"PowerX/internal/svc"
Expand Down Expand Up @@ -40,28 +38,3 @@ func (l *GetCategoryLogic) GetCategory(req *types.GetCategoryRequest) (resp *typ
Category: categoryReply,
}, nil
}

func TransformCategoryToReplyForWeb(category *infoOrganizatoin.Category) *types.Category {

node := &types.Category{
Id: category.Id,
PId: category.PId,
Name: category.Name,
Sort: category.Sort,
ViceName: category.ViceName,
Description: category.Description,
CreatedAt: category.CreatedAt.String(),
CoverImage: mediaResource.TransformMediaResourceToReply(category.CoverImage),
ImageAbleInfo: types.ImageAbleInfo{
Icon: category.Icon,
BackgroundColor: category.BackgroundColor,
},
Children: nil,
}
if len(category.Children) > 0 {
node.Children = TransformCategoriesToReplyForWeb(category.Children)

}

return node
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package category

import (
"PowerX/internal/logic/admin/infoOrganization/category"
"PowerX/internal/model/infoOrganization"
"PowerX/internal/uc/powerx/crm/infoOrganization"
"context"

Expand Down Expand Up @@ -42,22 +41,3 @@ func (l *ListCategoryTreeLogic) ListCategoryTree(req *types.ListCategoryTreeRequ
ProductCategories: productCategoryReplyList,
}, nil
}

func TransformCategoriesToReplyForWeb(productCategoryList []*infoOrganizatoin.Category) []*types.Category {
uniqueIds := make(map[int64]bool)
var productCategoryReplyList []*types.Category
for _, category := range productCategoryList {
if !uniqueIds[category.Id] {
node := TransformCategoryToReplyForWeb(category)
if len(category.Children) > 0 {
node.Children = TransformCategoriesToReplyForWeb(category.Children)
}

productCategoryReplyList = append(productCategoryReplyList, node)
uniqueIds[category.Id] = true

}
}

return productCategoryReplyList
}
Loading

0 comments on commit 79a1128

Please sign in to comment.