mini_business_logic.go 1.4 KB
package message

import (
	"context"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"

	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"

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

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

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

func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) {
	queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
	total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), queryOptions)
	if err != nil {
		return nil, err
	}
	if err != nil {
		return nil, err
	}
	resp = &types.MessageBusinessResponse{}
	resp.Total = total
	resp.List = make([]types.MessageBusinessItem, 0)
	for _, item := range list {
		to := types.MessageBusinessItem{
			Id:   item.Id,
			Type: item.Type,
			//Title:     item.Title,
			Content:   item.Content,
			CreatedAt: item.CreatedAt,
		}
		resp.List = append(resp.List, to)
	}
	return resp, nil
}