You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/03/21 02:13:57 UTC
(incubator-answer) branch feat/1.3.0/review updated: feat(review): add rank for reviewed user
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch feat/1.3.0/review
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git
The following commit(s) were added to refs/heads/feat/1.3.0/review by this push:
new 63a23340 feat(review): add rank for reviewed user
63a23340 is described below
commit 63a233401005e8a9ba866717ef98f254951ccc8a
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Thu Mar 21 10:13:39 2024 +0800
feat(review): add rank for reviewed user
---
cmd/wire_gen.go | 3 +-
i18n/en_US.yaml | 2 +
internal/repo/activity/review_repo.go | 125 ++++++++++++++++++++++++
internal/repo/provider.go | 1 +
internal/schema/activity.go | 9 ++
internal/service/activity/review_active.go | 31 ++++++
internal/service/activity_type/activity_type.go | 2 +
internal/service/content/revision_service.go | 26 +++++
8 files changed, 198 insertions(+), 1 deletion(-)
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index 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.yaml
index 0feac0b8..2c578418 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -496,6 +496,8 @@ backend:
other: accept
accepted:
other: accepted
+ edit:
+ other: edit
review:
queued_post:
other: Queued post
diff --git a/internal/repo/activity/review_repo.go b/internal/repo/activity/review_repo.go
new file mode 100644
index 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.go
index 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.go
index 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.go
new file mode 100644
index 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.go
index 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.go
index 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.ActivityQueueService
reportRepo report_common.ReportRepo
reviewService *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.Revisi
return 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
}