2022-09-27 17:59:05 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/base/handler"
|
|
|
|
"github.com/answerdev/answer/internal/base/middleware"
|
|
|
|
"github.com/answerdev/answer/internal/base/reason"
|
2022-12-13 18:10:35 +08:00
|
|
|
"github.com/answerdev/answer/internal/base/validator"
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/entity"
|
|
|
|
"github.com/answerdev/answer/internal/schema"
|
|
|
|
"github.com/answerdev/answer/internal/service"
|
2022-12-02 15:08:18 +08:00
|
|
|
"github.com/answerdev/answer/internal/service/permission"
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/service/rank"
|
|
|
|
"github.com/answerdev/answer/pkg/converter"
|
2022-09-27 17:59:05 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/segmentfault/pacman/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// QuestionController question controller
|
|
|
|
type QuestionController struct {
|
|
|
|
questionService *service.QuestionService
|
|
|
|
rankService *rank.RankService
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewQuestionController new controller
|
|
|
|
func NewQuestionController(questionService *service.QuestionService, rankService *rank.RankService) *QuestionController {
|
|
|
|
return &QuestionController{questionService: questionService, rankService: rankService}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveQuestion delete question
|
|
|
|
// @Summary delete question
|
|
|
|
// @Description delete question
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.RemoveQuestionReq true "question"
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/question [delete]
|
|
|
|
func (qc *QuestionController) RemoveQuestion(ctx *gin.Context) {
|
|
|
|
req := &schema.RemoveQuestionReq{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
2022-11-24 15:24:04 +08:00
|
|
|
req.IsAdmin = middleware.GetIsAdminFromContext(ctx)
|
2022-12-02 15:08:18 +08:00
|
|
|
can, err := qc.rankService.CheckOperationPermission(ctx, req.UserID, permission.QuestionDelete, req.ID)
|
2022-11-24 18:00:30 +08:00
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !can {
|
|
|
|
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
2022-09-27 17:59:05 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-24 18:00:30 +08:00
|
|
|
err = qc.questionService.RemoveQuestion(ctx, req)
|
2022-09-27 17:59:05 +08:00
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CloseQuestion Close question
|
|
|
|
// @Summary Close question
|
|
|
|
// @Description Close question
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.CloseQuestionReq true "question"
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/question/status [put]
|
|
|
|
func (qc *QuestionController) CloseQuestion(ctx *gin.Context) {
|
|
|
|
req := &schema.CloseQuestionReq{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
2022-11-01 15:25:44 +08:00
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
2022-12-02 17:24:46 +08:00
|
|
|
can, err := qc.rankService.CheckOperationPermission(ctx, req.UserID, permission.QuestionClose, "")
|
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !can {
|
|
|
|
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = qc.questionService.CloseQuestion(ctx, req)
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReopenQuestion reopen question
|
|
|
|
// @Summary reopen question
|
|
|
|
// @Description reopen question
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.ReopenQuestionReq true "question"
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/question/reopen [put]
|
|
|
|
func (qc *QuestionController) ReopenQuestion(ctx *gin.Context) {
|
|
|
|
req := &schema.ReopenQuestionReq{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
can, err := qc.rankService.CheckOperationPermission(ctx, req.UserID, permission.QuestionReopen, "")
|
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !can {
|
|
|
|
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = qc.questionService.ReopenQuestion(ctx, req)
|
2022-09-27 17:59:05 +08:00
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetQuestion godoc
|
|
|
|
// @Summary GetQuestion Question
|
|
|
|
// @Description GetQuestion Question
|
|
|
|
// @Tags api-question
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param id query string true "Question TagID" default(1)
|
|
|
|
// @Success 200 {string} string ""
|
|
|
|
// @Router /answer/api/v1/question/info [get]
|
2022-11-24 15:24:04 +08:00
|
|
|
func (qc *QuestionController) GetQuestion(ctx *gin.Context) {
|
|
|
|
id := ctx.Query("id")
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
2022-11-25 16:43:00 +08:00
|
|
|
req := schema.QuestionPermission{}
|
2022-11-25 12:07:56 +08:00
|
|
|
canList, err := qc.rankService.CheckOperationPermissions(ctx, userID, []string{
|
2022-12-02 15:08:18 +08:00
|
|
|
permission.QuestionEdit,
|
|
|
|
permission.QuestionDelete,
|
|
|
|
permission.QuestionClose,
|
|
|
|
permission.QuestionReopen,
|
2022-12-09 17:41:23 +08:00
|
|
|
})
|
2022-11-25 12:07:56 +08:00
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-12-09 17:41:23 +08:00
|
|
|
objectOwner := qc.rankService.CheckOperationObjectOwner(ctx, userID, id)
|
|
|
|
|
|
|
|
req.CanEdit = canList[0] || objectOwner
|
2022-11-25 14:55:56 +08:00
|
|
|
req.CanDelete = canList[1]
|
2022-12-02 15:08:18 +08:00
|
|
|
req.CanClose = canList[2]
|
|
|
|
req.CanReopen = canList[3]
|
2022-11-25 12:07:56 +08:00
|
|
|
|
|
|
|
info, err := qc.questionService.GetQuestionAndAddPV(ctx, id, userID, req)
|
2022-09-27 17:59:05 +08:00
|
|
|
if err != nil {
|
2022-11-24 15:24:04 +08:00
|
|
|
handler.HandleResponse(ctx, err, nil)
|
2022-09-27 17:59:05 +08:00
|
|
|
return
|
|
|
|
}
|
2022-11-24 15:24:04 +08:00
|
|
|
handler.HandleResponse(ctx, nil, info)
|
2022-09-27 17:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SimilarQuestion godoc
|
|
|
|
// @Summary Search Similar Question
|
|
|
|
// @Description Search Similar Question
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param question_id query string true "question_id" default()
|
|
|
|
// @Success 200 {string} string ""
|
|
|
|
// @Router /answer/api/v1/question/similar/tag [get]
|
|
|
|
func (qc *QuestionController) SimilarQuestion(ctx *gin.Context) {
|
|
|
|
questionID := ctx.Query("question_id")
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
list, count, err := qc.questionService.SimilarQuestion(ctx, questionID, userID)
|
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
handler.HandleResponse(ctx, nil, gin.H{
|
|
|
|
"list": list,
|
|
|
|
"count": count,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Index godoc
|
|
|
|
// @Summary SearchQuestionList
|
|
|
|
// @Description SearchQuestionList <br> "order" Enums(newest, active,frequent,score,unanswered)
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param data body schema.QuestionSearch true "QuestionSearch"
|
|
|
|
// @Success 200 {string} string ""
|
2022-10-12 17:12:17 +08:00
|
|
|
// @Router /answer/api/v1/question/page [get]
|
2022-09-27 17:59:05 +08:00
|
|
|
func (qc *QuestionController) Index(ctx *gin.Context) {
|
|
|
|
req := &schema.QuestionSearch{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
list, count, err := qc.questionService.SearchList(ctx, req, userID)
|
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
handler.HandleResponse(ctx, nil, gin.H{
|
|
|
|
"list": list,
|
|
|
|
"count": count,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// SearchList godoc
|
|
|
|
// @Summary SearchQuestionList
|
|
|
|
// @Description SearchQuestionList
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param data body schema.QuestionSearch true "QuestionSearch"
|
|
|
|
// @Router /answer/api/v1/question/search [post]
|
|
|
|
// @Success 200 {string} string ""
|
|
|
|
func (qc *QuestionController) SearchList(c *gin.Context) {
|
|
|
|
Request := new(schema.QuestionSearch)
|
|
|
|
err := c.BindJSON(Request)
|
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(c, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(c)
|
|
|
|
list, count, err := qc.questionService.SearchList(ctx, Request, userID)
|
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(c, err, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
handler.HandleResponse(c, nil, gin.H{
|
|
|
|
"list": list,
|
|
|
|
"count": count,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddQuestion add question
|
|
|
|
// @Summary add question
|
|
|
|
// @Description add question
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.QuestionAdd true "question"
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/question [post]
|
|
|
|
func (qc *QuestionController) AddQuestion(ctx *gin.Context) {
|
|
|
|
req := &schema.QuestionAdd{}
|
2022-12-13 18:10:35 +08:00
|
|
|
errFields := handler.BindAndCheckReturnErr(ctx, req)
|
|
|
|
if ctx.IsAborted() {
|
2022-09-27 17:59:05 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
|
2022-11-25 12:07:56 +08:00
|
|
|
canList, err := qc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
2022-12-02 15:08:18 +08:00
|
|
|
permission.QuestionAdd,
|
|
|
|
permission.QuestionEdit,
|
|
|
|
permission.QuestionDelete,
|
|
|
|
permission.QuestionClose,
|
|
|
|
permission.QuestionReopen,
|
2022-12-09 17:41:23 +08:00
|
|
|
permission.TagUseReservedTag,
|
|
|
|
})
|
2022-11-24 18:00:30 +08:00
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-11-25 12:07:56 +08:00
|
|
|
req.CanAdd = canList[0]
|
|
|
|
req.CanEdit = canList[1]
|
|
|
|
req.CanDelete = canList[2]
|
2022-12-02 15:08:18 +08:00
|
|
|
req.CanClose = canList[3]
|
|
|
|
req.CanReopen = canList[4]
|
2022-12-09 17:41:23 +08:00
|
|
|
req.CanUseReservedTag = canList[5]
|
2022-11-25 12:07:56 +08:00
|
|
|
if !req.CanAdd {
|
2022-11-24 18:00:30 +08:00
|
|
|
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
2022-09-27 17:59:05 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := qc.questionService.AddQuestion(ctx, req)
|
2022-12-13 18:10:35 +08:00
|
|
|
if err != nil {
|
|
|
|
errlist, ok := resp.([]*validator.FormErrorField)
|
|
|
|
if ok {
|
|
|
|
for _, item := range errlist {
|
|
|
|
errFields = append(errFields, item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(errFields) > 0 {
|
|
|
|
handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), errFields)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-27 17:59:05 +08:00
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateQuestion update question
|
|
|
|
// @Summary update question
|
|
|
|
// @Description update question
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.QuestionUpdate true "question"
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/question [put]
|
|
|
|
func (qc *QuestionController) UpdateQuestion(ctx *gin.Context) {
|
|
|
|
req := &schema.QuestionUpdate{}
|
2022-12-09 10:55:53 +08:00
|
|
|
errFields := handler.BindAndCheckReturnErr(ctx, req)
|
|
|
|
if ctx.IsAborted() {
|
2022-09-27 17:59:05 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
2022-11-25 12:07:56 +08:00
|
|
|
|
2022-11-24 18:00:30 +08:00
|
|
|
canList, err := qc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
2022-12-02 15:08:18 +08:00
|
|
|
permission.QuestionEdit,
|
|
|
|
permission.QuestionDelete,
|
|
|
|
permission.QuestionEditWithoutReview,
|
2022-12-08 11:14:56 +08:00
|
|
|
permission.TagUseReservedTag,
|
2022-12-09 17:41:23 +08:00
|
|
|
})
|
2022-11-24 18:00:30 +08:00
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-12-09 17:41:23 +08:00
|
|
|
|
|
|
|
objectOwner := qc.rankService.CheckOperationObjectOwner(ctx, req.UserID, req.ID)
|
|
|
|
req.CanEdit = canList[0] || objectOwner
|
2022-11-25 16:43:00 +08:00
|
|
|
req.CanDelete = canList[1]
|
2022-12-09 17:41:23 +08:00
|
|
|
req.NoNeedReview = canList[2] || objectOwner
|
2022-12-08 11:14:56 +08:00
|
|
|
req.CanUseReservedTag = canList[3]
|
2022-11-25 12:07:56 +08:00
|
|
|
if !req.CanEdit {
|
2022-11-24 18:00:30 +08:00
|
|
|
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
|
2022-09-27 17:59:05 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-09 17:52:11 +08:00
|
|
|
errlist, err := qc.questionService.UpdateQuestionCheckTags(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
for _, item := range errlist {
|
|
|
|
errFields = append(errFields, item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(errFields) > 0 {
|
|
|
|
handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), errFields)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-08 11:14:56 +08:00
|
|
|
resp, err := qc.questionService.UpdateQuestion(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
handler.HandleResponse(ctx, nil, &schema.UpdateQuestionResp{WaitForReview: !req.NoNeedReview})
|
2022-09-27 17:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CloseMsgList close question msg list
|
|
|
|
// @Summary close question msg list
|
|
|
|
// @Description close question msg list
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/question/closemsglist [get]
|
|
|
|
func (qc *QuestionController) CloseMsgList(ctx *gin.Context) {
|
|
|
|
resp, err := qc.questionService.CloseMsgList(ctx, handler.GetLang(ctx))
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SearchByTitleLike add question title like
|
|
|
|
// @Summary add question title like
|
|
|
|
// @Description add question title like
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param title query string true "title" default(string)
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/question/similar [get]
|
|
|
|
func (qc *QuestionController) SearchByTitleLike(ctx *gin.Context) {
|
|
|
|
title := ctx.Query("title")
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
resp, err := qc.questionService.SearchByTitleLike(ctx, title, userID)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserTop godoc
|
|
|
|
// @Summary UserTop
|
|
|
|
// @Description UserTop
|
|
|
|
// @Tags api-question
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param username query string true "username" default(string)
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/api/v1/personal/qa/top [get]
|
|
|
|
func (qc *QuestionController) UserTop(ctx *gin.Context) {
|
|
|
|
userName := ctx.Query("username")
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
questionList, answerList, err := qc.questionService.SearchUserTopList(ctx, userName, userID)
|
|
|
|
handler.HandleResponse(ctx, err, gin.H{
|
|
|
|
"question": questionList,
|
|
|
|
"answer": answerList,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserList godoc
|
|
|
|
// @Summary UserList
|
|
|
|
// @Description UserList
|
|
|
|
// @Tags api-question
|
|
|
|
// @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)
|
|
|
|
// @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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserAnswerList godoc
|
|
|
|
// @Summary UserAnswerList
|
|
|
|
// @Description UserAnswerList
|
|
|
|
// @Tags api-answer
|
|
|
|
// @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)
|
|
|
|
// @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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserCollectionList godoc
|
|
|
|
// @Summary UserCollectionList
|
|
|
|
// @Description UserCollectionList
|
|
|
|
// @Tags Collection
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param page query string true "page" default(0)
|
|
|
|
// @Param pagesize query string true "pagesize" 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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// CmsSearchList godoc
|
|
|
|
// @Summary CmsSearchList
|
|
|
|
// @Description Status:[available,closed,deleted]
|
|
|
|
// @Tags admin
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param page query int false "page size"
|
|
|
|
// @Param page_size query int false "page size"
|
|
|
|
// @Param status query string false "user status" Enums(available, closed, deleted)
|
2022-11-01 09:12:12 +08:00
|
|
|
// @Param query query string false "question id or title"
|
2022-09-27 17:59:05 +08:00
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/admin/api/question/page [get]
|
|
|
|
func (qc *QuestionController) CmsSearchList(ctx *gin.Context) {
|
|
|
|
req := &schema.CmsQuestionSearch{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
questionList, count, err := qc.questionService.CmsSearchList(ctx, req, userID)
|
|
|
|
handler.HandleResponse(ctx, err, gin.H{
|
|
|
|
"list": questionList,
|
|
|
|
"count": count,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// CmsSearchAnswerList godoc
|
|
|
|
// @Summary CmsSearchList
|
|
|
|
// @Description Status:[available,deleted]
|
|
|
|
// @Tags admin
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param page query int false "page size"
|
|
|
|
// @Param page_size query int false "page size"
|
|
|
|
// @Param status query string false "user status" Enums(available,deleted)
|
2022-11-01 09:12:12 +08:00
|
|
|
// @Param query query string false "answer id or question title"
|
2022-11-01 18:15:18 +08:00
|
|
|
// @Param question_id query string false "question id"
|
2022-09-27 17:59:05 +08:00
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
// @Router /answer/admin/api/answer/page [get]
|
|
|
|
func (qc *QuestionController) CmsSearchAnswerList(ctx *gin.Context) {
|
|
|
|
req := &entity.CmsAnswerSearch{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
questionList, count, err := qc.questionService.CmsSearchAnswerList(ctx, req, userID)
|
|
|
|
handler.HandleResponse(ctx, err, gin.H{
|
|
|
|
"list": questionList,
|
|
|
|
"count": count,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// AdminSetQuestionStatus godoc
|
|
|
|
// @Summary AdminSetQuestionStatus
|
|
|
|
// @Description Status:[available,closed,deleted]
|
|
|
|
// @Tags admin
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param data body schema.AdminSetQuestionStatusRequest true "AdminSetQuestionStatusRequest"
|
|
|
|
// @Router /answer/admin/api/question/status [put]
|
|
|
|
// @Success 200 {object} handler.RespBody
|
|
|
|
func (qc *QuestionController) AdminSetQuestionStatus(ctx *gin.Context) {
|
|
|
|
req := &schema.AdminSetQuestionStatusRequest{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err := qc.questionService.AdminSetQuestionStatus(ctx, req.QuestionID, req.StatusStr)
|
|
|
|
handler.HandleResponse(ctx, err, gin.H{})
|
|
|
|
}
|