mirror of https://gitee.com/answerdev/answer.git
refactor(answer): refactor admin question answer page list
This commit is contained in:
parent
3ed9568614
commit
92c5bb6616
|
@ -49,7 +49,7 @@ const docTemplate = `{
|
||||||
"tags": [
|
"tags": [
|
||||||
"admin"
|
"admin"
|
||||||
],
|
],
|
||||||
"summary": "AdminSearchAnswerList",
|
"summary": "AdminAnswerPage admin answer page",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
@ -379,7 +379,7 @@ const docTemplate = `{
|
||||||
"tags": [
|
"tags": [
|
||||||
"admin"
|
"admin"
|
||||||
],
|
],
|
||||||
"summary": "AdminSearchList",
|
"summary": "AdminQuestionPage admin question page",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
@ -8186,7 +8186,7 @@ const docTemplate = `{
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"site_seo": {
|
"site_seo": {
|
||||||
"$ref": "#/definitions/schema.SiteSeoReq"
|
"$ref": "#/definitions/schema.SiteSeoResp"
|
||||||
},
|
},
|
||||||
"site_users": {
|
"site_users": {
|
||||||
"$ref": "#/definitions/schema.SiteUsersResp"
|
"$ref": "#/definitions/schema.SiteUsersResp"
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"admin"
|
"admin"
|
||||||
],
|
],
|
||||||
"summary": "AdminSearchAnswerList",
|
"summary": "AdminAnswerPage admin answer page",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
@ -367,7 +367,7 @@
|
||||||
"tags": [
|
"tags": [
|
||||||
"admin"
|
"admin"
|
||||||
],
|
],
|
||||||
"summary": "AdminSearchList",
|
"summary": "AdminQuestionPage admin question page",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
@ -8174,7 +8174,7 @@
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"site_seo": {
|
"site_seo": {
|
||||||
"$ref": "#/definitions/schema.SiteSeoReq"
|
"$ref": "#/definitions/schema.SiteSeoResp"
|
||||||
},
|
},
|
||||||
"site_users": {
|
"site_users": {
|
||||||
"$ref": "#/definitions/schema.SiteUsersResp"
|
"$ref": "#/definitions/schema.SiteUsersResp"
|
||||||
|
|
|
@ -1507,7 +1507,7 @@ definitions:
|
||||||
revision:
|
revision:
|
||||||
type: string
|
type: string
|
||||||
site_seo:
|
site_seo:
|
||||||
$ref: '#/definitions/schema.SiteSeoReq'
|
$ref: '#/definitions/schema.SiteSeoResp'
|
||||||
site_users:
|
site_users:
|
||||||
$ref: '#/definitions/schema.SiteUsersResp'
|
$ref: '#/definitions/schema.SiteUsersResp'
|
||||||
theme:
|
theme:
|
||||||
|
@ -2335,7 +2335,7 @@ paths:
|
||||||
$ref: '#/definitions/handler.RespBody'
|
$ref: '#/definitions/handler.RespBody'
|
||||||
security:
|
security:
|
||||||
- ApiKeyAuth: []
|
- ApiKeyAuth: []
|
||||||
summary: AdminSearchAnswerList
|
summary: AdminAnswerPage admin answer page
|
||||||
tags:
|
tags:
|
||||||
- admin
|
- admin
|
||||||
/answer/admin/api/answer/status:
|
/answer/admin/api/answer/status:
|
||||||
|
@ -2533,7 +2533,7 @@ paths:
|
||||||
$ref: '#/definitions/handler.RespBody'
|
$ref: '#/definitions/handler.RespBody'
|
||||||
security:
|
security:
|
||||||
- ApiKeyAuth: []
|
- ApiKeyAuth: []
|
||||||
summary: AdminSearchList
|
summary: AdminQuestionPage admin question page
|
||||||
tags:
|
tags:
|
||||||
- admin
|
- admin
|
||||||
/answer/admin/api/question/status:
|
/answer/admin/api/question/status:
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"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"
|
||||||
"github.com/answerdev/answer/internal/entity"
|
|
||||||
"github.com/answerdev/answer/internal/schema"
|
"github.com/answerdev/answer/internal/schema"
|
||||||
"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"
|
||||||
|
@ -709,8 +708,8 @@ func (qc *QuestionController) PersonalCollectionPage(ctx *gin.Context) {
|
||||||
handler.HandleResponse(ctx, err, resp)
|
handler.HandleResponse(ctx, err, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdminSearchList godoc
|
// AdminQuestionPage admin question page
|
||||||
// @Summary AdminSearchList
|
// @Summary AdminQuestionPage admin question page
|
||||||
// @Description Status:[available,closed,deleted]
|
// @Description Status:[available,closed,deleted]
|
||||||
// @Tags admin
|
// @Tags admin
|
||||||
// @Accept json
|
// @Accept json
|
||||||
|
@ -722,21 +721,19 @@ func (qc *QuestionController) PersonalCollectionPage(ctx *gin.Context) {
|
||||||
// @Param query query string false "question id or title"
|
// @Param query query string false "question id or title"
|
||||||
// @Success 200 {object} handler.RespBody
|
// @Success 200 {object} handler.RespBody
|
||||||
// @Router /answer/admin/api/question/page [get]
|
// @Router /answer/admin/api/question/page [get]
|
||||||
func (qc *QuestionController) AdminSearchList(ctx *gin.Context) {
|
func (qc *QuestionController) AdminQuestionPage(ctx *gin.Context) {
|
||||||
req := &schema.AdminQuestionSearch{}
|
req := &schema.AdminQuestionPageReq{}
|
||||||
if handler.BindAndCheck(ctx, req) {
|
if handler.BindAndCheck(ctx, req) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
||||||
questionList, count, err := qc.questionService.AdminSearchList(ctx, req, userID)
|
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
handler.HandleResponse(ctx, err, gin.H{
|
resp, err := qc.questionService.AdminQuestionPage(ctx, req)
|
||||||
"list": questionList,
|
handler.HandleResponse(ctx, err, resp)
|
||||||
"count": count,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdminSearchAnswerList godoc
|
// AdminAnswerPage admin answer page
|
||||||
// @Summary AdminSearchAnswerList
|
// @Summary AdminAnswerPage admin answer page
|
||||||
// @Description Status:[available,deleted]
|
// @Description Status:[available,deleted]
|
||||||
// @Tags admin
|
// @Tags admin
|
||||||
// @Accept json
|
// @Accept json
|
||||||
|
@ -749,21 +746,15 @@ func (qc *QuestionController) AdminSearchList(ctx *gin.Context) {
|
||||||
// @Param question_id query string false "question id"
|
// @Param question_id query string false "question id"
|
||||||
// @Success 200 {object} handler.RespBody
|
// @Success 200 {object} handler.RespBody
|
||||||
// @Router /answer/admin/api/answer/page [get]
|
// @Router /answer/admin/api/answer/page [get]
|
||||||
func (qc *QuestionController) AdminSearchAnswerList(ctx *gin.Context) {
|
func (qc *QuestionController) AdminAnswerPage(ctx *gin.Context) {
|
||||||
req := &entity.AdminAnswerSearch{}
|
req := &schema.AdminAnswerPageReq{}
|
||||||
if handler.BindAndCheck(ctx, req) {
|
if handler.BindAndCheck(ctx, req) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.QuestionID = uid.DeShortID(req.QuestionID)
|
|
||||||
if req.QuestionID == "0" {
|
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
req.QuestionID = ""
|
resp, err := qc.questionService.AdminAnswerPage(ctx, req)
|
||||||
}
|
handler.HandleResponse(ctx, err, resp)
|
||||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
||||||
questionList, count, err := qc.questionService.AdminSearchAnswerList(ctx, req, userID)
|
|
||||||
handler.HandleResponse(ctx, err, gin.H{
|
|
||||||
"list": questionList,
|
|
||||||
"count": count,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdminSetQuestionStatus godoc
|
// AdminSetQuestionStatus godoc
|
||||||
|
|
|
@ -42,15 +42,6 @@ type AnswerSearch struct {
|
||||||
PageSize int `json:"page_size" form:"page_size"` // Search page size
|
PageSize int `json:"page_size" form:"page_size"` // Search page size
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminAnswerSearch struct {
|
|
||||||
Page int `json:"page" form:"page"` // Query number of pages
|
|
||||||
PageSize int `json:"page_size" form:"page_size"` // Search page size
|
|
||||||
Status int `json:"-" form:"-"`
|
|
||||||
StatusStr string `json:"status" form:"status"` // Status 1 Available 2 closed 10 Deleted
|
|
||||||
Query string `validate:"omitempty,gt=0,lte=100" json:"query" form:"query" ` //Query string
|
|
||||||
QuestionID string `validate:"omitempty,gt=0,lte=24" json:"question_id" form:"question_id" ` //Query string
|
|
||||||
}
|
|
||||||
|
|
||||||
// TableName answer table name
|
// TableName answer table name
|
||||||
func (Answer) TableName() string {
|
func (Answer) TableName() string {
|
||||||
return "answer"
|
return "answer"
|
||||||
|
|
|
@ -2,15 +2,11 @@ package answer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/base/handler"
|
|
||||||
"xorm.io/builder"
|
|
||||||
|
|
||||||
"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/pager"
|
"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/entity"
|
"github.com/answerdev/answer/internal/entity"
|
||||||
|
@ -295,82 +291,31 @@ func (ar *answerRepo) SearchList(ctx context.Context, search *entity.AnswerSearc
|
||||||
return rows, count, nil
|
return rows, count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ar *answerRepo) AdminSearchList(ctx context.Context, search *entity.AdminAnswerSearch) ([]*entity.Answer, int64, error) {
|
func (ar *answerRepo) AdminSearchList(ctx context.Context, req *schema.AdminAnswerPageReq) (
|
||||||
var (
|
resp []*entity.Answer, total int64, err error) {
|
||||||
count int64
|
cond := &entity.Answer{}
|
||||||
err error
|
session := ar.data.DB.Context(ctx)
|
||||||
session = ar.data.DB.Context(ctx).Table([]string{entity.Answer{}.TableName(), "a"}).Select("a.*")
|
if len(req.QuestionID) == 0 && len(req.AnswerID) == 0 {
|
||||||
)
|
session.Join("INNER", "question", "answer.question_id = question.id")
|
||||||
if search.QuestionID != "" {
|
if len(req.QuestionTitle) > 0 {
|
||||||
search.QuestionID = uid.DeShortID(search.QuestionID)
|
session.Where("question.title like ?", "%"+req.QuestionTitle+"%")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if len(req.AnswerID) > 0 {
|
||||||
|
cond.ID = req.AnswerID
|
||||||
|
}
|
||||||
|
if len(req.QuestionID) > 0 {
|
||||||
|
session.Where("answer.question_id = ?", req.QuestionID)
|
||||||
|
}
|
||||||
|
if req.Status > 0 {
|
||||||
|
cond.Status = req.Status
|
||||||
|
}
|
||||||
|
session.Desc("answer.created_at")
|
||||||
|
|
||||||
session.Where(builder.Eq{
|
resp = make([]*entity.Answer, 0)
|
||||||
"a.status": search.Status,
|
total, err = pager.Help(req.Page, req.PageSize, &resp, cond, session)
|
||||||
})
|
|
||||||
|
|
||||||
rows := make([]*entity.Answer, 0)
|
|
||||||
if search.Page > 0 {
|
|
||||||
search.Page = search.Page - 1
|
|
||||||
} else {
|
|
||||||
search.Page = 0
|
|
||||||
}
|
|
||||||
if search.PageSize == 0 {
|
|
||||||
search.PageSize = constant.DefaultPageSize
|
|
||||||
}
|
|
||||||
|
|
||||||
// search by question title like or answer id
|
|
||||||
if len(search.Query) > 0 {
|
|
||||||
// check id search
|
|
||||||
var (
|
|
||||||
idSearch = false
|
|
||||||
id = ""
|
|
||||||
)
|
|
||||||
|
|
||||||
if strings.Contains(search.Query, "answer:") {
|
|
||||||
idSearch = true
|
|
||||||
id = strings.TrimSpace(strings.TrimPrefix(search.Query, "answer:"))
|
|
||||||
id = uid.DeShortID(id)
|
|
||||||
for _, r := range id {
|
|
||||||
if !unicode.IsDigit(r) {
|
|
||||||
idSearch = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if idSearch {
|
|
||||||
session.And(builder.Eq{
|
|
||||||
"id": id,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
session.Join("LEFT", []string{entity.Question{}.TableName(), "q"}, "q.id = a.question_id")
|
|
||||||
session.And(builder.Like{
|
|
||||||
"q.title", search.Query,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check search by question id
|
|
||||||
if len(search.QuestionID) > 0 {
|
|
||||||
session.And(builder.Eq{
|
|
||||||
"question_id": search.QuestionID,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
offset := search.Page * search.PageSize
|
|
||||||
session.
|
|
||||||
OrderBy("a.created_at desc").
|
|
||||||
Limit(search.PageSize, offset)
|
|
||||||
count, err = session.FindAndCount(&rows)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rows, count, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
return nil, 0, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
}
|
}
|
||||||
if handler.GetEnableShortID(ctx) {
|
return resp, total, nil
|
||||||
for _, item := range rows {
|
|
||||||
item.ID = uid.EnShortID(item.ID)
|
|
||||||
item.QuestionID = uid.EnShortID(item.QuestionID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rows, count, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,7 +333,7 @@ func (qr *questionRepo) GetQuestionPage(ctx context.Context, page, pageSize int,
|
||||||
return questionList, total, err
|
return questionList, total, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qr *questionRepo) AdminSearchList(ctx context.Context, search *schema.AdminQuestionSearch) ([]*entity.Question, int64, error) {
|
func (qr *questionRepo) AdminQuestionPage(ctx context.Context, search *schema.AdminQuestionPageReq) ([]*entity.Question, int64, error) {
|
||||||
var (
|
var (
|
||||||
count int64
|
count int64
|
||||||
err error
|
err error
|
||||||
|
|
|
@ -244,9 +244,9 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AnswerAPIRouter) RegisterAnswerAdminAPIRouter(r *gin.RouterGroup) {
|
func (a *AnswerAPIRouter) RegisterAnswerAdminAPIRouter(r *gin.RouterGroup) {
|
||||||
r.GET("/question/page", a.questionController.AdminSearchList)
|
r.GET("/question/page", a.questionController.AdminQuestionPage)
|
||||||
r.PUT("/question/status", a.questionController.AdminSetQuestionStatus)
|
r.PUT("/question/status", a.questionController.AdminSetQuestionStatus)
|
||||||
r.GET("/answer/page", a.questionController.AdminSearchAnswerList)
|
r.GET("/answer/page", a.questionController.AdminAnswerPage)
|
||||||
r.PUT("/answer/status", a.answerController.AdminSetAnswerStatus)
|
r.PUT("/answer/status", a.answerController.AdminSetAnswerStatus)
|
||||||
|
|
||||||
// report
|
// report
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package schema
|
package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/base/validator"
|
"github.com/answerdev/answer/internal/base/validator"
|
||||||
|
"github.com/answerdev/answer/internal/entity"
|
||||||
"github.com/answerdev/answer/pkg/converter"
|
"github.com/answerdev/answer/pkg/converter"
|
||||||
|
"github.com/answerdev/answer/pkg/uid"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -361,12 +364,62 @@ type QuestionPageRespOperator struct {
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminQuestionSearch struct {
|
type AdminQuestionPageReq struct {
|
||||||
Page int `json:"page" form:"page"` // Query number of pages
|
Page int `validate:"omitempty,min=1" form:"page"`
|
||||||
PageSize int `json:"page_size" form:"page_size"` // Search page size
|
PageSize int `validate:"omitempty,min=1" form:"page_size"`
|
||||||
Status int `json:"-" form:"-"`
|
StatusCond string `validate:"omitempty,oneof=normal closed deleted" form:"status"`
|
||||||
StatusStr string `json:"status" form:"status"` // Status 1 Available 2 closed 10 UserDeleted
|
Query string `validate:"omitempty,gt=0,lte=100" json:"query" form:"query" `
|
||||||
Query string `validate:"omitempty,gt=0,lte=100" json:"query" form:"query" ` //Query string
|
Status int `json:"-"`
|
||||||
|
LoginUserID string `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (req *AdminQuestionPageReq) Check() (errField []*validator.FormErrorField, err error) {
|
||||||
|
status, ok := entity.AdminQuestionSearchStatus[req.StatusCond]
|
||||||
|
if ok {
|
||||||
|
req.Status = status
|
||||||
|
}
|
||||||
|
if req.Status == 0 {
|
||||||
|
req.Status = 1
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminAnswerPageReq admin answer page req
|
||||||
|
type AdminAnswerPageReq struct {
|
||||||
|
Page int `validate:"omitempty,min=1" form:"page"`
|
||||||
|
PageSize int `validate:"omitempty,min=1" form:"page_size"`
|
||||||
|
StatusCond string `validate:"omitempty,oneof=normal deleted" form:"status"`
|
||||||
|
Query string `validate:"omitempty,gt=0,lte=100" form:"query"`
|
||||||
|
QuestionID string `validate:"omitempty,gt=0,lte=24" form:"question_id"`
|
||||||
|
QuestionTitle string `json:"-"`
|
||||||
|
AnswerID string `json:"-"`
|
||||||
|
Status int `json:"-"`
|
||||||
|
LoginUserID string `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (req *AdminAnswerPageReq) Check() (errField []*validator.FormErrorField, err error) {
|
||||||
|
req.QuestionID = uid.DeShortID(req.QuestionID)
|
||||||
|
if req.QuestionID == "0" {
|
||||||
|
req.QuestionID = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if status, ok := entity.AdminAnswerSearchStatus[req.StatusCond]; ok {
|
||||||
|
req.Status = status
|
||||||
|
}
|
||||||
|
if req.Status == 0 {
|
||||||
|
req.Status = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse query condition
|
||||||
|
if len(req.Query) > 0 {
|
||||||
|
prefix := "answer:"
|
||||||
|
if strings.Contains(req.Query, prefix) {
|
||||||
|
req.AnswerID = uid.DeShortID(strings.TrimSpace(strings.TrimPrefix(req.Query, prefix)))
|
||||||
|
} else {
|
||||||
|
req.QuestionTitle = strings.TrimSpace(req.Query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminSetQuestionStatusRequest struct {
|
type AdminSetQuestionStatusRequest struct {
|
||||||
|
|
|
@ -3,9 +3,11 @@ package answercommon
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/answerdev/answer/internal/base/handler"
|
||||||
"github.com/answerdev/answer/internal/entity"
|
"github.com/answerdev/answer/internal/entity"
|
||||||
"github.com/answerdev/answer/internal/schema"
|
"github.com/answerdev/answer/internal/schema"
|
||||||
"github.com/answerdev/answer/pkg/htmltext"
|
"github.com/answerdev/answer/pkg/htmltext"
|
||||||
|
"github.com/answerdev/answer/pkg/uid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AnswerRepo interface {
|
type AnswerRepo interface {
|
||||||
|
@ -21,7 +23,7 @@ type AnswerRepo interface {
|
||||||
GetCountByUserID(ctx context.Context, userID string) (int64, error)
|
GetCountByUserID(ctx context.Context, userID string) (int64, error)
|
||||||
GetByUserIDQuestionID(ctx context.Context, userID string, questionID string) (*entity.Answer, bool, error)
|
GetByUserIDQuestionID(ctx context.Context, userID string, questionID string) (*entity.Answer, bool, error)
|
||||||
SearchList(ctx context.Context, search *entity.AnswerSearch) ([]*entity.Answer, int64, error)
|
SearchList(ctx context.Context, search *entity.AnswerSearch) ([]*entity.Answer, int64, error)
|
||||||
AdminSearchList(ctx context.Context, search *entity.AdminAnswerSearch) ([]*entity.Answer, int64, error)
|
AdminSearchList(ctx context.Context, search *schema.AdminAnswerPageReq) ([]*entity.Answer, int64, error)
|
||||||
UpdateAnswerStatus(ctx context.Context, answer *entity.Answer) (err error)
|
UpdateAnswerStatus(ctx context.Context, answer *entity.Answer) (err error)
|
||||||
GetAnswerCount(ctx context.Context) (count int64, err error)
|
GetAnswerCount(ctx context.Context) (count int64, err error)
|
||||||
}
|
}
|
||||||
|
@ -45,11 +47,16 @@ func (as *AnswerCommon) SearchAnswered(ctx context.Context, userID, questionID s
|
||||||
return has, nil
|
return has, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *AnswerCommon) AdminSearchList(ctx context.Context, search *entity.AdminAnswerSearch) ([]*entity.Answer, int64, error) {
|
func (as *AnswerCommon) AdminSearchList(ctx context.Context, req *schema.AdminAnswerPageReq) (
|
||||||
if search.Status == 0 {
|
resp []*entity.Answer, count int64, err error) {
|
||||||
search.Status = 1
|
resp, count, err = as.answerRepo.AdminSearchList(ctx, req)
|
||||||
|
if handler.GetEnableShortID(ctx) {
|
||||||
|
for _, item := range resp {
|
||||||
|
item.ID = uid.EnShortID(item.ID)
|
||||||
|
item.QuestionID = uid.EnShortID(item.QuestionID)
|
||||||
}
|
}
|
||||||
return as.answerRepo.AdminSearchList(ctx, search)
|
}
|
||||||
|
return resp, count, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *AnswerCommon) Search(ctx context.Context, search *entity.AnswerSearch) ([]*entity.Answer, int64, error) {
|
func (as *AnswerCommon) Search(ctx context.Context, search *entity.AnswerSearch) ([]*entity.Answer, int64, error) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ type QuestionRepo interface {
|
||||||
UpdateAccepted(ctx context.Context, question *entity.Question) (err error)
|
UpdateAccepted(ctx context.Context, question *entity.Question) (err error)
|
||||||
UpdateLastAnswer(ctx context.Context, question *entity.Question) (err error)
|
UpdateLastAnswer(ctx context.Context, question *entity.Question) (err error)
|
||||||
FindByID(ctx context.Context, id []string) (questionList []*entity.Question, err error)
|
FindByID(ctx context.Context, id []string) (questionList []*entity.Question, err error)
|
||||||
AdminSearchList(ctx context.Context, search *schema.AdminQuestionSearch) ([]*entity.Question, int64, error)
|
AdminQuestionPage(ctx context.Context, search *schema.AdminQuestionPageReq) ([]*entity.Question, int64, error)
|
||||||
GetQuestionCount(ctx context.Context) (count int64, err error)
|
GetQuestionCount(ctx context.Context) (count int64, err error)
|
||||||
GetUserQuestionCount(ctx context.Context, userID string) (count int64, err error)
|
GetUserQuestionCount(ctx context.Context, userID string) (count int64, err error)
|
||||||
GetQuestionCountByIDs(ctx context.Context, ids []string) (count int64, err error)
|
GetQuestionCountByIDs(ctx context.Context, ids []string) (count int64, err error)
|
||||||
|
|
|
@ -1256,89 +1256,73 @@ func (qs *QuestionService) AdminSetQuestionStatus(ctx context.Context, questionI
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuestionService) AdminSearchList(ctx context.Context, search *schema.AdminQuestionSearch, loginUserID string) ([]*schema.AdminQuestionInfo, int64, error) {
|
func (qs *QuestionService) AdminQuestionPage(
|
||||||
|
ctx context.Context, req *schema.AdminQuestionPageReq) (
|
||||||
|
resp *pager.PageModel, err error) {
|
||||||
|
|
||||||
list := make([]*schema.AdminQuestionInfo, 0)
|
list := make([]*schema.AdminQuestionInfo, 0)
|
||||||
|
questionList, count, err := qs.questionRepo.AdminQuestionPage(ctx, req)
|
||||||
status, ok := entity.AdminQuestionSearchStatus[search.StatusStr]
|
|
||||||
if ok {
|
|
||||||
search.Status = status
|
|
||||||
}
|
|
||||||
|
|
||||||
if search.Status == 0 {
|
|
||||||
search.Status = 1
|
|
||||||
}
|
|
||||||
dblist, count, err := qs.questionRepo.AdminSearchList(ctx, search)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return list, count, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
userIds := make([]string, 0)
|
userIds := make([]string, 0)
|
||||||
for _, dbitem := range dblist {
|
for _, info := range questionList {
|
||||||
item := &schema.AdminQuestionInfo{}
|
item := &schema.AdminQuestionInfo{}
|
||||||
_ = copier.Copy(item, dbitem)
|
_ = copier.Copy(item, info)
|
||||||
item.CreateTime = dbitem.CreatedAt.Unix()
|
item.CreateTime = info.CreatedAt.Unix()
|
||||||
item.UpdateTime = dbitem.PostUpdateTime.Unix()
|
item.UpdateTime = info.PostUpdateTime.Unix()
|
||||||
item.EditTime = dbitem.UpdatedAt.Unix()
|
item.EditTime = info.UpdatedAt.Unix()
|
||||||
list = append(list, item)
|
list = append(list, item)
|
||||||
userIds = append(userIds, dbitem.UserID)
|
userIds = append(userIds, info.UserID)
|
||||||
}
|
}
|
||||||
userInfoMap, err := qs.userCommon.BatchUserBasicInfoByID(ctx, userIds)
|
userInfoMap, err := qs.userCommon.BatchUserBasicInfoByID(ctx, userIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return list, count, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, item := range list {
|
for _, item := range list {
|
||||||
_, ok = userInfoMap[item.UserID]
|
if u, ok := userInfoMap[item.UserID]; ok {
|
||||||
if ok {
|
item.UserInfo = u
|
||||||
item.UserInfo = userInfoMap[item.UserID]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return pager.NewPageModel(count, list), nil
|
||||||
|
}
|
||||||
|
|
||||||
return list, count, nil
|
// AdminAnswerPage search answer list
|
||||||
}
|
func (qs *QuestionService) AdminAnswerPage(ctx context.Context, req *schema.AdminAnswerPageReq) (
|
||||||
|
resp *pager.PageModel, err error) {
|
||||||
// AdminSearchList
|
answerList, count, err := qs.questioncommon.AnswerCommon.AdminSearchList(ctx, req)
|
||||||
func (qs *QuestionService) AdminSearchAnswerList(ctx context.Context, search *entity.AdminAnswerSearch, loginUserID string) ([]*schema.AdminAnswerInfo, int64, error) {
|
|
||||||
answerlist := make([]*schema.AdminAnswerInfo, 0)
|
|
||||||
|
|
||||||
status, ok := entity.AdminAnswerSearchStatus[search.StatusStr]
|
|
||||||
if ok {
|
|
||||||
search.Status = status
|
|
||||||
}
|
|
||||||
|
|
||||||
if search.Status == 0 {
|
|
||||||
search.Status = 1
|
|
||||||
}
|
|
||||||
dblist, count, err := qs.questioncommon.AnswerCommon.AdminSearchList(ctx, search)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return answerlist, count, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
questionIDs := make([]string, 0)
|
questionIDs := make([]string, 0)
|
||||||
userIds := make([]string, 0)
|
userIds := make([]string, 0)
|
||||||
for _, item := range dblist {
|
answerResp := make([]*schema.AdminAnswerInfo, 0)
|
||||||
answerinfo := qs.questioncommon.AnswerCommon.AdminShowFormat(ctx, item)
|
for _, item := range answerList {
|
||||||
answerlist = append(answerlist, answerinfo)
|
answerInfo := qs.questioncommon.AnswerCommon.AdminShowFormat(ctx, item)
|
||||||
|
answerResp = append(answerResp, answerInfo)
|
||||||
questionIDs = append(questionIDs, item.QuestionID)
|
questionIDs = append(questionIDs, item.QuestionID)
|
||||||
userIds = append(userIds, item.UserID)
|
userIds = append(userIds, item.UserID)
|
||||||
}
|
}
|
||||||
userInfoMap, err := qs.userCommon.BatchUserBasicInfoByID(ctx, userIds)
|
userInfoMap, err := qs.userCommon.BatchUserBasicInfoByID(ctx, userIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return answerlist, count, err
|
return nil, err
|
||||||
|
}
|
||||||
|
questionMaps, err := qs.questioncommon.FindInfoByID(ctx, questionIDs, req.LoginUserID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
questionMaps, err := qs.questioncommon.FindInfoByID(ctx, questionIDs, loginUserID)
|
for _, item := range answerResp {
|
||||||
if err != nil {
|
if q, ok := questionMaps[item.QuestionID]; ok {
|
||||||
return answerlist, count, err
|
item.QuestionInfo.Title = q.Title
|
||||||
}
|
}
|
||||||
for _, item := range answerlist {
|
if u, ok := userInfoMap[item.UserID]; ok {
|
||||||
_, ok := questionMaps[item.QuestionID]
|
item.UserInfo = u
|
||||||
if ok {
|
|
||||||
item.QuestionInfo.Title = questionMaps[item.QuestionID].Title
|
|
||||||
}
|
|
||||||
_, ok = userInfoMap[item.UserID]
|
|
||||||
if ok {
|
|
||||||
item.UserInfo = userInfoMap[item.UserID]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return answerlist, count, nil
|
return pager.NewPageModel(count, answerResp), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qs *QuestionService) changeQuestionToRevision(ctx context.Context, questionInfo *entity.Question, tags []*entity.Tag) (
|
func (qs *QuestionService) changeQuestionToRevision(ctx context.Context, questionInfo *entity.Question, tags []*entity.Tag) (
|
||||||
|
|
Loading…
Reference in New Issue