feat(review): add API about reviewing type
This commit is contained in:
+3
-23
@@ -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 !wireinject
|
||||
|
||||
package 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)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
// comment
|
||||
r.POST("/comment", a.commentController.AddComment)
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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.TagCommonService
|
||||
notificationQueueService notice_queue.NotificationQueueService
|
||||
activityQueueService 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user