mirror of https://gitee.com/answerdev/answer.git
fix question last edit userid
This commit is contained in:
parent
7b6901e642
commit
d4b1a5b4e5
56
docs/docs.go
56
docs/docs.go
|
@ -1294,7 +1294,7 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/answer/api/v1/answer/list": {
|
||||
"/answer/api/v1/answer/page": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
|
@ -1314,13 +1314,32 @@ const docTemplate = `{
|
|||
"summary": "AnswerList",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "AnswerListReq",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.AnswerListReq"
|
||||
}
|
||||
"type": "string",
|
||||
"description": "question_id",
|
||||
"name": "question_id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "order",
|
||||
"name": "order",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "page",
|
||||
"name": "page",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "page_size",
|
||||
"name": "page_size",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
@ -4875,27 +4894,6 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerListReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"order": {
|
||||
"description": "1 Default 2 time",
|
||||
"type": "string"
|
||||
},
|
||||
"page": {
|
||||
"description": "Query number of pages",
|
||||
"type": "integer"
|
||||
},
|
||||
"page_size": {
|
||||
"description": "Search page size",
|
||||
"type": "integer"
|
||||
},
|
||||
"question_id": {
|
||||
"description": "question_id",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerUpdateReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -1282,7 +1282,7 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/answer/api/v1/answer/list": {
|
||||
"/answer/api/v1/answer/page": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
|
@ -1302,13 +1302,32 @@
|
|||
"summary": "AnswerList",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "AnswerListReq",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.AnswerListReq"
|
||||
}
|
||||
"type": "string",
|
||||
"description": "question_id",
|
||||
"name": "question_id",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "order",
|
||||
"name": "order",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "page",
|
||||
"name": "page",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "page_size",
|
||||
"name": "page_size",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
@ -4863,27 +4882,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerListReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"order": {
|
||||
"description": "1 Default 2 time",
|
||||
"type": "string"
|
||||
},
|
||||
"page": {
|
||||
"description": "Query number of pages",
|
||||
"type": "integer"
|
||||
},
|
||||
"page_size": {
|
||||
"description": "Search page size",
|
||||
"type": "integer"
|
||||
},
|
||||
"question_id": {
|
||||
"description": "question_id",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.AnswerUpdateReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -206,21 +206,6 @@ definitions:
|
|||
description: question_id
|
||||
type: string
|
||||
type: object
|
||||
schema.AnswerListReq:
|
||||
properties:
|
||||
order:
|
||||
description: 1 Default 2 time
|
||||
type: string
|
||||
page:
|
||||
description: Query number of pages
|
||||
type: integer
|
||||
page_size:
|
||||
description: Search page size
|
||||
type: integer
|
||||
question_id:
|
||||
description: question_id
|
||||
type: string
|
||||
type: object
|
||||
schema.AnswerUpdateReq:
|
||||
properties:
|
||||
content:
|
||||
|
@ -2462,18 +2447,32 @@ paths:
|
|||
summary: Get Answer
|
||||
tags:
|
||||
- api-answer
|
||||
/answer/api/v1/answer/list:
|
||||
/answer/api/v1/answer/page:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: AnswerList <br> <b>order</b> (default or updated)
|
||||
parameters:
|
||||
- description: AnswerListReq
|
||||
in: body
|
||||
name: data
|
||||
- description: question_id
|
||||
in: query
|
||||
name: question_id
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/schema.AnswerListReq'
|
||||
type: string
|
||||
- description: order
|
||||
in: query
|
||||
name: order
|
||||
required: true
|
||||
type: string
|
||||
- description: page
|
||||
in: query
|
||||
name: page
|
||||
required: true
|
||||
type: string
|
||||
- description: page_size
|
||||
in: query
|
||||
name: page_size
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
|
|
|
@ -203,14 +203,18 @@ func (ac *AnswerController) Update(ctx *gin.Context) {
|
|||
// @Security ApiKeyAuth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param data body schema.AnswerListReq true "AnswerListReq"
|
||||
// @Param question_id query string true "question_id"
|
||||
// @Param order query string true "order"
|
||||
// @Param page query string true "page"
|
||||
// @Param page_size query string true "page_size"
|
||||
// @Success 200 {string} string ""
|
||||
// @Router /answer/api/v1/answer/list [get]
|
||||
// @Router /answer/api/v1/answer/page [get]
|
||||
func (ac *AnswerController) AnswerList(ctx *gin.Context) {
|
||||
req := &schema.AnswerListReq{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
}
|
||||
|
||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||
|
||||
canList, err := ac.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||
|
|
|
@ -230,7 +230,7 @@ func (qr *questionRepo) SearchList(ctx context.Context, search *schema.QuestionS
|
|||
session = session.OrderBy("question.created_at desc")
|
||||
}
|
||||
session = session.Limit(search.PageSize, offset)
|
||||
session = session.Select("question.id,question.user_id,question.title,question.original_text,question.parsed_text,question.status,question.view_count,question.unique_view_count,question.vote_count,question.answer_count,question.collection_count,question.follow_count,question.accepted_answer_id,question.last_answer_id,question.created_at,question.updated_at,question.post_update_time,question.revision_id")
|
||||
session = session.Select("question.id,question.user_id,last_edit_user_id,question.title,question.original_text,question.parsed_text,question.status,question.view_count,question.unique_view_count,question.vote_count,question.answer_count,question.collection_count,question.follow_count,question.accepted_answer_id,question.last_answer_id,question.created_at,question.updated_at,question.post_update_time,question.revision_id")
|
||||
count, err = session.FindAndCount(&rows)
|
||||
if err != nil {
|
||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
|
|
|
@ -249,7 +249,7 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
|
|||
if !canUpdate {
|
||||
revisionDTO.Status = entity.RevisionUnreviewedStatus
|
||||
} else {
|
||||
if err = as.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "update_time"}); err != nil {
|
||||
if err = as.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "update_time", "last_edit_user_id"}); err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = as.questionCommon.UpdataPostTime(ctx, req.QuestionID)
|
||||
|
@ -370,13 +370,22 @@ func (as *AnswerService) Get(ctx context.Context, answerID, loginUserID string)
|
|||
return nil, nil, has, err
|
||||
}
|
||||
// todo UserFunc
|
||||
userinfo, has, err := as.userCommon.GetUserBasicInfoByID(ctx, answerInfo.UserID)
|
||||
|
||||
userIds := make([]string, 0)
|
||||
userIds = append(userIds, answerInfo.UserID)
|
||||
userIds = append(userIds, answerInfo.LastEditUserID)
|
||||
userInfoMap, err := as.userCommon.BatchUserBasicInfoByID(ctx, userIds)
|
||||
if err != nil {
|
||||
return nil, nil, has, err
|
||||
}
|
||||
if has {
|
||||
info.UserInfo = userinfo
|
||||
info.UpdateUserInfo = userinfo
|
||||
|
||||
_, ok := userInfoMap[answerInfo.UserID]
|
||||
if ok {
|
||||
info.UserInfo = userInfoMap[answerInfo.UserID]
|
||||
}
|
||||
_, ok = userInfoMap[answerInfo.LastEditUserID]
|
||||
if ok {
|
||||
info.UpdateUserInfo = userInfoMap[answerInfo.LastEditUserID]
|
||||
}
|
||||
|
||||
if loginUserID == "" {
|
||||
|
@ -389,7 +398,7 @@ func (as *AnswerService) Get(ctx context.Context, answerID, loginUserID string)
|
|||
if err != nil {
|
||||
log.Error("CollectionFunc.SearchObjectCollected error", err)
|
||||
}
|
||||
_, ok := CollectedMap[answerInfo.ID]
|
||||
_, ok = CollectedMap[answerInfo.ID]
|
||||
if ok {
|
||||
info.Collected = true
|
||||
}
|
||||
|
|
|
@ -184,14 +184,26 @@ func (qs *QuestionCommon) Info(ctx context.Context, questionID string, loginUser
|
|||
}
|
||||
showinfo.Tags = tagmap
|
||||
|
||||
userinfo, has, err := qs.userCommon.GetUserBasicInfoByID(ctx, dbinfo.UserID)
|
||||
userIds := make([]string, 0)
|
||||
userIds = append(userIds, dbinfo.UserID)
|
||||
userIds = append(userIds, dbinfo.LastEditUserID)
|
||||
userIds = append(userIds, showinfo.LastAnsweredUserID)
|
||||
userInfoMap, err := qs.userCommon.BatchUserBasicInfoByID(ctx, userIds)
|
||||
if err != nil {
|
||||
return showinfo, err
|
||||
}
|
||||
if has {
|
||||
showinfo.UserInfo = userinfo
|
||||
showinfo.UpdateUserInfo = userinfo
|
||||
showinfo.LastAnsweredUserInfo = userinfo
|
||||
|
||||
_, ok := userInfoMap[dbinfo.UserID]
|
||||
if ok {
|
||||
showinfo.UserInfo = userInfoMap[dbinfo.UserID]
|
||||
}
|
||||
_, ok = userInfoMap[dbinfo.LastEditUserID]
|
||||
if ok {
|
||||
showinfo.UpdateUserInfo = userInfoMap[dbinfo.LastEditUserID]
|
||||
}
|
||||
_, ok = userInfoMap[showinfo.LastAnsweredUserID]
|
||||
if ok {
|
||||
showinfo.LastAnsweredUserInfo = userInfoMap[showinfo.LastAnsweredUserID]
|
||||
}
|
||||
|
||||
if loginUserID == "" {
|
||||
|
@ -216,7 +228,7 @@ func (qs *QuestionCommon) Info(ctx context.Context, questionID string, loginUser
|
|||
if err != nil {
|
||||
log.Error("CollectionFunc.SearchObjectCollected", err)
|
||||
}
|
||||
_, ok := CollectedMap[dbinfo.ID]
|
||||
_, ok = CollectedMap[dbinfo.ID]
|
||||
if ok {
|
||||
showinfo.Collected = true
|
||||
}
|
||||
|
@ -233,10 +245,9 @@ func (qs *QuestionCommon) ListFormat(ctx context.Context, questionList []*entity
|
|||
item := qs.ShowListFormat(ctx, questionInfo)
|
||||
list = append(list, item)
|
||||
objectIds = append(objectIds, item.ID)
|
||||
userIds = append(userIds, questionInfo.UserID)
|
||||
userIds = append(userIds, questionInfo.LastEditUserID)
|
||||
userIds = append(userIds, item.UserID)
|
||||
userIds = append(userIds, item.LastEditUserID)
|
||||
userIds = append(userIds, item.LastAnsweredUserID)
|
||||
|
||||
}
|
||||
tagsMap, err := qs.tagCommon.BatchGetObjectTag(ctx, objectIds)
|
||||
if err != nil {
|
||||
|
@ -256,11 +267,10 @@ func (qs *QuestionCommon) ListFormat(ctx context.Context, questionList []*entity
|
|||
_, ok = userInfoMap[item.UserID]
|
||||
if ok {
|
||||
item.UserInfo = userInfoMap[item.UserID]
|
||||
item.UpdateUserInfo = userInfoMap[item.UserID]
|
||||
}
|
||||
_, ok = userInfoMap[item.LastEditUserID]
|
||||
if ok {
|
||||
item.UpdateUserInfo = userInfoMap[item.UserID]
|
||||
item.UpdateUserInfo = userInfoMap[item.LastEditUserID]
|
||||
}
|
||||
_, ok = userInfoMap[item.LastAnsweredUserID]
|
||||
if ok {
|
||||
|
|
Loading…
Reference in New Issue