作者 tangxvhui

调试接口

... ... @@ -258,7 +258,7 @@ type (
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"` //
TopId int64 `json:"topId"` // 文章顶层ID
TopId int64 `json:"topId"` // 评论的顶层ID
FromUser string `json:"fromUser,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
... ... @@ -272,6 +272,9 @@ type (
}
SystemCommentItem {
Id int64 `json:"id"` //评论id
Pid int64 `json:"pid"` //
TopId int64 `json:"topId"` //
ArticleId int64 `json:"articleId"` //对应的文章id
ArticleTitle string `json:"articleTitle"` //文章标题
FromUserId int64 `json:"fromUserId"` //填写评论的人
FromUser CommentAuthor `json:"fromUser"` //填写评论的人
... ... @@ -293,6 +296,9 @@ type (
SystemGetCommentResponse {
Id int64 `json:"id"` //评论id
Pid int64 `json:"pid"` //
TopId int64 `json:"topId"` //
ArticleId int64 `json:"articleId"` //对应的文章id
ArticleTitle string `json:"articleTitle"` //文章标题
FromUserId int64 `json:"fromUserId"` //填写评论的人
FromUser CommentAuthor `json:"fromUser"` //填写评论的人
... ...
... ... @@ -16,7 +16,7 @@ func MiniSearchArticlePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniSearchArticleRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
package comment
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -14,7 +15,7 @@ func SystemArticleCommentSearchHandler(svcCtx *svc.ServiceContext) http.HandlerF
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleCommentSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
package comment
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -14,7 +15,7 @@ func SystemArticleCommentSearchMeHandler(svcCtx *svc.ServiceContext) http.Handle
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleCommentSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func SystemEditAticleCommentShowHandler(svcCtx *svc.ServiceContext) http.Handler
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemEditCommentShowRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func SystemGetAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemGetCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -15,7 +15,7 @@ func SystemListAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemListCommentRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
result.HttpResult(r, w, nil, err)
return
}
... ...
... ... @@ -35,8 +35,12 @@ func (l *SystemGetAticleCommentLogic) SystemGetAticleComment(req *types.SystemGe
return nil, xerr.NewErrMsg("没有查看权限")
}
resp = &types.SystemGetCommentResponse{
Id: commentInfo.Id,
FromUserId: commentInfo.FromUserId,
Id: commentInfo.Id,
Pid: commentInfo.Pid,
TopId: commentInfo.TopId,
ArticleId: commentInfo.ArticleId,
ArticleTitle: "",
FromUserId: commentInfo.FromUserId,
FromUser: types.CommentAuthor{
Id: commentInfo.FromUserId,
Name: commentInfo.FromUser.Name,
... ...
... ... @@ -29,10 +29,10 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
var conn = l.svcCtx.DefaultDBConn()
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size,
req.ArticleTitle, req.Content, req.FromUser, req.Show,
req.TopId, req.ArticleTitle, req.Content, req.FromUser, req.Show,
)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论详情失败", err)
return nil, xerr.NewErrMsgErr("获取评论列表失败", err)
}
resp = &types.SystemListCommentResponse{
... ... @@ -43,6 +43,8 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
for i, val := range commentList {
resp.List[i] = types.SystemCommentItem{
Id: val.Id,
Pid: val.Pid,
TopId: val.TopId,
ArticleTitle: val.ArticleTitle,
FromUserId: val.FromUserId,
FromUser: types.CommentAuthor{
... ...
... ... @@ -172,7 +172,7 @@ type SystemListCommentRequest struct {
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"` //
TopId int64 `json:"topId"` // 文章顶层ID
TopId int64 `json:"topId"` // 评论的顶层ID
FromUser string `json:"fromUser,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
... ... @@ -188,6 +188,9 @@ type SystemListCommentResponse struct {
type SystemCommentItem struct {
Id int64 `json:"id"` //评论id
Pid int64 `json:"pid"` //
TopId int64 `json:"topId"` //
ArticleId int64 `json:"articleId"` //对应的文章id
ArticleTitle string `json:"articleTitle"` //文章标题
FromUserId int64 `json:"fromUserId"` //填写评论的人
FromUser CommentAuthor `json:"fromUser"` //填写评论的人
... ... @@ -206,6 +209,9 @@ type SystemGetCommentRequest struct {
type SystemGetCommentResponse struct {
Id int64 `json:"id"` //评论id
Pid int64 `json:"pid"` //
TopId int64 `json:"topId"` //
ArticleId int64 `json:"articleId"` //对应的文章id
ArticleTitle string `json:"articleTitle"` //文章标题
FromUserId int64 `json:"fromUserId"` //填写评论的人
FromUser CommentAuthor `json:"fromUser"` //填写评论的人
... ...
... ... @@ -72,8 +72,10 @@ func (m *ArticleComment) CachePrimaryKeyFunc() string {
}
type ArticleCommentShow struct {
Id int64 //评论id
Pid int64
TopId int64
ArticleTitle string //文章标题
Id int64 //评论id
FromUserId int64 // 评论填写人的id
FromUser domain.UserSimple `gorm:"type:jsonb;serializer:json"`
Content string // 评论内容
... ...
... ... @@ -327,21 +327,8 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con
}
func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
articleTitle string, contentLike string, fromUserName string, show int) (int, []*domain.ArticleCommentShow, error) {
sqlStr := `select
article.title as article_title ,
article_comment.id ,
article_comment.from_user_id ,
article_comment.from_user,
article_comment."content" ,
article_comment.created_at ,
article_comment.count_reply ,
article_comment.count_user_love ,
article_comment.count_admin_love ,
article_comment."show"
from article_comment
join article on article.id = article_comment.article_id
where 1=1 `
topId int64, articleTitle string, contentLike string, fromUserName string, show int) (int, []*domain.ArticleCommentShow, error) {
if size <= 0 {
size = 20
}
... ... @@ -349,8 +336,8 @@ where 1=1 `
page = 1
}
where := ""
condition := []interface{}{}
where := " and article_comment.company_id=? "
condition := []interface{}{companyId}
if len(articleTitle) > 0 {
where += ` and article.title like ? `
... ... @@ -370,7 +357,15 @@ where 1=1 `
condition = append(condition, show)
}
countSql := sqlStr + where
if topId >= 0 {
where += ` and article_comment."top_id"= ? `
condition = append(condition, topId)
}
countSql := `select
count(*)
from article_comment
join article on article.id = article_comment.article_id
where 1=1 ` + where
var cnt int
db := conn.DB()
... ... @@ -379,7 +374,23 @@ where 1=1 `
return 0, nil, result.Error
}
dataSql := sqlStr + where + ` order by article_comment.id desc limit ? offset ? `
dataSql := `select
article.title as article_title ,
article_comment.id ,
article_comment.pid,
article_comment.top_id,
article_comment.from_user_id ,
article_comment.from_user,
article_comment."content" ,
article_comment.created_at ,
article_comment.count_reply ,
article_comment.count_user_love ,
article_comment.count_admin_love ,
article_comment."show"
from article_comment
join article on article.id = article_comment.article_id
where 1=1` + where + ` order by article_comment.id desc limit ? offset ? `
condition = append(condition, size, (page-1)*size)
ms := []models.ArticleCommentShow{}
... ... @@ -387,7 +398,6 @@ where 1=1 `
if result.Error != nil {
return 0, nil, result.Error
}
d := []*domain.ArticleCommentShow{}
for _, val := range ms {
d = append(d, &domain.ArticleCommentShow{
... ...
... ... @@ -51,8 +51,10 @@ func (show CommentShow) Named() string {
}
type ArticleCommentShow struct {
Id int64 // 评论id
Pid int64
TopId int64
ArticleTitle string // 文章标题
Id int64 // 评论id
FromUserId int64 // 评论填写人的id
FromUser UserSimple // 评论填写人
Content string // 评论内容
... ... @@ -75,5 +77,5 @@ type ArticleCommentRepository interface {
Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error)
// 特定的查询
CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
articleTitle string, contentLike string, fromUserName string, show int) (int, []*ArticleCommentShow, error)
topId int64, articleTitle string, contentLike string, fromUserName string, show int) (int, []*ArticleCommentShow, error)
}
... ...