作者 tangxvhui

更新接口

... ... @@ -131,7 +131,8 @@ type (
type (
MiniGetArticleCommentRequest {
CommentId int64 `path:"commentId"`
CompanyId int64 `json:",optional"`
CompanyId int64 `path:",optional"`
UserId int64 `path:",optional"`
}
MiniGetArticleCommentResponse {
ArticleCommentAndReply
... ...
... ... @@ -26,6 +26,7 @@ func NewMiniArticleMarkUserReadLogic(ctx context.Context, svcCtx *svc.ServiceCon
}
}
// 记录人员浏览的文章
func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniArticleMarkUserReadRequest) (resp *types.MiniArticleMarkUserReadResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
... ...
... ... @@ -28,6 +28,7 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
// 创建新文章
func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
// 检查发布人
... ...
... ... @@ -26,6 +26,7 @@ func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi
}
}
// 小程序端展示文章内容
func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (resp *types.MiniArticleGetResponse, err error) {
// 获取文章内容
var conn = l.svcCtx.DefaultDBConn()
... ... @@ -88,10 +89,9 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
Title: articleInfo.Title,
AuthorId: articleInfo.AuthorId,
Author: types.ArticleAuthor{
Id: articleInfo.Author.Id,
Name: articleInfo.Author.Name,
Avatar: articleInfo.Author.Avatar,
// Group: articleInfo.Author.Group,
Id: articleInfo.Author.Id,
Name: articleInfo.Author.Name,
Avatar: articleInfo.Author.Avatar,
Position: articleInfo.Author.Position,
Company: articleInfo.Author.Company,
},
... ...
... ... @@ -49,7 +49,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
return nil, xerr.NewErrMsg("没有评论权限")
}
//查看评论权限,
//临时注释
//TODO 临时注释
// if len(articleInfo.WhoReview) > 0 {
// ok := lo.IndexOf(articleInfo.WhoReview, req.FromUserId)
// if ok < 0 {
... ...
... ... @@ -5,6 +5,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -23,8 +25,24 @@ func NewMiniDeleteArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCo
}
}
// 小程序端人人员删除评论
func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.MiniDeleteArticleCommentRequest) (resp *types.MiniDeleteArticleCommentResponse, err error) {
// todo: add your logic here and delete this line
var conn = l.svcCtx.DefaultDBConn()
commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
if err != nil {
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
}
if commetInfo.FromUserId != req.UserId {
return nil, xerr.NewErrMsg("没有操作权限")
}
return
commetInfo.Show = domain.CommentShowDisable
_, err = l.svcCtx.ArticleCommentRepository.Update(l.ctx, conn, commetInfo)
if err != nil {
return nil, xerr.NewErrMsgErr("删除评论信息失败", err)
}
resp = &types.MiniDeleteArticleCommentResponse{Id: commetInfo.Id}
return resp, nil
}
... ...
... ... @@ -25,6 +25,7 @@ func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceConte
}
}
// 获取单条评论详情
func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
//获取主评论
... ... @@ -42,7 +43,18 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
//TODO 获取我点赞的评论
queryOption = domain.NewQueryOptions().WithFindOnly().
MustWithKV("articleId", commentInfo.ArticleId).
MustWithKV("userId", req.UserId)
//TODO 获取我点赞的评论
_, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
flagMap := map[int64]struct{}{}
for _, val := range userFlagList {
flagMap[val.CommentId] = struct{}{}
}
//混合数据
commentResp := types.ArticleCommentItem{
... ... @@ -73,6 +85,10 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
CountAdminLove: commentInfo.CountAdminLove,
AtWho: []types.CommentAuthor{},
CreatedAt: commentInfo.CreatedAt,
MeLoveFlag: 0,
}
if _, ok := flagMap[commentInfo.Id]; ok {
commentResp.MeLoveFlag = 1
}
for _, val := range commentInfo.AtWho {
commentResp.AtWho = append(commentResp.AtWho, types.CommentAuthor{
... ... @@ -115,6 +131,9 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
CreatedAt: val.CreatedAt,
MeLoveFlag: 0,
}
if _, ok := flagMap[val.Id]; ok {
reply.MeLoveFlag = 1
}
for _, val2 := range val.AtWho {
reply.AtWho = append(reply.AtWho, types.CommentAuthor{
Id: val2.Id,
... ...
... ... @@ -83,7 +83,8 @@ type ArticleCommentItem struct {
type MiniGetArticleCommentRequest struct {
CommentId int64 `path:"commentId"`
CompanyId int64 `json:",optional"`
CompanyId int64 `path:",optional"`
UserId int64 `path:",optional"`
}
type MiniGetArticleCommentResponse struct {
... ...
... ... @@ -9,6 +9,7 @@ import (
"gorm.io/plugin/soft_delete"
)
// 文章的所有标签
type ArticleTag struct {
Id int64 `gorm:"primaryKey"` // 唯一标识
CompanyId int64
... ...
... ... @@ -40,6 +40,16 @@ const (
CommentShowDisable CommentShow = 1
)
func (show CommentShow) Named() string {
switch show {
case CommentShowEnable:
return "显示"
case CommentShowDisable:
return "隐藏"
}
return ""
}
type ArticleCommentRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error)
... ...