package category

import (
	"context"

	v1 "server/api/category/v1"
	"server/internal/model"
	"server/internal/service"
)

func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
	// 调用service层获取分类列表
	result, err := service.Category().List(ctx, &model.CategoryListIn{
		Page:    req.Page,
		Size:    req.Size,
		Name:    req.Name,
		Channel: req.Channel,
	})
	if err != nil {
		return nil, err
	}

	// 构造响应
	res = &v1.ListRes{
		Total: result.Total,
		List:  result.List,
	}

	return res, nil
}
