fix(question): remove delete question on similar questions

This commit is contained in:
LinkinStars 2023-08-28 15:27:17 +08:00
parent c68eff2011
commit 9337f69154
5 changed files with 28 additions and 21 deletions

View File

@ -686,9 +686,9 @@ func (qc *QuestionController) UpdateQuestionInviteUser(ctx *gin.Context) {
handler.HandleResponse(ctx, nil, nil)
}
// SearchByTitleLike add question title like
// @Summary add question title like
// @Description add question title like
// GetSimilarQuestions fuzzy query similar questions based on title
// @Summary fuzzy query similar questions based on title
// @Description fuzzy query similar questions based on title
// @Tags Question
// @Accept json
// @Produce json
@ -696,10 +696,9 @@ func (qc *QuestionController) UpdateQuestionInviteUser(ctx *gin.Context) {
// @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) {
func (qc *QuestionController) GetSimilarQuestions(ctx *gin.Context) {
title := ctx.Query("title")
userID := middleware.GetLoginUserIDFromContext(ctx)
resp, err := qc.questionService.SearchByTitleLike(ctx, title, userID)
resp, err := qc.questionService.GetQuestionsByTitle(ctx, title)
handler.HandleResponse(ctx, err, resp)
}

View File

@ -186,10 +186,15 @@ func (qr *questionRepo) GetQuestion(ctx context.Context, id string) (
return
}
// GetTagBySlugName get tag by slug name
func (qr *questionRepo) SearchByTitleLike(ctx context.Context, title string) (questionList []*entity.Question, err error) {
// GetQuestionsByTitle get question list by title
func (qr *questionRepo) GetQuestionsByTitle(ctx context.Context, title string, pageSize int) (
questionList []*entity.Question, err error) {
questionList = make([]*entity.Question, 0)
err = qr.data.DB.Context(ctx).Table("question").Where("title like ?", "%"+title+"%").Limit(10, 0).Find(&questionList)
session := qr.data.DB.Context(ctx)
session.Where("status != ?", entity.QuestionStatusDeleted)
session.Where("title like ?", "%"+title+"%")
session.Limit(pageSize)
err = session.Find(&questionList)
if err != nil {
return nil, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}

View File

@ -203,7 +203,7 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
r.PUT("/question/status", a.questionController.CloseQuestion)
r.PUT("/question/operation", a.questionController.OperationQuestion)
r.PUT("/question/reopen", a.questionController.ReopenQuestion)
r.GET("/question/similar", a.questionController.SearchByTitleLike)
r.GET("/question/similar", a.questionController.GetSimilarQuestions)
// answer
r.POST("/answer", a.answerController.Add)

View File

@ -40,7 +40,7 @@ type QuestionRepo interface {
UpdateQuestionStatus(ctx context.Context, question *entity.Question) (err error)
UpdateQuestionStatusWithOutUpdateTime(ctx context.Context, question *entity.Question) (err error)
UpdateQuestionOperation(ctx context.Context, question *entity.Question) (err error)
SearchByTitleLike(ctx context.Context, title string) (questionList []*entity.Question, err error)
GetQuestionsByTitle(ctx context.Context, title string, pageSize int) (questionList []*entity.Question, err error)
UpdatePvCount(ctx context.Context, questionID string) (err error)
UpdateAnswerCount(ctx context.Context, questionID string, num int) (err error)
UpdateCollectionCount(ctx context.Context, questionID string, num int) (err error)

View File

@ -1103,14 +1103,18 @@ func (qs *QuestionService) SearchUserTopList(ctx context.Context, userName strin
return userQuestionlist, userAnswerlist, nil
}
// SearchByTitleLike
func (qs *QuestionService) SearchByTitleLike(ctx context.Context, title string, loginUserID string) ([]*schema.QuestionBaseInfo, error) {
list := make([]*schema.QuestionBaseInfo, 0)
dblist, err := qs.questionRepo.SearchByTitleLike(ctx, title)
if err != nil {
return list, err
// GetQuestionsByTitle get questions by title
func (qs *QuestionService) GetQuestionsByTitle(ctx context.Context, title string) (
resp []*schema.QuestionBaseInfo, err error) {
resp = make([]*schema.QuestionBaseInfo, 0)
if len(title) == 0 {
return resp, nil
}
for _, question := range dblist {
questions, err := qs.questionRepo.GetQuestionsByTitle(ctx, title, 10)
if err != nil {
return resp, err
}
for _, question := range questions {
item := &schema.QuestionBaseInfo{}
item.ID = question.ID
item.Title = question.Title
@ -1125,10 +1129,9 @@ func (qs *QuestionService) SearchByTitleLike(ctx context.Context, title string,
if question.AcceptedAnswerID != "0" {
item.AcceptedAnswer = true
}
list = append(list, item)
resp = append(resp, item)
}
return list, nil
return resp, nil
}
// SimilarQuestion