Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

update question pin show

aichy1260de09c53050f
diff --git a/internal/base/constant/acticity.go b/internal/base/constant/acticity.go
index 8300147b..b0db1f46 100644
--- a/internal/base/constant/acticity.go
+++ b/internal/base/constant/acticity.go
@@ -29,6 +29,10 @@ const (
ActQuestionRollback ActivityTypeKey = "question.rollback"
ActQuestionDeleted ActivityTypeKey = "question.deleted"
ActQuestionUndeleted ActivityTypeKey = "question.undeleted"
+ ActQuestionPin ActivityTypeKey = "question.pin"
+ ActQuestionUnPin ActivityTypeKey = "question.unpin"
+ ActQuestionHide ActivityTypeKey = "question.hide"
+ ActQuestionShow ActivityTypeKey = "question.show"
)
const (
diff --git a/internal/controller/question_controller.go b/internal/controller/question_controller.go
index 97052183..5c9d2e25 100644
--- a/internal/controller/question_controller.go
+++ b/internal/controller/question_controller.go
@@ -105,8 +105,8 @@ func (qc *QuestionController) OperationQuestion(ctx *gin.Context) {
handler.HandleResponse(ctx, errors.Forbidden(reason.RankFailToMeetTheCondition), nil)
return
}
-
- handler.HandleResponse(ctx, nil, nil)
+ err = qc.questionService.OperationQuestion(ctx, req)
+ handler.HandleResponse(ctx, err, nil)
}
// CloseQuestion Close question
diff --git a/internal/repo/question/question_repo.go b/internal/repo/question/question_repo.go
index 5c05dd19..c22a97d6 100644
--- a/internal/repo/question/question_repo.go
+++ b/internal/repo/question/question_repo.go
@@ -125,6 +125,15 @@ func (qr *questionRepo) UpdateQuestionStatusWithOutUpdateTime(ctx context.Contex
return nil
}
+func (qr *questionRepo) UpdateQuestionOperation(ctx context.Context, question *entity.Question) (err error) {
+ question.ID = uid.DeShortID(question.ID)
+ _, err = qr.data.DB.Where("id =?", question.ID).Cols("pin", "show").Update(question)
+ if err != nil {
+ return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
+ }
+ return nil
+}
+
func (qr *questionRepo) UpdateAccepted(ctx context.Context, question *entity.Question) (err error) {
question.ID = uid.DeShortID(question.ID)
_, err = qr.data.DB.Where("id =?", question.ID).Cols("accepted_answer_id").Update(question)
diff --git a/internal/service/question_common/question.go b/internal/service/question_common/question.go
index 38ae8a9d..842670f4 100644
--- a/internal/service/question_common/question.go
+++ b/internal/service/question_common/question.go
@@ -36,6 +36,7 @@ type QuestionRepo interface {
questionList []*entity.Question, total int64, err error)
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)
UpdatePvCount(ctx context.Context, questionID string) (err error)
UpdateAnswerCount(ctx context.Context, questionID string, num int) (err error)
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index f3f8d546..b59e97d5 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -319,6 +319,59 @@ func (qs *QuestionService) AddQuestion(ctx context.Context, req *schema.Question
return
}
+// OperationQuestion
+func (qs *QuestionService) OperationQuestion(ctx context.Context, req *schema.OperationQuestionReq) (err error) {
+ questionInfo, has, err := qs.questionRepo.GetQuestion(ctx, req.ID)
+ if err != nil {
+ return err
+ }
+ if !has {
+ return nil
+ }
+ // Hidden question cannot be placed at the top
+ if questionInfo.Show == entity.QuestionHide && req.Operation == schema.QuestionOperationPin {
+ return nil
+ }
+ // Question cannot be hidden when they are at the top
+ if questionInfo.Pin == entity.QuestionPin && req.Operation == schema.QuestionOperationHide {
+ return nil
+ }
+
+ switch req.Operation {
+ case schema.QuestionOperationHide:
+ questionInfo.Show = entity.QuestionHide
+ case schema.QuestionOperationShow:
+ questionInfo.Show = entity.QuestionShow
+ case schema.QuestionOperationPin:
+ questionInfo.Pin = entity.QuestionPin
+ case schema.QuestionOperationUnPin:
+ questionInfo.Pin = entity.QuestionUnPin
+ }
+
+ err = qs.questionRepo.UpdateQuestionOperation(ctx, questionInfo)
+ if err != nil {
+ return err
+ }
+
+ actMap := make(map[string]constant.ActivityTypeKey)
+ actMap[schema.QuestionOperationPin] = constant.ActQuestionPin
+ actMap[schema.QuestionOperationUnPin] = constant.ActQuestionUnPin
+ actMap[schema.QuestionOperationHide] = constant.ActQuestionHide
+ actMap[schema.QuestionOperationShow] = constant.ActQuestionShow
+
+ _, ok := actMap[req.Operation]
+ if !ok {
+ activity_queue.AddActivity(&schema.ActivityMsg{
+ UserID: req.UserID,
+ ObjectID: questionInfo.ID,
+ OriginalObjectID: questionInfo.ID,
+ ActivityTypeKey: actMap[req.Operation],
+ })
+ }
+
+ return nil
+}
+
// RemoveQuestion delete question
func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.RemoveQuestionReq) (err error) {
questionInfo, has, err := qs.questionRepo.GetQuestion(ctx, req.ID)