mirror of https://gitee.com/answerdev/answer.git
Merge branch 'fix/1.1.0/personal-page' into test
This commit is contained in:
commit
e45a5f151f
28
docs/docs.go
28
docs/docs.go
|
@ -2517,7 +2517,7 @@ const docTemplate = `{
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "UserAnswerList",
|
"description": "list personal answers",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
@ -2525,9 +2525,9 @@ const docTemplate = `{
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"api-answer"
|
"Personal"
|
||||||
],
|
],
|
||||||
"summary": "UserAnswerList",
|
"summary": "list personal answers",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -2559,8 +2559,8 @@ const docTemplate = `{
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "20",
|
"default": "20",
|
||||||
"description": "pagesize",
|
"description": "page_size",
|
||||||
"name": "pagesize",
|
"name": "page_size",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
|
@ -2582,7 +2582,7 @@ const docTemplate = `{
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "UserCollectionList",
|
"description": "list personal collections",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
@ -2592,7 +2592,7 @@ const docTemplate = `{
|
||||||
"tags": [
|
"tags": [
|
||||||
"Collection"
|
"Collection"
|
||||||
],
|
],
|
||||||
"summary": "UserCollectionList",
|
"summary": "list personal collections",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -2605,8 +2605,8 @@ const docTemplate = `{
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "20",
|
"default": "20",
|
||||||
"description": "pagesize",
|
"description": "page_size",
|
||||||
"name": "pagesize",
|
"name": "page_size",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
|
@ -5324,7 +5324,7 @@ const docTemplate = `{
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "UserList",
|
"description": "list personal questions",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
@ -5332,9 +5332,9 @@ const docTemplate = `{
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Question"
|
"Personal"
|
||||||
],
|
],
|
||||||
"summary": "UserList",
|
"summary": "list personal questions",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -5366,8 +5366,8 @@ const docTemplate = `{
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "20",
|
"default": "20",
|
||||||
"description": "pagesize",
|
"description": "page_size",
|
||||||
"name": "pagesize",
|
"name": "page_size",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -2505,7 +2505,7 @@
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "UserAnswerList",
|
"description": "list personal answers",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
@ -2513,9 +2513,9 @@
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"api-answer"
|
"Personal"
|
||||||
],
|
],
|
||||||
"summary": "UserAnswerList",
|
"summary": "list personal answers",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -2547,8 +2547,8 @@
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "20",
|
"default": "20",
|
||||||
"description": "pagesize",
|
"description": "page_size",
|
||||||
"name": "pagesize",
|
"name": "page_size",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
|
@ -2570,7 +2570,7 @@
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "UserCollectionList",
|
"description": "list personal collections",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
@ -2580,7 +2580,7 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"Collection"
|
"Collection"
|
||||||
],
|
],
|
||||||
"summary": "UserCollectionList",
|
"summary": "list personal collections",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -2593,8 +2593,8 @@
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "20",
|
"default": "20",
|
||||||
"description": "pagesize",
|
"description": "page_size",
|
||||||
"name": "pagesize",
|
"name": "page_size",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
|
@ -5312,7 +5312,7 @@
|
||||||
"ApiKeyAuth": []
|
"ApiKeyAuth": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "UserList",
|
"description": "list personal questions",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
|
@ -5320,9 +5320,9 @@
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Question"
|
"Personal"
|
||||||
],
|
],
|
||||||
"summary": "UserList",
|
"summary": "list personal questions",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -5354,8 +5354,8 @@
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "20",
|
"default": "20",
|
||||||
"description": "pagesize",
|
"description": "page_size",
|
||||||
"name": "pagesize",
|
"name": "page_size",
|
||||||
"in": "query",
|
"in": "query",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -3509,7 +3509,7 @@ paths:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: UserAnswerList
|
description: list personal answers
|
||||||
parameters:
|
parameters:
|
||||||
- default: string
|
- default: string
|
||||||
description: username
|
description: username
|
||||||
|
@ -3532,9 +3532,9 @@ paths:
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
- default: "20"
|
- default: "20"
|
||||||
description: pagesize
|
description: page_size
|
||||||
in: query
|
in: query
|
||||||
name: pagesize
|
name: page_size
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
produces:
|
produces:
|
||||||
|
@ -3546,14 +3546,14 @@ paths:
|
||||||
$ref: '#/definitions/handler.RespBody'
|
$ref: '#/definitions/handler.RespBody'
|
||||||
security:
|
security:
|
||||||
- ApiKeyAuth: []
|
- ApiKeyAuth: []
|
||||||
summary: UserAnswerList
|
summary: list personal answers
|
||||||
tags:
|
tags:
|
||||||
- api-answer
|
- Personal
|
||||||
/answer/api/v1/personal/collection/page:
|
/answer/api/v1/personal/collection/page:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: UserCollectionList
|
description: list personal collections
|
||||||
parameters:
|
parameters:
|
||||||
- default: "0"
|
- default: "0"
|
||||||
description: page
|
description: page
|
||||||
|
@ -3562,9 +3562,9 @@ paths:
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
- default: "20"
|
- default: "20"
|
||||||
description: pagesize
|
description: page_size
|
||||||
in: query
|
in: query
|
||||||
name: pagesize
|
name: page_size
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
produces:
|
produces:
|
||||||
|
@ -3576,7 +3576,7 @@ paths:
|
||||||
$ref: '#/definitions/handler.RespBody'
|
$ref: '#/definitions/handler.RespBody'
|
||||||
security:
|
security:
|
||||||
- ApiKeyAuth: []
|
- ApiKeyAuth: []
|
||||||
summary: UserCollectionList
|
summary: list personal collections
|
||||||
tags:
|
tags:
|
||||||
- Collection
|
- Collection
|
||||||
/answer/api/v1/personal/comment/page:
|
/answer/api/v1/personal/comment/page:
|
||||||
|
@ -5210,7 +5210,7 @@ paths:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: UserList
|
description: list personal questions
|
||||||
parameters:
|
parameters:
|
||||||
- default: string
|
- default: string
|
||||||
description: username
|
description: username
|
||||||
|
@ -5233,9 +5233,9 @@ paths:
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
- default: "20"
|
- default: "20"
|
||||||
description: pagesize
|
description: page_size
|
||||||
in: query
|
in: query
|
||||||
name: pagesize
|
name: page_size
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
produces:
|
produces:
|
||||||
|
@ -5247,9 +5247,9 @@ paths:
|
||||||
$ref: '#/definitions/handler.RespBody'
|
$ref: '#/definitions/handler.RespBody'
|
||||||
security:
|
security:
|
||||||
- ApiKeyAuth: []
|
- ApiKeyAuth: []
|
||||||
summary: UserList
|
summary: list personal questions
|
||||||
tags:
|
tags:
|
||||||
- Question
|
- Personal
|
||||||
/robots.txt:
|
/robots.txt:
|
||||||
get:
|
get:
|
||||||
description: get site robots information
|
description: get site robots information
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/answerdev/answer/internal/service"
|
"github.com/answerdev/answer/internal/service"
|
||||||
"github.com/answerdev/answer/internal/service/permission"
|
"github.com/answerdev/answer/internal/service/permission"
|
||||||
"github.com/answerdev/answer/internal/service/rank"
|
"github.com/answerdev/answer/internal/service/rank"
|
||||||
"github.com/answerdev/answer/pkg/converter"
|
|
||||||
"github.com/answerdev/answer/pkg/uid"
|
"github.com/answerdev/answer/pkg/uid"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
|
@ -552,84 +551,75 @@ func (qc *QuestionController) UserTop(ctx *gin.Context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserList godoc
|
// PersonalQuestionPage list personal questions
|
||||||
// @Summary UserList
|
// @Summary list personal questions
|
||||||
// @Description UserList
|
// @Description list personal questions
|
||||||
// @Tags Question
|
// @Tags Personal
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security ApiKeyAuth
|
// @Security ApiKeyAuth
|
||||||
// @Param username query string true "username" default(string)
|
// @Param username query string true "username" default(string)
|
||||||
// @Param order query string true "order" Enums(newest,score)
|
// @Param order query string true "order" Enums(newest,score)
|
||||||
// @Param page query string true "page" default(0)
|
// @Param page query string true "page" default(0)
|
||||||
// @Param pagesize query string true "pagesize" default(20)
|
// @Param page_size query string true "page_size" default(20)
|
||||||
// @Success 200 {object} handler.RespBody
|
// @Success 200 {object} handler.RespBody
|
||||||
// @Router /personal/question/page [get]
|
// @Router /personal/question/page [get]
|
||||||
func (qc *QuestionController) UserList(ctx *gin.Context) {
|
func (qc *QuestionController) PersonalQuestionPage(ctx *gin.Context) {
|
||||||
userName := ctx.Query("username")
|
req := &schema.PersonalQuestionPageReq{}
|
||||||
order := ctx.Query("order")
|
if handler.BindAndCheck(ctx, req) {
|
||||||
pageStr := ctx.Query("page")
|
return
|
||||||
pageSizeStr := ctx.Query("pagesize")
|
}
|
||||||
page := converter.StringToInt(pageStr)
|
|
||||||
pageSize := converter.StringToInt(pageSizeStr)
|
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
resp, err := qc.questionService.PersonalQuestionPage(ctx, req)
|
||||||
questionList, count, err := qc.questionService.SearchUserList(ctx, userName, order, page, pageSize, userID)
|
handler.HandleResponse(ctx, err, resp)
|
||||||
handler.HandleResponse(ctx, err, gin.H{
|
|
||||||
"list": questionList,
|
|
||||||
"count": count,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserAnswerList godoc
|
// PersonalAnswerPage list personal answers
|
||||||
// @Summary UserAnswerList
|
// @Summary list personal answers
|
||||||
// @Description UserAnswerList
|
// @Description list personal answers
|
||||||
// @Tags api-answer
|
// @Tags Personal
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security ApiKeyAuth
|
// @Security ApiKeyAuth
|
||||||
// @Param username query string true "username" default(string)
|
// @Param username query string true "username" default(string)
|
||||||
// @Param order query string true "order" Enums(newest,score)
|
// @Param order query string true "order" Enums(newest,score)
|
||||||
// @Param page query string true "page" default(0)
|
// @Param page query string true "page" default(0)
|
||||||
// @Param pagesize query string true "pagesize" default(20)
|
// @Param page_size query string true "page_size" default(20)
|
||||||
// @Success 200 {object} handler.RespBody
|
// @Success 200 {object} handler.RespBody
|
||||||
// @Router /answer/api/v1/personal/answer/page [get]
|
// @Router /answer/api/v1/personal/answer/page [get]
|
||||||
func (qc *QuestionController) UserAnswerList(ctx *gin.Context) {
|
func (qc *QuestionController) PersonalAnswerPage(ctx *gin.Context) {
|
||||||
userName := ctx.Query("username")
|
req := &schema.PersonalAnswerPageReq{}
|
||||||
order := ctx.Query("order")
|
if handler.BindAndCheck(ctx, req) {
|
||||||
pageStr := ctx.Query("page")
|
return
|
||||||
pageSizeStr := ctx.Query("pagesize")
|
}
|
||||||
page := converter.StringToInt(pageStr)
|
|
||||||
pageSize := converter.StringToInt(pageSizeStr)
|
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
resp, err := qc.questionService.PersonalAnswerPage(ctx, req)
|
||||||
questionList, count, err := qc.questionService.SearchUserAnswerList(ctx, userName, order, page, pageSize, userID)
|
handler.HandleResponse(ctx, err, resp)
|
||||||
handler.HandleResponse(ctx, err, gin.H{
|
|
||||||
"list": questionList,
|
|
||||||
"count": count,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserCollectionList godoc
|
// PersonalCollectionPage list personal collections
|
||||||
// @Summary UserCollectionList
|
// @Summary list personal collections
|
||||||
// @Description UserCollectionList
|
// @Description list personal collections
|
||||||
// @Tags Collection
|
// @Tags Collection
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security ApiKeyAuth
|
// @Security ApiKeyAuth
|
||||||
// @Param page query string true "page" default(0)
|
// @Param page query string true "page" default(0)
|
||||||
// @Param pagesize query string true "pagesize" default(20)
|
// @Param page_size query string true "page_size" default(20)
|
||||||
// @Success 200 {object} handler.RespBody
|
// @Success 200 {object} handler.RespBody
|
||||||
// @Router /answer/api/v1/personal/collection/page [get]
|
// @Router /answer/api/v1/personal/collection/page [get]
|
||||||
func (qc *QuestionController) UserCollectionList(ctx *gin.Context) {
|
func (qc *QuestionController) PersonalCollectionPage(ctx *gin.Context) {
|
||||||
pageStr := ctx.Query("page")
|
req := &schema.PersonalCollectionPageReq{}
|
||||||
pageSizeStr := ctx.Query("pagesize")
|
if handler.BindAndCheck(ctx, req) {
|
||||||
page := converter.StringToInt(pageStr)
|
return
|
||||||
pageSize := converter.StringToInt(pageSizeStr)
|
}
|
||||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
||||||
questionList, count, err := qc.questionService.SearchUserCollectionList(ctx, page, pageSize, userID)
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
handler.HandleResponse(ctx, err, gin.H{
|
|
||||||
"list": questionList,
|
resp, err := qc.questionService.PersonalCollectionPage(ctx, req)
|
||||||
"count": count,
|
handler.HandleResponse(ctx, err, resp)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdminSearchList godoc
|
// AdminSearchList godoc
|
||||||
|
|
|
@ -120,14 +120,14 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
|
||||||
//answer
|
//answer
|
||||||
r.GET("/answer/info", a.answerController.Get)
|
r.GET("/answer/info", a.answerController.Get)
|
||||||
r.GET("/answer/page", a.answerController.AnswerList)
|
r.GET("/answer/page", a.answerController.AnswerList)
|
||||||
r.GET("/personal/answer/page", a.questionController.UserAnswerList)
|
r.GET("/personal/answer/page", a.questionController.PersonalAnswerPage)
|
||||||
|
|
||||||
//question
|
//question
|
||||||
r.GET("/question/info", a.questionController.GetQuestion)
|
r.GET("/question/info", a.questionController.GetQuestion)
|
||||||
r.GET("/question/page", a.questionController.QuestionPage)
|
r.GET("/question/page", a.questionController.QuestionPage)
|
||||||
r.GET("/question/similar/tag", a.questionController.SimilarQuestion)
|
r.GET("/question/similar/tag", a.questionController.SimilarQuestion)
|
||||||
r.GET("/personal/qa/top", a.questionController.UserTop)
|
r.GET("/personal/qa/top", a.questionController.UserTop)
|
||||||
r.GET("/personal/question/page", a.questionController.UserList)
|
r.GET("/personal/question/page", a.questionController.PersonalQuestionPage)
|
||||||
|
|
||||||
// comment
|
// comment
|
||||||
r.GET("/comment/page", a.commentController.GetCommentWithPage)
|
r.GET("/comment/page", a.commentController.GetCommentWithPage)
|
||||||
|
@ -182,7 +182,7 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
|
||||||
|
|
||||||
// collection
|
// collection
|
||||||
r.POST("/collection/switch", a.collectionController.CollectionSwitch)
|
r.POST("/collection/switch", a.collectionController.CollectionSwitch)
|
||||||
r.GET("/personal/collection/page", a.questionController.UserCollectionList)
|
r.GET("/personal/collection/page", a.questionController.PersonalCollectionPage)
|
||||||
|
|
||||||
// question
|
// question
|
||||||
r.POST("/question", a.questionController.AddQuestion)
|
r.POST("/question", a.questionController.AddQuestion)
|
||||||
|
|
|
@ -374,3 +374,25 @@ type SiteMapQuestionInfo struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
UpdateTime string `json:"time"`
|
UpdateTime string `json:"time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PersonalQuestionPageReq struct {
|
||||||
|
Page int `validate:"omitempty,min=1" form:"page"`
|
||||||
|
PageSize int `validate:"omitempty,min=1" form:"page_size"`
|
||||||
|
OrderCond string `validate:"omitempty,oneof=newest active frequent score unanswered" form:"order"`
|
||||||
|
Username string `validate:"omitempty,gt=0,lte=100" form:"username"`
|
||||||
|
LoginUserID string `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PersonalAnswerPageReq struct {
|
||||||
|
Page int `validate:"omitempty,min=1" form:"page"`
|
||||||
|
PageSize int `validate:"omitempty,min=1" form:"page_size"`
|
||||||
|
OrderCond string `validate:"omitempty,oneof=newest active frequent score unanswered" form:"order"`
|
||||||
|
Username string `validate:"omitempty,gt=0,lte=100" form:"username"`
|
||||||
|
LoginUserID string `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PersonalCollectionPageReq struct {
|
||||||
|
Page int `validate:"omitempty,min=1" form:"page"`
|
||||||
|
PageSize int `validate:"omitempty,min=1" form:"page_size"`
|
||||||
|
UserID string `json:"-"`
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/answerdev/answer/internal/base/constant"
|
"github.com/answerdev/answer/internal/base/constant"
|
||||||
"github.com/answerdev/answer/internal/base/data"
|
"github.com/answerdev/answer/internal/base/data"
|
||||||
"github.com/answerdev/answer/internal/base/handler"
|
"github.com/answerdev/answer/internal/base/handler"
|
||||||
|
"github.com/answerdev/answer/internal/base/pager"
|
||||||
"github.com/answerdev/answer/internal/base/reason"
|
"github.com/answerdev/answer/internal/base/reason"
|
||||||
"github.com/answerdev/answer/internal/base/translator"
|
"github.com/answerdev/answer/internal/base/translator"
|
||||||
"github.com/answerdev/answer/internal/base/validator"
|
"github.com/answerdev/answer/internal/base/validator"
|
||||||
|
@ -734,70 +735,74 @@ func (qs *QuestionService) CheckChangeReservedTag(ctx context.Context, oldobject
|
||||||
return qs.tagCommon.CheckChangeReservedTag(ctx, oldobjectTagData, objectTagData)
|
return qs.tagCommon.CheckChangeReservedTag(ctx, oldobjectTagData, objectTagData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuestionService) SearchUserList(ctx context.Context, userName, order string, page, pageSize int, loginUserID string) ([]*schema.UserQuestionInfo, int64, error) {
|
// PersonalQuestionPage get question list by user
|
||||||
userlist := make([]*schema.UserQuestionInfo, 0)
|
func (qs *QuestionService) PersonalQuestionPage(ctx context.Context, req *schema.PersonalQuestionPageReq) (
|
||||||
|
pageModel *pager.PageModel, err error) {
|
||||||
|
|
||||||
userinfo, Exist, err := qs.userCommon.GetUserBasicInfoByUserName(ctx, userName)
|
userinfo, exist, err := qs.userCommon.GetUserBasicInfoByUserName(ctx, req.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return userlist, 0, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !Exist {
|
if !exist {
|
||||||
return userlist, 0, nil
|
return nil, errors.BadRequest(reason.UserNotFound)
|
||||||
}
|
}
|
||||||
search := &schema.QuestionPageReq{}
|
search := &schema.QuestionPageReq{}
|
||||||
search.OrderCond = order
|
search.OrderCond = req.OrderCond
|
||||||
search.Page = page
|
search.Page = req.Page
|
||||||
search.PageSize = pageSize
|
search.PageSize = req.PageSize
|
||||||
search.UserIDBeSearched = userinfo.ID
|
search.UserIDBeSearched = userinfo.ID
|
||||||
search.LoginUserID = loginUserID
|
search.LoginUserID = req.LoginUserID
|
||||||
questionlist, count, err := qs.GetQuestionPage(ctx, search)
|
questionList, total, err := qs.GetQuestionPage(ctx, search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return userlist, 0, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, item := range questionlist {
|
userQuestionInfoList := make([]*schema.UserQuestionInfo, 0)
|
||||||
|
for _, item := range questionList {
|
||||||
info := &schema.UserQuestionInfo{}
|
info := &schema.UserQuestionInfo{}
|
||||||
_ = copier.Copy(info, item)
|
_ = copier.Copy(info, item)
|
||||||
status, ok := entity.AdminQuestionSearchStatusIntToString[item.Status]
|
status, ok := entity.AdminQuestionSearchStatusIntToString[item.Status]
|
||||||
if ok {
|
if ok {
|
||||||
info.Status = status
|
info.Status = status
|
||||||
}
|
}
|
||||||
userlist = append(userlist, info)
|
userQuestionInfoList = append(userQuestionInfoList, info)
|
||||||
}
|
}
|
||||||
return userlist, count, nil
|
return pager.NewPageModel(total, userQuestionInfoList), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuestionService) SearchUserAnswerList(ctx context.Context, userName, order string, page, pageSize int, loginUserID string) ([]*schema.UserAnswerInfo, int64, error) {
|
func (qs *QuestionService) PersonalAnswerPage(ctx context.Context, req *schema.PersonalAnswerPageReq) (
|
||||||
answerlist := make([]*schema.AnswerInfo, 0)
|
pageModel *pager.PageModel, err error) {
|
||||||
userAnswerlist := make([]*schema.UserAnswerInfo, 0)
|
userinfo, exist, err := qs.userCommon.GetUserBasicInfoByUserName(ctx, req.Username)
|
||||||
userinfo, Exist, err := qs.userCommon.GetUserBasicInfoByUserName(ctx, userName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return userAnswerlist, 0, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if !Exist {
|
if !exist {
|
||||||
return userAnswerlist, 0, nil
|
return nil, errors.BadRequest(reason.UserNotFound)
|
||||||
}
|
}
|
||||||
answersearch := &entity.AnswerSearch{}
|
answersearch := &entity.AnswerSearch{}
|
||||||
answersearch.UserID = userinfo.ID
|
answersearch.UserID = userinfo.ID
|
||||||
answersearch.PageSize = pageSize
|
answersearch.PageSize = req.PageSize
|
||||||
answersearch.Page = page
|
answersearch.Page = req.Page
|
||||||
if order == "newest" {
|
if req.OrderCond == "newest" {
|
||||||
answersearch.Order = entity.AnswerSearchOrderByTime
|
answersearch.Order = entity.AnswerSearchOrderByTime
|
||||||
} else {
|
} else {
|
||||||
answersearch.Order = entity.AnswerSearchOrderByDefault
|
answersearch.Order = entity.AnswerSearchOrderByDefault
|
||||||
}
|
}
|
||||||
questionIDs := make([]string, 0)
|
questionIDs := make([]string, 0)
|
||||||
answerList, count, err := qs.questioncommon.AnswerCommon.Search(ctx, answersearch)
|
answerList, total, err := qs.questioncommon.AnswerCommon.Search(ctx, answersearch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return userAnswerlist, count, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
answerlist := make([]*schema.AnswerInfo, 0)
|
||||||
|
userAnswerlist := make([]*schema.UserAnswerInfo, 0)
|
||||||
for _, item := range answerList {
|
for _, item := range answerList {
|
||||||
answerinfo := qs.questioncommon.AnswerCommon.ShowFormat(ctx, item)
|
answerinfo := qs.questioncommon.AnswerCommon.ShowFormat(ctx, item)
|
||||||
answerlist = append(answerlist, answerinfo)
|
answerlist = append(answerlist, answerinfo)
|
||||||
questionIDs = append(questionIDs, uid.DeShortID(item.QuestionID))
|
questionIDs = append(questionIDs, uid.DeShortID(item.QuestionID))
|
||||||
}
|
}
|
||||||
questionMaps, err := qs.questioncommon.FindInfoByID(ctx, questionIDs, loginUserID)
|
questionMaps, err := qs.questioncommon.FindInfoByID(ctx, questionIDs, req.LoginUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return userAnswerlist, count, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range answerlist {
|
for _, item := range answerlist {
|
||||||
|
@ -814,34 +819,29 @@ func (qs *QuestionService) SearchUserAnswerList(ctx context.Context, userName, o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return userAnswerlist, count, nil
|
return pager.NewPageModel(total, userAnswerlist), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuestionService) SearchUserCollectionList(ctx context.Context, page, pageSize int, loginUserID string) ([]*schema.QuestionInfo, int64, error) {
|
// PersonalCollectionPage get collection list by user
|
||||||
|
func (qs *QuestionService) PersonalCollectionPage(ctx context.Context, req *schema.PersonalCollectionPageReq) (
|
||||||
|
pageModel *pager.PageModel, err error) {
|
||||||
list := make([]*schema.QuestionInfo, 0)
|
list := make([]*schema.QuestionInfo, 0)
|
||||||
userinfo, Exist, err := qs.userCommon.GetUserBasicInfoByID(ctx, loginUserID)
|
|
||||||
if err != nil {
|
|
||||||
return list, 0, err
|
|
||||||
}
|
|
||||||
if !Exist {
|
|
||||||
return list, 0, nil
|
|
||||||
}
|
|
||||||
collectionSearch := &entity.CollectionSearch{}
|
collectionSearch := &entity.CollectionSearch{}
|
||||||
collectionSearch.UserID = userinfo.ID
|
collectionSearch.UserID = req.UserID
|
||||||
collectionSearch.Page = page
|
collectionSearch.Page = req.Page
|
||||||
collectionSearch.PageSize = pageSize
|
collectionSearch.PageSize = req.PageSize
|
||||||
collectionlist, count, err := qs.collectionCommon.SearchList(ctx, collectionSearch)
|
collectionList, total, err := qs.collectionCommon.SearchList(ctx, collectionSearch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return list, 0, err
|
return nil, err
|
||||||
}
|
}
|
||||||
questionIDs := make([]string, 0)
|
questionIDs := make([]string, 0)
|
||||||
for _, item := range collectionlist {
|
for _, item := range collectionList {
|
||||||
questionIDs = append(questionIDs, item.ObjectID)
|
questionIDs = append(questionIDs, item.ObjectID)
|
||||||
}
|
}
|
||||||
|
|
||||||
questionMaps, err := qs.questioncommon.FindInfoByID(ctx, questionIDs, loginUserID)
|
questionMaps, err := qs.questioncommon.FindInfoByID(ctx, questionIDs, req.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return list, count, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, id := range questionIDs {
|
for _, id := range questionIDs {
|
||||||
_, ok := questionMaps[uid.EnShortID(id)]
|
_, ok := questionMaps[uid.EnShortID(id)]
|
||||||
|
@ -854,7 +854,7 @@ func (qs *QuestionService) SearchUserCollectionList(ctx context.Context, page, p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list, count, nil
|
return pager.NewPageModel(total, list), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuestionService) SearchUserTopList(ctx context.Context, userName string, loginUserID string) ([]*schema.UserQuestionInfo, []*schema.UserAnswerInfo, error) {
|
func (qs *QuestionService) SearchUserTopList(ctx context.Context, userName string, loginUserID string) ([]*schema.UserQuestionInfo, []*schema.UserAnswerInfo, error) {
|
||||||
|
|
Loading…
Reference in New Issue