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 tags

aichy12625ccd8f717a4
diff --git a/internal/migrations/v13.go b/internal/migrations/v13.go
index ddef599c..843f5dd0 100644
--- a/internal/migrations/v13.go
+++ b/internal/migrations/v13.go
@@ -9,7 +9,7 @@ import (
)
func updateQuestionCount(x *xorm.Engine) error {
- //search all answers
+ //question answer count
answers := make([]entity.Answer, 0)
err := x.Find(&answers, &entity.Answer{Status: entity.AnswerStatusAvailable})
if err != nil {
@@ -39,5 +39,12 @@ func updateQuestionCount(x *xorm.Engine) error {
}
}
}
+
+ //tag question count
+
+ //user question count
+
+ //user answer count
+
return nil
}
diff --git a/internal/service/question_service.go b/internal/service/question_service.go
index b47ffba9..f9158b3c 100644
--- a/internal/service/question_service.go
+++ b/internal/service/question_service.go
@@ -436,6 +436,25 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Remov
}
}
+ //tag count
+ tagIDs := make([]string, 0)
+ Tags, tagerr := qs.tagCommon.GetObjectEntityTag(ctx, req.ID)
+ if tagerr != nil {
+ log.Error("GetObjectEntityTag error", tagerr)
+ return nil
+ }
+ for _, v := range Tags {
+ tagIDs = append(tagIDs, v.ID)
+ }
+ err = qs.tagCommon.RemoveTagRelListByObjectID(ctx, req.ID)
+ if err != nil {
+ log.Error("RemoveTagRelListByObjectID error", err.Error())
+ }
+ err = qs.tagCommon.RefreshTagQuestionCount(ctx, tagIDs)
+ if err != nil {
+ log.Error("efreshTagQuestionCount error", err.Error())
+ }
+
err = qs.answerActivityService.DeleteQuestion(ctx, questionInfo.ID, questionInfo.CreatedAt, questionInfo.VoteCount)
if err != nil {
log.Errorf("user DeleteQuestion rank rollback error %s", err.Error())
diff --git a/internal/service/tag_common/tag_common.go b/internal/service/tag_common/tag_common.go
index c136838e..51ecbddb 100644
--- a/internal/service/tag_common/tag_common.go
+++ b/internal/service/tag_common/tag_common.go
@@ -44,6 +44,7 @@ type TagRepo interface {
type TagRelRepo interface {
AddTagRelList(ctx context.Context, tagList []*entity.TagRel) (err error)
+ RemoveTagRelListByObjectID(ctx context.Context, objectID string) (err error)
RemoveTagRelListByIDs(ctx context.Context, ids []int64) (err error)
EnableTagRelByIDs(ctx context.Context, ids []int64) (err error)
GetObjectTagRelWithoutStatus(ctx context.Context, objectId, tagID string) (tagRel *entity.TagRel, exist bool, err error)
@@ -653,6 +654,11 @@ func (ts *TagCommonService) RefreshTagQuestionCount(ctx context.Context, tagIDs
return nil
}
+// RemoveTagRelListByObjectID remove tag relation by object id
+func (ts *TagCommonService) RemoveTagRelListByObjectID(ctx context.Context, objectID string) (err error) {
+ return ts.tagRelRepo.RemoveTagRelListByObjectID(ctx, objectID)
+}
+
// CreateOrUpdateTagRelList if tag relation is exists update status, if not create it
func (ts *TagCommonService) CreateOrUpdateTagRelList(ctx context.Context, objectId string, tagIDs []string) (err error) {
addTagIDMapping := make(map[string]bool)