package tag

import (
	"context"

	"bsm/full/module/social/feed/internal/models"
	pb "bsm/full/module/social/feed/pb"
	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/service"
)

// 标签列表
func List(ctx context.Context, in *pb.FetchRequest) (reply *pb.TagListReply, err error) {
	// parse authorization meta.
	_, err = service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}

	tags, cnt, err := models.TagsList()
	if err != nil {
		return nil, errcode.ErrDB
	}

	var res = &pb.TagListReply{Total: cnt}
	for _, v := range tags {
		res.Tags = append(res.Tags, &pb.TagItem{
			Key:     v.Key,
			Content: v.Content,
		})
	}
	return &pb.TagListReply{}, nil
}
