package post

import (
	"context"

	"bsm/full/module/base/cms/internal/impl"
	"bsm/full/module/base/cms/internal/models"
	"git.apinb.com/bsm-sdk/core/errcode"
	"git.apinb.com/bsm-sdk/core/service"
	"git.apinb.com/bsm-sdk/core/types"

	pb "bsm/full/module/base/cms/pb"
)

// 修改评论
func ModifyComment(ctx context.Context, in *pb.CommentItem) (*pb.StatusReply, error) {
	_, err := service.ParseMetaCtx(ctx, nil)
	if err != nil {
		return nil, err
	}
	if in.GetIdentity() == "" {
		return nil, errcode.ErrInvalidArgument
	}

	var data = models.CmsComment{
		Std_Identity:  types.Std_Identity{Identity: in.Identity},
		PostIdentity:  in.PostIdentity,
		ParentId:      uint(in.ParentId),
		ReplyIdentity: in.ReplyIdentity,
		Cms:           in.Cms,
	}
	// err = logic.ModifyComment(&data)
	if err := impl.DBService.Where("identity = ?", data.Identity).Updates(data).Error; err != nil {
		return nil, err
	}
	return &pb.StatusReply{}, nil
}
