fix(personal): rename all wrong name about page size

This commit is contained in:
LinkinStars 2023-05-06 11:57:47 +08:00
parent a93668d455
commit fafdc5435a
7 changed files with 156 additions and 144 deletions

View File

@ -2517,7 +2517,7 @@ const docTemplate = `{
"ApiKeyAuth": []
}
],
"description": "UserAnswerList",
"description": "list personal answers",
"consumes": [
"application/json"
],
@ -2525,9 +2525,9 @@ const docTemplate = `{
"application/json"
],
"tags": [
"api-answer"
"Personal"
],
"summary": "UserAnswerList",
"summary": "list personal answers",
"parameters": [
{
"type": "string",
@ -2559,8 +2559,8 @@ const docTemplate = `{
{
"type": "string",
"default": "20",
"description": "pagesize",
"name": "pagesize",
"description": "page_size",
"name": "page_size",
"in": "query",
"required": true
}
@ -2582,7 +2582,7 @@ const docTemplate = `{
"ApiKeyAuth": []
}
],
"description": "UserCollectionList",
"description": "list personal collections",
"consumes": [
"application/json"
],
@ -2592,7 +2592,7 @@ const docTemplate = `{
"tags": [
"Collection"
],
"summary": "UserCollectionList",
"summary": "list personal collections",
"parameters": [
{
"type": "string",
@ -2605,8 +2605,8 @@ const docTemplate = `{
{
"type": "string",
"default": "20",
"description": "pagesize",
"name": "pagesize",
"description": "page_size",
"name": "page_size",
"in": "query",
"required": true
}
@ -5324,7 +5324,7 @@ const docTemplate = `{
"ApiKeyAuth": []
}
],
"description": "UserList",
"description": "list personal questions",
"consumes": [
"application/json"
],
@ -5332,9 +5332,9 @@ const docTemplate = `{
"application/json"
],
"tags": [
"Question"
"Personal"
],
"summary": "UserList",
"summary": "list personal questions",
"parameters": [
{
"type": "string",
@ -5366,8 +5366,8 @@ const docTemplate = `{
{
"type": "string",
"default": "20",
"description": "pagesize",
"name": "pagesize",
"description": "page_size",
"name": "page_size",
"in": "query",
"required": true
}

View File

@ -2505,7 +2505,7 @@
"ApiKeyAuth": []
}
],
"description": "UserAnswerList",
"description": "list personal answers",
"consumes": [
"application/json"
],
@ -2513,9 +2513,9 @@
"application/json"
],
"tags": [
"api-answer"
"Personal"
],
"summary": "UserAnswerList",
"summary": "list personal answers",
"parameters": [
{
"type": "string",
@ -2547,8 +2547,8 @@
{
"type": "string",
"default": "20",
"description": "pagesize",
"name": "pagesize",
"description": "page_size",
"name": "page_size",
"in": "query",
"required": true
}
@ -2570,7 +2570,7 @@
"ApiKeyAuth": []
}
],
"description": "UserCollectionList",
"description": "list personal collections",
"consumes": [
"application/json"
],
@ -2580,7 +2580,7 @@
"tags": [
"Collection"
],
"summary": "UserCollectionList",
"summary": "list personal collections",
"parameters": [
{
"type": "string",
@ -2593,8 +2593,8 @@
{
"type": "string",
"default": "20",
"description": "pagesize",
"name": "pagesize",
"description": "page_size",
"name": "page_size",
"in": "query",
"required": true
}
@ -5312,7 +5312,7 @@
"ApiKeyAuth": []
}
],
"description": "UserList",
"description": "list personal questions",
"consumes": [
"application/json"
],
@ -5320,9 +5320,9 @@
"application/json"
],
"tags": [
"Question"
"Personal"
],
"summary": "UserList",
"summary": "list personal questions",
"parameters": [
{
"type": "string",
@ -5354,8 +5354,8 @@
{
"type": "string",
"default": "20",
"description": "pagesize",
"name": "pagesize",
"description": "page_size",
"name": "page_size",
"in": "query",
"required": true
}

View File

@ -3509,7 +3509,7 @@ paths:
get:
consumes:
- application/json
description: UserAnswerList
description: list personal answers
parameters:
- default: string
description: username
@ -3532,9 +3532,9 @@ paths:
required: true
type: string
- default: "20"
description: pagesize
description: page_size
in: query
name: pagesize
name: page_size
required: true
type: string
produces:
@ -3546,14 +3546,14 @@ paths:
$ref: '#/definitions/handler.RespBody'
security:
- ApiKeyAuth: []
summary: UserAnswerList
summary: list personal answers
tags:
- api-answer
- Personal
/answer/api/v1/personal/collection/page:
get:
consumes:
- application/json
description: UserCollectionList
description: list personal collections
parameters:
- default: "0"
description: page
@ -3562,9 +3562,9 @@ paths:
required: true
type: string
- default: "20"
description: pagesize
description: page_size
in: query
name: pagesize
name: page_size
required: true
type: string
produces:
@ -3576,7 +3576,7 @@ paths:
$ref: '#/definitions/handler.RespBody'
security:
- ApiKeyAuth: []
summary: UserCollectionList
summary: list personal collections
tags:
- Collection
/answer/api/v1/personal/comment/page:
@ -5210,7 +5210,7 @@ paths:
get:
consumes:
- application/json
description: UserList
description: list personal questions
parameters:
- default: string
description: username
@ -5233,9 +5233,9 @@ paths:
required: true
type: string
- default: "20"
description: pagesize
description: page_size
in: query
name: pagesize
name: page_size
required: true
type: string
produces:
@ -5247,9 +5247,9 @@ paths:
$ref: '#/definitions/handler.RespBody'
security:
- ApiKeyAuth: []
summary: UserList
summary: list personal questions
tags:
- Question
- Personal
/robots.txt:
get:
description: get site robots information

View File

@ -11,7 +11,6 @@ import (
"github.com/answerdev/answer/internal/service"
"github.com/answerdev/answer/internal/service/permission"
"github.com/answerdev/answer/internal/service/rank"
"github.com/answerdev/answer/pkg/converter"
"github.com/answerdev/answer/pkg/uid"
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
@ -552,84 +551,75 @@ func (qc *QuestionController) UserTop(ctx *gin.Context) {
})
}
// UserList godoc
// @Summary UserList
// @Description UserList
// @Tags Question
// PersonalQuestionPage list personal questions
// @Summary list personal questions
// @Description list personal questions
// @Tags Personal
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param username query string true "username" default(string)
// @Param order query string true "order" Enums(newest,score)
// @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
// @Router /personal/question/page [get]
func (qc *QuestionController) UserList(ctx *gin.Context) {
userName := ctx.Query("username")
order := ctx.Query("order")
pageStr := ctx.Query("page")
pageSizeStr := ctx.Query("pagesize")
page := converter.StringToInt(pageStr)
pageSize := converter.StringToInt(pageSizeStr)
userID := middleware.GetLoginUserIDFromContext(ctx)
questionList, count, err := qc.questionService.SearchUserList(ctx, userName, order, page, pageSize, userID)
handler.HandleResponse(ctx, err, gin.H{
"list": questionList,
"count": count,
})
func (qc *QuestionController) PersonalQuestionPage(ctx *gin.Context) {
req := &schema.PersonalQuestionPageReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
resp, err := qc.questionService.PersonalQuestionPage(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UserAnswerList godoc
// @Summary UserAnswerList
// @Description UserAnswerList
// @Tags api-answer
// PersonalAnswerPage list personal answers
// @Summary list personal answers
// @Description list personal answers
// @Tags Personal
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Param username query string true "username" default(string)
// @Param order query string true "order" Enums(newest,score)
// @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
// @Router /answer/api/v1/personal/answer/page [get]
func (qc *QuestionController) UserAnswerList(ctx *gin.Context) {
userName := ctx.Query("username")
order := ctx.Query("order")
pageStr := ctx.Query("page")
pageSizeStr := ctx.Query("pagesize")
page := converter.StringToInt(pageStr)
pageSize := converter.StringToInt(pageSizeStr)
userID := middleware.GetLoginUserIDFromContext(ctx)
questionList, count, err := qc.questionService.SearchUserAnswerList(ctx, userName, order, page, pageSize, userID)
handler.HandleResponse(ctx, err, gin.H{
"list": questionList,
"count": count,
})
func (qc *QuestionController) PersonalAnswerPage(ctx *gin.Context) {
req := &schema.PersonalAnswerPageReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
resp, err := qc.questionService.PersonalAnswerPage(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// UserCollectionList godoc
// @Summary UserCollectionList
// @Description UserCollectionList
// PersonalCollectionPage list personal collections
// @Summary list personal collections
// @Description list personal collections
// @Tags Collection
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @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
// @Router /answer/api/v1/personal/collection/page [get]
func (qc *QuestionController) UserCollectionList(ctx *gin.Context) {
pageStr := ctx.Query("page")
pageSizeStr := ctx.Query("pagesize")
page := converter.StringToInt(pageStr)
pageSize := converter.StringToInt(pageSizeStr)
userID := middleware.GetLoginUserIDFromContext(ctx)
questionList, count, err := qc.questionService.SearchUserCollectionList(ctx, page, pageSize, userID)
handler.HandleResponse(ctx, err, gin.H{
"list": questionList,
"count": count,
})
func (qc *QuestionController) PersonalCollectionPage(ctx *gin.Context) {
req := &schema.PersonalCollectionPageReq{}
if handler.BindAndCheck(ctx, req) {
return
}
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
resp, err := qc.questionService.PersonalCollectionPage(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
// AdminSearchList godoc

View File

@ -120,14 +120,14 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
//answer
r.GET("/answer/info", a.answerController.Get)
r.GET("/answer/page", a.answerController.AnswerList)
r.GET("/personal/answer/page", a.questionController.UserAnswerList)
r.GET("/personal/answer/page", a.questionController.PersonalAnswerPage)
//question
r.GET("/question/info", a.questionController.GetQuestion)
r.GET("/question/page", a.questionController.QuestionPage)
r.GET("/question/similar/tag", a.questionController.SimilarQuestion)
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
r.GET("/comment/page", a.commentController.GetCommentWithPage)
@ -182,7 +182,7 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
// collection
r.POST("/collection/switch", a.collectionController.CollectionSwitch)
r.GET("/personal/collection/page", a.questionController.UserCollectionList)
r.GET("/personal/collection/page", a.questionController.PersonalCollectionPage)
// question
r.POST("/question", a.questionController.AddQuestion)

View File

@ -374,3 +374,25 @@ type SiteMapQuestionInfo struct {
Title string `json:"title"`
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:"-"`
}

View File

@ -10,6 +10,7 @@ import (
"github.com/answerdev/answer/internal/base/constant"
"github.com/answerdev/answer/internal/base/data"
"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/translator"
"github.com/answerdev/answer/internal/base/validator"
@ -733,70 +734,74 @@ func (qs *QuestionService) CheckChangeReservedTag(ctx context.Context, oldobject
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) {
userlist := make([]*schema.UserQuestionInfo, 0)
// PersonalQuestionPage get question list by user
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 {
return userlist, 0, err
return nil, err
}
if !Exist {
return userlist, 0, nil
if !exist {
return nil, errors.BadRequest(reason.UserNotFound)
}
search := &schema.QuestionPageReq{}
search.OrderCond = order
search.Page = page
search.PageSize = pageSize
search.OrderCond = req.OrderCond
search.Page = req.Page
search.PageSize = req.PageSize
search.UserIDBeSearched = userinfo.ID
search.LoginUserID = loginUserID
questionlist, count, err := qs.GetQuestionPage(ctx, search)
search.LoginUserID = req.LoginUserID
questionList, total, err := qs.GetQuestionPage(ctx, search)
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{}
_ = copier.Copy(info, item)
status, ok := entity.AdminQuestionSearchStatusIntToString[item.Status]
if ok {
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) {
answerlist := make([]*schema.AnswerInfo, 0)
userAnswerlist := make([]*schema.UserAnswerInfo, 0)
userinfo, Exist, err := qs.userCommon.GetUserBasicInfoByUserName(ctx, userName)
func (qs *QuestionService) PersonalAnswerPage(ctx context.Context, req *schema.PersonalAnswerPageReq) (
pageModel *pager.PageModel, err error) {
userinfo, exist, err := qs.userCommon.GetUserBasicInfoByUserName(ctx, req.Username)
if err != nil {
return userAnswerlist, 0, err
return nil, err
}
if !Exist {
return userAnswerlist, 0, nil
if !exist {
return nil, errors.BadRequest(reason.UserNotFound)
}
answersearch := &entity.AnswerSearch{}
answersearch.UserID = userinfo.ID
answersearch.PageSize = pageSize
answersearch.Page = page
if order == "newest" {
answersearch.PageSize = req.PageSize
answersearch.Page = req.Page
if req.OrderCond == "newest" {
answersearch.Order = entity.AnswerSearchOrderByTime
} else {
answersearch.Order = entity.AnswerSearchOrderByDefault
}
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 {
return userAnswerlist, count, err
return nil, err
}
answerlist := make([]*schema.AnswerInfo, 0)
userAnswerlist := make([]*schema.UserAnswerInfo, 0)
for _, item := range answerList {
answerinfo := qs.questioncommon.AnswerCommon.ShowFormat(ctx, item)
answerlist = append(answerlist, answerinfo)
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 {
return userAnswerlist, count, err
return nil, err
}
for _, item := range answerlist {
@ -813,34 +818,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)
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.UserID = userinfo.ID
collectionSearch.Page = page
collectionSearch.PageSize = pageSize
collectionlist, count, err := qs.collectionCommon.SearchList(ctx, collectionSearch)
collectionSearch.UserID = req.UserID
collectionSearch.Page = req.Page
collectionSearch.PageSize = req.PageSize
collectionList, total, err := qs.collectionCommon.SearchList(ctx, collectionSearch)
if err != nil {
return list, 0, err
return nil, err
}
questionIDs := make([]string, 0)
for _, item := range collectionlist {
for _, item := range collectionList {
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 {
return list, count, err
return nil, err
}
for _, id := range questionIDs {
_, ok := questionMaps[uid.EnShortID(id)]
@ -853,7 +853,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) {