delete_app_page_logic.go 1.5 KB
package page

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

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

func (l *DeleteAppPageLogic) DeleteAppPage(req *types.AppPageDeleteRequest) (resp *types.AppPageDeleteResponse, err error) {
	var (
		conn    = l.svcCtx.DefaultDBConn()
		appPage *domain.AppPage
	)
	if appPage, err = l.svcCtx.AppPageRepository.FindOne(l.ctx, conn, req.Id); err != nil {
		return nil, xerr.NewErr(err)
	}
	resp = &types.AppPageDeleteResponse{}
	if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
		if appPage, err = l.svcCtx.AppPageRepository.Delete(l.ctx, conn, appPage); err != nil {
			return err
		}
		return nil
	}, true); err != nil {
		return nil, xerr.NewErrMsgErr("删除页面失败", err)
	}

	return
}