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 API about reviewing type
LinkinStars34e56f3e81e7
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.goindex 199c2ce9..96bdade4 100644--- a/cmd/wire_gen.go+++ b/cmd/wire_gen.go@@ -1,28 +1,8 @@-//go:build !wireinject-// +build !wireinject--/*- * 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.- */-// Code generated by Wire. DO NOT EDIT.//go:generate go run github.com/google/wire/cmd/wire+//go:build !wireinject+// +build !wireinjectpackage answercmd@@ -210,7 +190,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,searchRepo := search_common.NewSearchRepo(dataData, uniqueIDRepo, userCommon, tagCommonService)searchService := service.NewSearchService(searchParser, searchRepo)searchController := controller.NewSearchController(searchService, captchaService)- serviceRevisionService := service.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, notificationQueueService, activityQueueService)+ serviceRevisionService := service.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, notificationQueueService, activityQueueService, reportRepo)revisionController := controller.NewRevisionController(serviceRevisionService, rankService)rankController := controller.NewRankController(rankService)reportHandle := report_handle_admin.NewReportHandle(questionCommon, commentRepo, configService, notificationQueueService)diff --git a/internal/base/constant/revision.go b/internal/base/constant/revision.gonew file mode 100644index 00000000..ac65c487--- /dev/null+++ b/internal/base/constant/revision.go@@ -0,0 +1,11 @@+package constant++type ReviewingType string++const (+ QueuedPost ReviewingType = "queued_post"+ QueuedUser ReviewingType = "queued_user"+ FlaggedPost ReviewingType = "flagged_post"+ FlaggedUser ReviewingType = "flagged_user"+ SuggestedPostEdit ReviewingType = "suggested_post_edit"+)diff --git a/internal/controller/revision_controller.go b/internal/controller/revision_controller.goindex 7bc892cd..a9d9164f 100644--- a/internal/controller/revision_controller.go+++ b/internal/controller/revision_controller.go@@ -191,3 +191,32 @@ func (rc *RevisionController) CheckCanUpdateRevision(ctx *gin.Context) {resp, err := rc.revisionListService.CheckCanUpdateRevision(ctx, req)handler.HandleResponse(ctx, err, resp)}++// GetReviewingType get reviewing type+// @Summary get reviewing type+// @Description get reviewing type+// @Tags Revision+// @Produce json+// @Security ApiKeyAuth+// @Success 200 {object} handler.RespBody{data=[]schema.GetReviewingTypeResp}+// @Router /answer/api/v1/reviewing/type [get]+func (rc *RevisionController) GetReviewingType(ctx *gin.Context) {+ req := &schema.GetReviewingTypeReq{}+ req.UserID = middleware.GetLoginUserIDFromContext(ctx)+ canList, err := rc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{+ permission.QuestionAudit,+ permission.AnswerAudit,+ permission.TagAudit,+ })+ if err != nil {+ handler.HandleResponse(ctx, err, nil)+ return+ }+ req.CanReviewQuestion = canList[0]+ req.CanReviewAnswer = canList[1]+ req.CanReviewTag = canList[2]+ req.IsAdmin = middleware.GetUserIsAdminModerator(ctx)++ resp, err := rc.revisionListService.GetReviewingType(ctx, req)+ handler.HandleResponse(ctx, err, resp)+}diff --git a/internal/repo/revision/revision_repo.go b/internal/repo/revision/revision_repo.goindex 958e6d7e..eba23251 100644--- a/internal/repo/revision/revision_repo.go+++ b/internal/repo/revision/revision_repo.go@@ -206,3 +206,18 @@ func (rr *revisionRepo) GetUnreviewedRevisionPage(ctx context.Context, page int,}return}++// CountUnreviewedRevision get unreviewed revision count+func (rr *revisionRepo) CountUnreviewedRevision(ctx context.Context, objectTypeList []int) (count int64, err error) {+ if len(objectTypeList) == 0 {+ return 0, nil+ }+ session := rr.data.DB.Context(ctx)+ session = session.And("status = ?", entity.RevisionUnreviewedStatus)+ session = session.In("object_type", objectTypeList)+ count, err = session.Count(&entity.Revision{})+ if err != nil {+ err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()+ }+ return+}diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.goindex 7e856903..0469103e 100644--- a/internal/router/answer_api_router.go+++ b/internal/router/answer_api_router.go@@ -194,6 +194,7 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {r.GET("/revisions/unreviewed", a.revisionController.GetUnreviewedRevisionList)r.PUT("/revisions/audit", a.revisionController.RevisionAudit)r.GET("/revisions/edit/check", a.revisionController.CheckCanUpdateRevision)+ r.GET("/reviewing/type", a.revisionController.GetReviewingType)// commentr.POST("/comment", a.commentController.AddComment)diff --git a/internal/schema/revision_schema.go b/internal/schema/revision_schema.goindex d52c1c4a..04b3439f 100644--- a/internal/schema/revision_schema.go+++ b/internal/schema/revision_schema.go@@ -112,3 +112,33 @@ type GetRevisionResp struct {UserInfo UserBasicInfo `json:"user_info"`Log string `json:"reason"`}++// GetReviewingTypeReq get reviewing type request+type GetReviewingTypeReq struct {+ CanReviewQuestion bool `json:"-"`+ CanReviewAnswer bool `json:"-"`+ CanReviewTag bool `json:"-"`+ IsAdmin bool `json:"-"`+ UserID string `json:"-"`+}++func (r *GetReviewingTypeReq) GetCanReviewObjectTypes() []int {+ objectType := make([]int, 0)+ if r.CanReviewAnswer {+ objectType = append(objectType, constant.ObjectTypeStrMapping[constant.AnswerObjectType])+ }+ if r.CanReviewQuestion {+ objectType = append(objectType, constant.ObjectTypeStrMapping[constant.QuestionObjectType])+ }+ if r.CanReviewTag {+ objectType = append(objectType, constant.ObjectTypeStrMapping[constant.TagObjectType])+ }+ return objectType+}++// GetReviewingTypeResp get reviewing type response+type GetReviewingTypeResp struct {+ Name string `json:"name"`+ Label string `json:"label"`+ TodoAmount int64 `json:"todo_amount"`+}diff --git a/internal/service/revision/revision.go b/internal/service/revision/revision.goindex 658c92f6..6844054b 100644--- a/internal/service/revision/revision.go+++ b/internal/service/revision/revision.go@@ -35,5 +35,6 @@ type RevisionRepo interface {UpdateObjectRevisionId(ctx context.Context, revision *entity.Revision, session *xorm.Session) (err error)ExistUnreviewedByObjectID(ctx context.Context, objectID string) (revision *entity.Revision, exist bool, err error)GetUnreviewedRevisionPage(ctx context.Context, page, pageSize int, objectTypes []int) ([]*entity.Revision, int64, error)+ CountUnreviewedRevision(ctx context.Context, objectTypeList []int) (count int64, err error)UpdateStatus(ctx context.Context, id string, status int, reviewUserID string) (err error)}diff --git a/internal/service/revision_service.go b/internal/service/revision_service.goindex 552bccd4..9479a2c6 100644--- a/internal/service/revision_service.go+++ b/internal/service/revision_service.go@@ -34,6 +34,7 @@ import ("github.com/apache/incubator-answer/internal/service/notice_queue""github.com/apache/incubator-answer/internal/service/object_info"questioncommon "github.com/apache/incubator-answer/internal/service/question_common"+ "github.com/apache/incubator-answer/internal/service/report_common""github.com/apache/incubator-answer/internal/service/revision""github.com/apache/incubator-answer/internal/service/tag_common"tagcommon "github.com/apache/incubator-answer/internal/service/tag_common"@@ -58,6 +59,7 @@ type RevisionService struct {tagCommon *tagcommon.TagCommonServicenotificationQueueService notice_queue.NotificationQueueServiceactivityQueueService activity_queue.ActivityQueueService+ reportRepo report_common.ReportRepo}func NewRevisionService(@@ -72,6 +74,7 @@ func NewRevisionService(tagCommon *tagcommon.TagCommonService,notificationQueueService notice_queue.NotificationQueueService,activityQueueService activity_queue.ActivityQueueService,+ reportRepo report_common.ReportRepo,) *RevisionService {return &RevisionService{revisionRepo: revisionRepo,@@ -85,6 +88,7 @@ func NewRevisionService(tagCommon: tagCommon,notificationQueueService: notificationQueueService,activityQueueService: activityQueueService,+ reportRepo: reportRepo,}}@@ -442,3 +446,42 @@ func (rs *RevisionService) CheckCanUpdateRevision(ctx context.Context, req *sche}return nil, nil}++// GetReviewingType get reviewing type+func (rs *RevisionService) GetReviewingType(ctx context.Context, req *schema.GetReviewingTypeReq) (resp []*schema.GetReviewingTypeResp, err error) {+ resp = make([]*schema.GetReviewingTypeResp, 0)++ // TODO: get queue amount+ resp = append(resp, &schema.GetReviewingTypeResp{+ Name: string(constant.QueuedPost),+ Label: "",+ TodoAmount: 0,+ })++ // get flag amount+ if req.IsAdmin {+ reportCount, err := rs.reportRepo.GetReportCount(ctx)+ if err != nil {+ log.Errorf("get report count failed: %v", err)+ } else {+ resp = append(resp, &schema.GetReviewingTypeResp{+ Name: string(constant.FlaggedPost),+ Label: "",+ TodoAmount: reportCount,+ })+ }+ }++ // get suggestion amount+ countUnreviewedRevision, err := rs.revisionRepo.CountUnreviewedRevision(ctx, req.GetCanReviewObjectTypes())+ if err != nil {+ log.Errorf("get unreviewed revision count failed: %v", err)+ } else {+ resp = append(resp, &schema.GetReviewingTypeResp{+ Name: string(constant.SuggestedPostEdit),+ Label: "",+ TodoAmount: countUnreviewedRevision,+ })+ }+ return resp, nil+}