get_app_page_logic.go 1.4 KB
package page

import (
	"context"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"

	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"

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

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

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

func (l *GetAppPageLogic) GetAppPage(req *types.AppPageGetRequest) (resp *types.AppPageGetResponse, err error) {
	var (
		conn     = l.svcCtx.DefaultDBConn()
		appPage  *domain.AppPage
		charts   []*domain.Chart
		tenantId = contextdata.GetTenantFromCtx(l.ctx)
	)
	if appPage, err = l.svcCtx.AppPageRepository.FindOne(l.ctx, conn, req.Id); err != nil {
		return nil, xerr.NewErr(err)
	}
	queryOptions := domain.IndexTenantId(tenantId)().WithKV("ids", appPage.Charts)
	if _, charts, err = l.svcCtx.ChartRepository.Find(l.ctx, conn, queryOptions); err != nil {
		return nil, xerr.NewErr(err)
	}
	resp = &types.AppPageGetResponse{
		AppPage: types.NewAppPageItem(appPage, charts),
	}
	return
}