get_chart_logic.go 1.3 KB
package chart

import (
	"context"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
	"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 GetChartLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

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

func (l *GetChartLogic) GetChart(req *types.ChartGetRequest) (resp *types.ChartGetResponse, err error) {
	var (
		conn         = l.svcCtx.DefaultDBConn()
		chart        *domain.Chart
		chartSetting *domain.ChartSetting
	)
	chart, err = l.svcCtx.ChartRepository.FindOne(l.ctx, conn, req.Id)
	if err != nil {
		return nil, xerr.NewErrMsgErr("图表不存在", err)
	}
	chartSetting, err = l.svcCtx.ChartSettingRepository.FindOne(l.ctx, conn, req.Id)
	if err != nil {
		return nil, xerr.NewErrMsgErr("图表配置不存在", err)
	}
	resp = &types.ChartGetResponse{
		Chart: types.NewChartItemWithSetting(chart, chartSetting),
	}
	return
}