51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
|
|
// Package post 提供文章相关的业务逻辑处理
|
|||
|
|
// 包括文章的创建、修改、删除、查询、点赞等功能
|
|||
|
|
package post
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"context"
|
|||
|
|
"time"
|
|||
|
|
|
|||
|
|
"git.apinb.com/bsm-apps/cms/internal/models"
|
|||
|
|
pb "git.apinb.com/bsm-apps/cms/pb"
|
|||
|
|
"git.apinb.com/bsm-sdk/core/errcode"
|
|||
|
|
"git.apinb.com/bsm-sdk/core/printer"
|
|||
|
|
"git.apinb.com/bsm-sdk/core/service"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// IncrPostLike 增加文章点赞数
|
|||
|
|
// 验证用户身份后,增加指定文章的点赞计数
|
|||
|
|
// 参数:
|
|||
|
|
// - ctx: 请求上下文,包含用户身份信息
|
|||
|
|
// - in: 操作请求,包含操作ID和文章ID
|
|||
|
|
//
|
|||
|
|
// 返回:
|
|||
|
|
// - *pb.StatusReply: 操作结果
|
|||
|
|
// - error: 错误信息
|
|||
|
|
func IncrPostLike(ctx context.Context, in *pb.PostOpIdentityRequest) (*pb.StatusReply, error) {
|
|||
|
|
// 解析请求上下文,验证用户身份
|
|||
|
|
_, err := service.ParseMetaCtx(ctx, nil)
|
|||
|
|
if err != nil {
|
|||
|
|
return nil, err
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 验证必填参数
|
|||
|
|
if in.GetOpIdentity() == "" || in.GetPostIdentity() == "" {
|
|||
|
|
return nil, errcode.ErrInvalidArgument
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 增加文章点赞数
|
|||
|
|
err = models.IncrOrDescPostField(in.PostIdentity, "like_hits", false)
|
|||
|
|
if err != nil {
|
|||
|
|
printer.Error(err.Error())
|
|||
|
|
return nil, errcode.ErrDB
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 返回成功响应
|
|||
|
|
return &pb.StatusReply{
|
|||
|
|
Code: 0,
|
|||
|
|
Message: "OK",
|
|||
|
|
Timeseq: time.Now().Unix(),
|
|||
|
|
}, nil
|
|||
|
|
}
|