mirror of https://gitee.com/answerdev/answer.git
update question pin show
This commit is contained in:
parent
766bf793c4
commit
0de09c5305
|
@ -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 (
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue