// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package post

import (
	"context"

	"sundynix-micro-go/app/plant/api/internal/svc"
	"sundynix-micro-go/app/plant/api/internal/types"
	"sundynix-micro-go/app/plant/rpc/plant"

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

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

// 帖子列表
func NewGetPostListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPostListLogic {
	return &GetPostListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetPostListLogic) GetPostList(req *types.PostListReq) (interface{}, error) {
	result, err := l.svcCtx.PlantRpc.GetPostList(l.ctx, &plant.PostListReq{
		Current:  int32(req.Current),
		PageSize: int32(req.PageSize),
		Keyword:  req.Keyword,
		TopicId:  req.TopicId,
	})
	if err != nil {
		return nil, err
	}
	return map[string]interface{}{"list": result.List, "total": result.Total}, nil
}
