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.
feat(review): add rank for reviewed user
LinkinStars63a233401005
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.goindex 816d05f2..0bf0eb42 100644--- a/cmd/wire_gen.go+++ b/cmd/wire_gen.go@@ -195,7 +195,8 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,searchRepo := search_common.NewSearchRepo(dataData, uniqueIDRepo, userCommon, tagCommonService)searchService := content.NewSearchService(searchParser, searchRepo)searchController := controller.NewSearchController(searchService, captchaService)- contentRevisionService := content.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, notificationQueueService, activityQueueService, reportRepo, reviewService)+ reviewActivityRepo := activity.NewReviewActivityRepo(dataData, activityRepo, userRankRepo, configService)+ contentRevisionService := content.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, notificationQueueService, activityQueueService, reportRepo, reviewService, reviewActivityRepo)revisionController := controller.NewRevisionController(contentRevisionService, rankService)rankController := controller.NewRankController(rankService)userAdminRepo := user.NewUserAdminRepo(dataData, authRepo)diff --git a/i18n/en_US.yaml b/i18n/en_US.yamlindex 0feac0b8..2c578418 100644--- a/i18n/en_US.yaml+++ b/i18n/en_US.yaml@@ -496,6 +496,8 @@ backend:other: acceptaccepted:other: accepted+ edit:+ other: editreview:queued_post:other: Queued postdiff --git a/internal/repo/activity/review_repo.go b/internal/repo/activity/review_repo.gonew file mode 100644index 00000000..3325a762--- /dev/null+++ b/internal/repo/activity/review_repo.go@@ -0,0 +1,125 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one+ * or more contributor license agreements. See the NOTICE file+ * distributed with this work for additional information+ * regarding copyright ownership. The ASF licenses this file+ * to you under the Apache License, Version 2.0 (the+ * "License"); you may not use this file except in compliance+ * with the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing,+ * software distributed under the License is distributed on an+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+ * KIND, either express or implied. See the License for the+ * specific language governing permissions and limitations+ * under the License.+ */++package activity++import (+ "context"+ "fmt"++ "github.com/apache/incubator-answer/internal/schema"+ "github.com/apache/incubator-answer/pkg/converter"+ "xorm.io/builder"++ "github.com/apache/incubator-answer/internal/base/data"+ "github.com/apache/incubator-answer/internal/base/reason"+ "github.com/apache/incubator-answer/internal/entity"+ "github.com/apache/incubator-answer/internal/service/activity"+ "github.com/apache/incubator-answer/internal/service/activity_common"+ "github.com/apache/incubator-answer/internal/service/config"+ "github.com/apache/incubator-answer/internal/service/rank"+ "github.com/segmentfault/pacman/errors"+ "xorm.io/xorm"+)++// ReviewActivityRepo answer accepted+type ReviewActivityRepo struct {+ data *data.Data+ activityRepo activity_common.ActivityRepo+ userRankRepo rank.UserRankRepo+ configService *config.ConfigService+}++const (+ EditAccepted = "edit.accepted"+)++// NewReviewActivityRepo new repository+func NewReviewActivityRepo(+ data *data.Data,+ activityRepo activity_common.ActivityRepo,+ userRankRepo rank.UserRankRepo,+ configService *config.ConfigService,+) activity.ReviewActivityRepo {+ return &ReviewActivityRepo{+ data: data,+ activityRepo: activityRepo,+ userRankRepo: userRankRepo,+ configService: configService,+ }+}++// Review user active+func (ar *ReviewActivityRepo) Review(ctx context.Context, act *schema.PassReviewActivity) (err error) {+ cfg, err := ar.configService.GetConfigByKey(ctx, EditAccepted)+ if err != nil {+ return err+ }+ addActivity := &entity.Activity{+ UserID: act.UserID,+ TriggerUserID: converter.StringToInt64(act.TriggerUserID),+ ObjectID: act.ObjectID,+ OriginalObjectID: act.OriginalObjectID,+ ActivityType: cfg.ID,+ Rank: cfg.GetIntValue(),+ HasRank: 1,+ RevisionID: converter.StringToInt64(act.RevisionID),+ }++ _, err = ar.data.DB.Transaction(func(session *xorm.Session) (result any, err error) {+ session = session.Context(ctx)++ user := &entity.User{}+ exist, err := session.ID(addActivity.UserID).ForUpdate().Get(user)+ if err != nil {+ return nil, err+ }+ if !exist {+ return nil, fmt.Errorf("user not exist")+ }++ existsActivity := &entity.Activity{}+ exist, err = session.+ And(builder.Eq{"user_id": addActivity.UserID}).+ And(builder.Eq{"activity_type": addActivity.ActivityType}).+ And(builder.Eq{"revision_id": addActivity.RevisionID}).+ Get(existsActivity)+ if err != nil {+ return nil, err+ }+ if exist {+ return nil, nil+ }++ err = ar.userRankRepo.ChangeUserRank(ctx, session, addActivity.UserID, user.Rank, addActivity.Rank)+ if err != nil {+ return nil, err+ }++ _, err = session.Insert(addActivity)+ if err != nil {+ return nil, err+ }+ return nil, nil+ })+ if err != nil {+ return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()+ }+ return nil+}diff --git a/internal/repo/provider.go b/internal/repo/provider.goindex 041b6c87..3a517120 100644--- a/internal/repo/provider.go+++ b/internal/repo/provider.go@@ -76,6 +76,7 @@ var ProviderSetRepo = wire.NewSet(activity.NewAnswerActivityRepo,activity.NewUserActiveActivityRepo,activity.NewActivityRepo,+ activity.NewReviewActivityRepo,tag.NewTagRepo,tag_common.NewTagCommonRepo,tag.NewTagRelRepo,diff --git a/internal/schema/activity.go b/internal/schema/activity.goindex 66a6b188..2ec837aa 100644--- a/internal/schema/activity.go+++ b/internal/schema/activity.go@@ -101,3 +101,12 @@ type ObjectTimelineTag struct {Recommend bool `json:"recommend"`Reserved bool `json:"reserved"`}++// PassReviewActivity pass review activity+type PassReviewActivity struct {+ UserID string `json:"user_id"`+ TriggerUserID string `json:"trigger_user_id"`+ ObjectID string `json:"object_id"`+ OriginalObjectID string `json:"original_object_id"`+ RevisionID string `json:"revision_id"`+}diff --git a/internal/service/activity/review_active.go b/internal/service/activity/review_active.gonew file mode 100644index 00000000..0f0a9c24--- /dev/null+++ b/internal/service/activity/review_active.go@@ -0,0 +1,31 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one+ * or more contributor license agreements. See the NOTICE file+ * distributed with this work for additional information+ * regarding copyright ownership. The ASF licenses this file+ * to you under the Apache License, Version 2.0 (the+ * "License"); you may not use this file except in compliance+ * with the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing,+ * software distributed under the License is distributed on an+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+ * KIND, either express or implied. See the License for the+ * specific language governing permissions and limitations+ * under the License.+ */++package activity++import (+ "context"++ "github.com/apache/incubator-answer/internal/schema"+)++// ReviewActivityRepo interface+type ReviewActivityRepo interface {+ Review(ctx context.Context, sct *schema.PassReviewActivity) (err error)+}diff --git a/internal/service/activity_type/activity_type.go b/internal/service/activity_type/activity_type.goindex b41d0770..5db98041 100644--- a/internal/service/activity_type/activity_type.go+++ b/internal/service/activity_type/activity_type.go@@ -31,6 +31,7 @@ const (AnswerAccepted = "answer.accepted"AnswerAccept = "answer.accept"CommentVoteUp = "comment.vote_up"+ EditAccepted = "edit.accepted")var (@@ -70,5 +71,6 @@ var (AnswerAccepted: "action_activity_type.accepted",AnswerAccept: "action_activity_type.accept",CommentVoteUp: "action_activity_type.upvote",+ EditAccepted: "action_activity_type.edit",})diff --git a/internal/service/content/revision_service.go b/internal/service/content/revision_service.goindex 715d30cc..b69a0568 100644--- a/internal/service/content/revision_service.go+++ b/internal/service/content/revision_service.go@@ -31,6 +31,7 @@ import ("github.com/apache/incubator-answer/internal/base/translator""github.com/apache/incubator-answer/internal/entity""github.com/apache/incubator-answer/internal/schema"+ "github.com/apache/incubator-answer/internal/service/activity""github.com/apache/incubator-answer/internal/service/activity_queue"answercommon "github.com/apache/incubator-answer/internal/service/answer_common""github.com/apache/incubator-answer/internal/service/notice_queue"@@ -66,6 +67,7 @@ type RevisionService struct {activityQueueService activity_queue.ActivityQueueServicereportRepo report_common.ReportReporeviewService *review.ReviewService+ reviewActivity activity.ReviewActivityRepo}func NewRevisionService(@@ -82,6 +84,7 @@ func NewRevisionService(activityQueueService activity_queue.ActivityQueueService,reportRepo report_common.ReportRepo,reviewService *review.ReviewService,+ reviewActivity activity.ReviewActivityRepo,) *RevisionService {return &RevisionService{revisionRepo: revisionRepo,@@ -97,6 +100,7 @@ func NewRevisionService(activityQueueService: activityQueueService,reportRepo: reportRepo,reviewService: reviewService,+ reviewActivity: reviewActivity,}}@@ -148,6 +152,28 @@ func (rs *RevisionService) RevisionAudit(ctx context.Context, req *schema.Revisireturn saveErr}err = rs.revisionRepo.UpdateStatus(ctx, req.ID, entity.RevisionReviewPassStatus, req.UserID)+ if err != nil {+ return err+ }+ err = rs.reviewActivity.Review(ctx, &schema.PassReviewActivity{+ UserID: revisioninfo.UserID,+ TriggerUserID: req.UserID,+ ObjectID: revisioninfo.ObjectID,+ OriginalObjectID: "0",+ RevisionID: revisioninfo.ID,+ })+ if err != nil {+ log.Errorf("add review activity failed: %v", err)+ }++ msg := &schema.NotificationMsg{+ TriggerUserID: req.UserID,+ ReceiverUserID: revisioninfo.UserID,+ Type: schema.NotificationTypeAchievement,+ ObjectID: revisioninfo.ObjectID,+ ObjectType: objectType,+ }+ rs.notificationQueueService.Send(ctx, msg)return}