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.

feat(review): Add review report API

LinkinStars009497ba6558
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index 33c943a5..de173cfb 100644
--- a/cmd/wire_gen.go
+++ b/cmd/wire_gen.go
@@ -44,17 +44,18 @@ import (
"github.com/apache/incubator-answer/internal/repo/user_external_login"
"github.com/apache/incubator-answer/internal/repo/user_notification_config"
"github.com/apache/incubator-answer/internal/router"
- "github.com/apache/incubator-answer/internal/service"
"github.com/apache/incubator-answer/internal/service/action"
activity2 "github.com/apache/incubator-answer/internal/service/activity"
activity_common2 "github.com/apache/incubator-answer/internal/service/activity_common"
"github.com/apache/incubator-answer/internal/service/activity_queue"
"github.com/apache/incubator-answer/internal/service/answer_common"
auth2 "github.com/apache/incubator-answer/internal/service/auth"
+ collection2 "github.com/apache/incubator-answer/internal/service/collection"
"github.com/apache/incubator-answer/internal/service/collection_common"
comment2 "github.com/apache/incubator-answer/internal/service/comment"
"github.com/apache/incubator-answer/internal/service/comment_common"
config2 "github.com/apache/incubator-answer/internal/service/config"
+ "github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/internal/service/dashboard"
export2 "github.com/apache/incubator-answer/internal/service/export"
"github.com/apache/incubator-answer/internal/service/follow"
@@ -131,7 +132,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
userNotificationConfigRepo := user_notification_config.NewUserNotificationConfigRepo(dataData)
userNotificationConfigService := user_notification_config2.NewUserNotificationConfigService(userRepo, userNotificationConfigRepo)
userExternalLoginService := user_external_login2.NewUserExternalLoginService(userRepo, userCommon, userExternalLoginRepo, emailService, siteInfoCommonService, userActiveActivityRepo, userNotificationConfigService)
- userService := service.NewUserService(userRepo, userActiveActivityRepo, activityRepo, emailService, authService, siteInfoCommonService, userRoleRelService, userCommon, userExternalLoginService, userNotificationConfigRepo, userNotificationConfigService)
+ userService := content.NewUserService(userRepo, userActiveActivityRepo, activityRepo, emailService, authService, siteInfoCommonService, userRoleRelService, userCommon, userExternalLoginService, userNotificationConfigRepo, userNotificationConfigService)
captchaRepo := captcha.NewCaptchaRepo(dataData)
captchaService := action.NewCaptchaService(captchaRepo)
userController := controller.NewUserController(authService, userService, captchaService, emailService, siteInfoCommonService, userNotificationConfigService)
@@ -165,11 +166,16 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
metaRepo := meta.NewMetaRepo(dataData)
metaService := meta2.NewMetaService(metaRepo)
questionCommon := questioncommon.NewQuestionCommon(questionRepo, answerRepo, voteRepo, followRepo, tagCommonService, userCommon, collectionCommon, answerCommon, metaService, configService, activityQueueService, dataData)
- reportHandle := report_handle.NewReportHandle(questionCommon, commentRepo, configService, notificationQueueService)
+ answerActivityRepo := activity.NewAnswerActivityRepo(dataData, activityRepo, userRankRepo, notificationQueueService)
+ answerActivityService := activity2.NewAnswerActivityService(answerActivityRepo, configService)
+ externalNotificationService := notification.NewExternalNotificationService(dataData, userNotificationConfigRepo, followRepo, emailService, userRepo, externalNotificationQueueService, userExternalLoginRepo, siteInfoCommonService)
+ questionService := content.NewQuestionService(questionRepo, tagCommonService, questionCommon, userCommon, userRepo, userRoleRelService, revisionService, metaService, collectionCommon, answerActivityService, emailService, notificationQueueService, externalNotificationQueueService, activityQueueService, siteInfoCommonService, externalNotificationService)
+ answerService := content.NewAnswerService(answerRepo, questionRepo, questionCommon, userCommon, collectionCommon, userRepo, revisionService, answerActivityService, answerCommon, voteRepo, emailService, userRoleRelService, notificationQueueService, externalNotificationQueueService, activityQueueService)
+ reportHandle := report_handle.NewReportHandle(questionService, answerService, commentService)
reportService := report2.NewReportService(reportRepo, objService, userCommon, answerRepo, questionRepo, commentCommonRepo, reportHandle, configService)
reportController := controller.NewReportController(reportService, rankService, captchaService)
- serviceVoteRepo := activity.NewVoteRepo(dataData, activityRepo, userRankRepo, notificationQueueService)
- voteService := service.NewVoteService(serviceVoteRepo, configService, questionRepo, answerRepo, commentCommonRepo, objService)
+ contentVoteRepo := activity.NewVoteRepo(dataData, activityRepo, userRankRepo, notificationQueueService)
+ voteService := content.NewVoteService(contentVoteRepo, configService, questionRepo, answerRepo, commentCommonRepo, objService)
voteController := controller.NewVoteController(voteService, rankService, captchaService)
tagService := tag2.NewTagService(tagRepo, tagCommonService, revisionService, followRepo, siteInfoCommonService, activityQueueService)
tagController := controller.NewTagController(tagService, tagCommonService, rankService)
@@ -177,21 +183,16 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
followService := follow.NewFollowService(followFollowRepo, followRepo, tagCommonRepo)
followController := controller.NewFollowController(followService)
collectionGroupRepo := collection.NewCollectionGroupRepo(dataData)
- collectionService := service.NewCollectionService(collectionRepo, collectionGroupRepo, questionCommon)
+ collectionService := collection2.NewCollectionService(collectionRepo, collectionGroupRepo, questionCommon)
collectionController := controller.NewCollectionController(collectionService)
- answerActivityRepo := activity.NewAnswerActivityRepo(dataData, activityRepo, userRankRepo, notificationQueueService)
- answerActivityService := activity2.NewAnswerActivityService(answerActivityRepo, configService)
- externalNotificationService := notification.NewExternalNotificationService(dataData, userNotificationConfigRepo, followRepo, emailService, userRepo, externalNotificationQueueService, userExternalLoginRepo, siteInfoCommonService)
- questionService := service.NewQuestionService(questionRepo, tagCommonService, questionCommon, userCommon, userRepo, userRoleRelService, revisionService, metaService, collectionCommon, answerActivityService, emailService, notificationQueueService, externalNotificationQueueService, activityQueueService, siteInfoCommonService, externalNotificationService)
- answerService := service.NewAnswerService(answerRepo, questionRepo, questionCommon, userCommon, collectionCommon, userRepo, revisionService, answerActivityService, answerCommon, voteRepo, emailService, userRoleRelService, notificationQueueService, externalNotificationQueueService, activityQueueService)
questionController := controller.NewQuestionController(questionService, answerService, rankService, siteInfoCommonService, captchaService, rateLimitMiddleware)
answerController := controller.NewAnswerController(answerService, rankService, captchaService, siteInfoCommonService, rateLimitMiddleware)
searchParser := search_parser.NewSearchParser(tagCommonService, userCommon)
searchRepo := search_common.NewSearchRepo(dataData, uniqueIDRepo, userCommon, tagCommonService)
- searchService := service.NewSearchService(searchParser, searchRepo)
+ searchService := content.NewSearchService(searchParser, searchRepo)
searchController := controller.NewSearchController(searchService, captchaService)
- serviceRevisionService := service.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, notificationQueueService, activityQueueService, reportRepo)
- revisionController := controller.NewRevisionController(serviceRevisionService, rankService)
+ contentRevisionService := content.NewRevisionService(revisionRepo, userCommon, questionCommon, answerService, objService, questionRepo, answerRepo, tagRepo, tagCommonService, notificationQueueService, activityQueueService, reportRepo)
+ revisionController := controller.NewRevisionController(contentRevisionService, rankService)
rankController := controller.NewRankController(rankService)
userAdminRepo := user.NewUserAdminRepo(dataData, authRepo)
userAdminService := user_admin.NewUserAdminService(userAdminRepo, userRoleRelService, authService, userCommon, userActiveActivityRepo, siteInfoCommonService, emailService, questionRepo, answerRepo, commentCommonRepo)
diff --git a/internal/base/constant/revision.go b/internal/base/constant/revision.go
index ac65c487..93ccf2ec 100644
--- a/internal/base/constant/revision.go
+++ b/internal/base/constant/revision.go
@@ -9,3 +9,11 @@ const (
FlaggedUser ReviewingType = "flagged_user"
SuggestedPostEdit ReviewingType = "suggested_post_edit"
)
+
+const (
+ ReportOperationEditPost = "edit_post"
+ ReportOperationClosePost = "close_post"
+ ReportOperationDeletePost = "delete_post"
+ ReportOperationUnlistPost = "unlist_post"
+ ReportOperationIgnoreReport = "ignore_report"
+)
diff --git a/internal/base/cron/cron.go b/internal/base/cron/cron.go
index bb9cb7e2..b7b05c26 100644
--- a/internal/base/cron/cron.go
+++ b/internal/base/cron/cron.go
@@ -23,7 +23,7 @@ import (
"context"
"fmt"
- "github.com/apache/incubator-answer/internal/service"
+ "github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/internal/service/siteinfo_common"
"github.com/robfig/cron/v3"
"github.com/segmentfault/pacman/log"
@@ -32,13 +32,13 @@ import (
// ScheduledTaskManager scheduled task manager
type ScheduledTaskManager struct {
siteInfoService siteinfo_common.SiteInfoCommonService
- questionService *service.QuestionService
+ questionService *content.QuestionService
}
// NewScheduledTaskManager new scheduled task manager
func NewScheduledTaskManager(
siteInfoService siteinfo_common.SiteInfoCommonService,
- questionService *service.QuestionService,
+ questionService *content.QuestionService,
) *ScheduledTaskManager {
manager := &ScheduledTaskManager{
siteInfoService: siteInfoService,
diff --git a/internal/controller/answer_controller.go b/internal/controller/answer_controller.go
index 8fdb089c..390aa422 100644
--- a/internal/controller/answer_controller.go
+++ b/internal/controller/answer_controller.go
@@ -30,8 +30,8 @@ import (
"github.com/apache/incubator-answer/internal/base/validator"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
"github.com/apache/incubator-answer/internal/service/action"
+ "github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/internal/service/permission"
"github.com/apache/incubator-answer/internal/service/rank"
"github.com/apache/incubator-answer/internal/service/siteinfo_common"
@@ -42,7 +42,7 @@ import (
// AnswerController answer controller
type AnswerController struct {
- answerService *service.AnswerService
+ answerService *content.AnswerService
rankService *rank.RankService
actionService *action.CaptchaService
siteInfoCommonService siteinfo_common.SiteInfoCommonService
@@ -51,7 +51,7 @@ type AnswerController struct {
// NewAnswerController new controller
func NewAnswerController(
- answerService *service.AnswerService,
+ answerService *content.AnswerService,
rankService *rank.RankService,
actionService *action.CaptchaService,
siteInfoCommonService siteinfo_common.SiteInfoCommonService,
diff --git a/internal/controller/collection_controller.go b/internal/controller/collection_controller.go
index 4e3eff38..a35ee693 100644
--- a/internal/controller/collection_controller.go
+++ b/internal/controller/collection_controller.go
@@ -23,18 +23,18 @@ import (
"github.com/apache/incubator-answer/internal/base/handler"
"github.com/apache/incubator-answer/internal/base/middleware"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
+ "github.com/apache/incubator-answer/internal/service/collection"
"github.com/apache/incubator-answer/pkg/uid"
"github.com/gin-gonic/gin"
)
// CollectionController collection controller
type CollectionController struct {
- collectionService *service.CollectionService
+ collectionService *collection.CollectionService
}
// NewCollectionController new controller
-func NewCollectionController(collectionService *service.CollectionService) *CollectionController {
+func NewCollectionController(collectionService *collection.CollectionService) *CollectionController {
return &CollectionController{collectionService: collectionService}
}
diff --git a/internal/controller/question_controller.go b/internal/controller/question_controller.go
index 7d287210..3e21c87b 100644
--- a/internal/controller/question_controller.go
+++ b/internal/controller/question_controller.go
@@ -20,6 +20,8 @@
package controller
import (
+ "net/http"
+
"github.com/apache/incubator-answer/internal/base/handler"
"github.com/apache/incubator-answer/internal/base/middleware"
"github.com/apache/incubator-answer/internal/base/pager"
@@ -28,8 +30,8 @@ import (
"github.com/apache/incubator-answer/internal/base/validator"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
"github.com/apache/incubator-answer/internal/service/action"
+ "github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/internal/service/permission"
"github.com/apache/incubator-answer/internal/service/rank"
"github.com/apache/incubator-answer/internal/service/siteinfo_common"
@@ -37,13 +39,12 @@ import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
"github.com/segmentfault/pacman/errors"
- "net/http"
)
// QuestionController question controller
type QuestionController struct {
- questionService *service.QuestionService
- answerService *service.AnswerService
+ questionService *content.QuestionService
+ answerService *content.AnswerService
rankService *rank.RankService
siteInfoService siteinfo_common.SiteInfoCommonService
actionService *action.CaptchaService
@@ -52,8 +53,8 @@ type QuestionController struct {
// NewQuestionController new controller
func NewQuestionController(
- questionService *service.QuestionService,
- answerService *service.AnswerService,
+ questionService *content.QuestionService,
+ answerService *content.AnswerService,
rankService *rank.RankService,
siteInfoService siteinfo_common.SiteInfoCommonService,
actionService *action.CaptchaService,
diff --git a/internal/controller/report_controller.go b/internal/controller/report_controller.go
index a2efbc2d..f4068579 100644
--- a/internal/controller/report_controller.go
+++ b/internal/controller/report_controller.go
@@ -31,7 +31,6 @@ import (
"github.com/apache/incubator-answer/internal/service/permission"
"github.com/apache/incubator-answer/internal/service/rank"
"github.com/apache/incubator-answer/internal/service/report"
- "github.com/apache/incubator-answer/pkg/converter"
"github.com/apache/incubator-answer/pkg/uid"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors"
@@ -105,60 +104,47 @@ func (rc *ReportController) AddReport(ctx *gin.Context) {
handler.HandleResponse(ctx, err, nil)
}
-// ListReportPage godoc
-// @Summary list report page
-// @Description list report records
-// @Security ApiKeyAuth
+// GetUnreviewedReportPostPage get unreviewed report post page
+// @Summary get unreviewed report post page
+// @Description get unreviewed report post page
// @Tags Report
// @Accept json
// @Produce json
// @Security ApiKeyAuth
-// @Param status query string true "status" Enums(pending, completed)
-// @Param object_type query string true "object_type" Enums(all, question,answer,comment)
-// @Param page query int false "page size"
-// @Param page_size query int false "page size"
-// @Success 200 {object} handler.RespBody
-// @Router /answer/api/v1/reports/page [get]
-func (rc *ReportController) ListReportPage(ctx *gin.Context) {
- var (
- objectType = ctx.Query("object_type")
- status = ctx.Query("status")
- page = converter.StringToInt(ctx.DefaultQuery("page", "1"))
- pageSize = converter.StringToInt(ctx.DefaultQuery("page_size", "20"))
- )
-
- dto := schema.GetReportListPageDTO{
- ObjectType: objectType,
- Status: status,
- Page: page,
- PageSize: pageSize,
+// @Param page query int false "page"
+// @Success 200 {object} handler.RespBody{data=pager.PageModel{list=[]schema.GetReportListPageResp}}
+// @Router /answer/api/v1/report/unreviewed/post [get]
+func (rc *ReportController) GetUnreviewedReportPostPage(ctx *gin.Context) {
+ req := &schema.GetUnreviewedReportPostPageReq{}
+ if handler.BindAndCheck(ctx, req) {
+ return
}
- resp, err := rc.reportService.ListReportPage(ctx, dto)
- if err != nil {
- handler.HandleResponse(ctx, err, schema.ErrTypeModal)
- } else {
- handler.HandleResponse(ctx, err, resp)
- }
+ // TODO: check permission
+
+ resp, err := rc.reportService.GetUnreviewedReportPostPage(ctx, req)
+ handler.HandleResponse(ctx, err, resp)
}
-// Handle godoc
-// @Summary handle flag
-// @Description handle flag
+// ReviewReport review report
+// @Summary review report
+// @Description review report
// @Security ApiKeyAuth
// @Tags Report
// @Accept json
// @Produce json
// @Security ApiKeyAuth
-// @Param data body schema.ReportHandleReq true "flag"
+// @Param data body schema.ReviewReportReq true "flag"
// @Success 200 {object} handler.RespBody
-// @Router /answer/api/v1/report/ [put]
-func (rc *ReportController) Handle(ctx *gin.Context) {
- req := schema.ReportHandleReq{}
- if handler.BindAndCheck(ctx, &req) {
+// @Router /answer/api/v1/report/review [put]
+func (rc *ReportController) ReviewReport(ctx *gin.Context) {
+ req := &schema.ReviewReportReq{}
+ if handler.BindAndCheck(ctx, req) {
return
}
- err := rc.reportService.HandleReported(ctx, req)
+ // TODO: check permission
+
+ err := rc.reportService.ReviewReport(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
diff --git a/internal/controller/revision_controller.go b/internal/controller/revision_controller.go
index a9d9164f..fd2735e0 100644
--- a/internal/controller/revision_controller.go
+++ b/internal/controller/revision_controller.go
@@ -26,7 +26,7 @@ import (
"github.com/apache/incubator-answer/internal/base/reason"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
+ "github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/internal/service/permission"
"github.com/apache/incubator-answer/internal/service/rank"
"github.com/apache/incubator-answer/pkg/obj"
@@ -37,13 +37,13 @@ import (
// RevisionController revision controller
type RevisionController struct {
- revisionListService *service.RevisionService
+ revisionListService *content.RevisionService
rankService *rank.RankService
}
// NewRevisionController new controller
func NewRevisionController(
- revisionListService *service.RevisionService,
+ revisionListService *content.RevisionService,
rankService *rank.RankService,
) *RevisionController {
return &RevisionController{
diff --git a/internal/controller/search_controller.go b/internal/controller/search_controller.go
index d08fd8f1..b74c0e9e 100644
--- a/internal/controller/search_controller.go
+++ b/internal/controller/search_controller.go
@@ -27,8 +27,8 @@ import (
"github.com/apache/incubator-answer/internal/base/validator"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
"github.com/apache/incubator-answer/internal/service/action"
+ "github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/plugin"
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors"
@@ -36,13 +36,13 @@ import (
// SearchController tag controller
type SearchController struct {
- searchService *service.SearchService
+ searchService *content.SearchService
actionService *action.CaptchaService
}
// NewSearchController new controller
func NewSearchController(
- searchService *service.SearchService,
+ searchService *content.SearchService,
actionService *action.CaptchaService,
) *SearchController {
return &SearchController{
diff --git a/internal/controller/template_render/controller.go b/internal/controller/template_render/controller.go
index 4fdcaf2b..521651b7 100644
--- a/internal/controller/template_render/controller.go
+++ b/internal/controller/template_render/controller.go
@@ -20,15 +20,16 @@
package templaterender
import (
- questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
"math"
+ "github.com/apache/incubator-answer/internal/service/content"
+ questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
+
"github.com/apache/incubator-answer/internal/service/comment"
"github.com/apache/incubator-answer/internal/service/siteinfo_common"
"github.com/google/wire"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
"github.com/apache/incubator-answer/internal/service/tag"
)
@@ -38,20 +39,20 @@ var ProviderSetTemplateRenderController = wire.NewSet(
)
type TemplateRenderController struct {
- questionService *service.QuestionService
- userService *service.UserService
+ questionService *content.QuestionService
+ userService *content.UserService
tagService *tag.TagService
- answerService *service.AnswerService
+ answerService *content.AnswerService
commentService *comment.CommentService
siteInfoService siteinfo_common.SiteInfoCommonService
questionRepo questioncommon.QuestionRepo
}
func NewTemplateRenderController(
- questionService *service.QuestionService,
- userService *service.UserService,
+ questionService *content.QuestionService,
+ userService *content.UserService,
tagService *tag.TagService,
- answerService *service.AnswerService,
+ answerService *content.AnswerService,
commentService *comment.CommentService,
siteInfoService siteinfo_common.SiteInfoCommonService,
questionRepo questioncommon.QuestionRepo,
diff --git a/internal/controller/user_controller.go b/internal/controller/user_controller.go
index 4ef50e9e..b95e86bd 100644
--- a/internal/controller/user_controller.go
+++ b/internal/controller/user_controller.go
@@ -20,6 +20,8 @@
package controller
import (
+ "net/url"
+
"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/base/handler"
"github.com/apache/incubator-answer/internal/base/middleware"
@@ -28,9 +30,9 @@ import (
"github.com/apache/incubator-answer/internal/base/validator"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
"github.com/apache/incubator-answer/internal/service/action"
"github.com/apache/incubator-answer/internal/service/auth"
+ "github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/internal/service/export"
"github.com/apache/incubator-answer/internal/service/siteinfo_common"
"github.com/apache/incubator-answer/internal/service/user_notification_config"
@@ -38,12 +40,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
- "net/url"
)
// UserController user controller
type UserController struct {
- userService *service.UserService
+ userService *content.UserService
authService *auth.AuthService
actionService *action.CaptchaService
emailService *export.EmailService
@@ -54,7 +55,7 @@ type UserController struct {
// NewUserController new controller
func NewUserController(
authService *auth.AuthService,
- userService *service.UserService,
+ userService *content.UserService,
actionService *action.CaptchaService,
emailService *export.EmailService,
siteInfoCommonService siteinfo_common.SiteInfoCommonService,
diff --git a/internal/controller/vote_controller.go b/internal/controller/vote_controller.go
index 6417087b..09b5fb07 100644
--- a/internal/controller/vote_controller.go
+++ b/internal/controller/vote_controller.go
@@ -27,8 +27,8 @@ import (
"github.com/apache/incubator-answer/internal/base/validator"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
"github.com/apache/incubator-answer/internal/service/action"
+ "github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/internal/service/rank"
"github.com/apache/incubator-answer/pkg/uid"
"github.com/gin-gonic/gin"
@@ -37,14 +37,14 @@ import (
// VoteController activity controller
type VoteController struct {
- VoteService *service.VoteService
+ VoteService *content.VoteService
rankService *rank.RankService
actionService *action.CaptchaService
}
// NewVoteController new controller
func NewVoteController(
- voteService *service.VoteService,
+ voteService *content.VoteService,
rankService *rank.RankService,
actionService *action.CaptchaService,
) *VoteController {
diff --git a/internal/entity/report_entity.go b/internal/entity/report_entity.go
index be0d76c7..07f5bc84 100644
--- a/internal/entity/report_entity.go
+++ b/internal/entity/report_entity.go
@@ -24,6 +24,7 @@ import "time"
const (
ReportStatusPending = 1
ReportStatusCompleted = 2
+ ReportStatusIgnore = 3
ReportStatusDeleted = 10
)
diff --git a/internal/repo/activity/vote_repo.go b/internal/repo/activity/vote_repo.go
index e7d38d3e..7e8b02e6 100644
--- a/internal/repo/activity/vote_repo.go
+++ b/internal/repo/activity/vote_repo.go
@@ -22,9 +22,11 @@ package activity
import (
"context"
"fmt"
- "github.com/segmentfault/pacman/log"
"time"
+ "github.com/apache/incubator-answer/internal/service/content"
+ "github.com/segmentfault/pacman/log"
+
"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/service/notice_queue"
"github.com/apache/incubator-answer/pkg/converter"
@@ -39,7 +41,6 @@ import (
"github.com/apache/incubator-answer/internal/base/reason"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
"github.com/apache/incubator-answer/internal/service/activity_common"
"github.com/segmentfault/pacman/errors"
"xorm.io/xorm"
@@ -59,7 +60,7 @@ func NewVoteRepo(
activityRepo activity_common.ActivityRepo,
userRankRepo rank.UserRankRepo,
notificationQueueService notice_queue.NotificationQueueService,
-) service.VoteRepo {
+) content.VoteRepo {
return &VoteRepo{
data: data,
activityRepo: activityRepo,
diff --git a/internal/repo/collection/collection_group_repo.go b/internal/repo/collection/collection_group_repo.go
index 0fc9c27a..05711f5a 100644
--- a/internal/repo/collection/collection_group_repo.go
+++ b/internal/repo/collection/collection_group_repo.go
@@ -21,6 +21,8 @@ package collection
import (
"context"
+
+ "github.com/apache/incubator-answer/internal/service/collection"
"xorm.io/xorm"
"github.com/apache/incubator-answer/internal/base/data"
@@ -28,7 +30,6 @@ import (
"github.com/apache/incubator-answer/internal/base/reason"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
- "github.com/apache/incubator-answer/internal/service"
"github.com/segmentfault/pacman/errors"
)
@@ -38,7 +39,7 @@ type collectionGroupRepo struct {
}
// NewCollectionGroupRepo new repository
-func NewCollectionGroupRepo(data *data.Data) service.CollectionGroupRepo {
+func NewCollectionGroupRepo(data *data.Data) collection.CollectionGroupRepo {
return &collectionGroupRepo{
data: data,
}
diff --git a/internal/repo/report/report_repo.go b/internal/repo/report/report_repo.go
index 0120f31c..013d036d 100644
--- a/internal/repo/report/report_repo.go
+++ b/internal/repo/report/report_repo.go
@@ -22,7 +22,6 @@ package report
import (
"context"
- "github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/base/pager"
"github.com/apache/incubator-answer/internal/schema"
"github.com/apache/incubator-answer/internal/service/report_common"
@@ -62,31 +61,11 @@ func (rr *reportRepo) AddReport(ctx context.Context, report *entity.Report) (err
}
// GetReportListPage get report list page
-func (rr *reportRepo) GetReportListPage(ctx context.Context, dto schema.GetReportListPageDTO) (reports []entity.Report, total int64, err error) {
- var (
- ok bool
- status int
- objectType int
- session = rr.data.DB.Context(ctx)
- cond = entity.Report{}
- )
-
- // parse status
- status, ok = entity.ReportStatus[dto.Status]
- if !ok {
- status = entity.ReportStatus["pending"]
- }
- cond.Status = status
-
- // parse object type
- objectType, ok = constant.ObjectTypeStrMapping[dto.ObjectType]
- if ok {
- cond.ObjectType = objectType
- }
-
- // order
- session.OrderBy("updated_at desc")
-
+func (rr *reportRepo) GetReportListPage(ctx context.Context, dto *schema.GetReportListPageDTO) (
+ reports []*entity.Report, total int64, err error) {
+ cond := &entity.Report{}
+ cond.Status = dto.Status
+ session := rr.data.DB.Context(ctx).Desc("updated_at")
total, err = pager.Help(dto.Page, dto.PageSize, &reports, cond, session)
if err != nil {
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
@@ -104,9 +83,9 @@ func (rr *reportRepo) GetByID(ctx context.Context, id string) (report *entity.Re
return
}
-// UpdateByID handle report by ID
-func (rr *reportRepo) UpdateByID(ctx context.Context, id string, handleData entity.Report) (err error) {
- _, err = rr.data.DB.Context(ctx).ID(id).Update(&handleData)
+// UpdateStatus update report status by ID
+func (rr *reportRepo) UpdateStatus(ctx context.Context, id string, status int) (err error) {
+ _, err = rr.data.DB.Context(ctx).ID(id).Update(&entity.Report{Status: status})
if err != nil {
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}
diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go
index 2895d103..b5786ba0 100644
--- a/internal/router/answer_api_router.go
+++ b/internal/router/answer_api_router.go
@@ -200,6 +200,8 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
// report
r.POST("/report", a.reportController.AddReport)
+ r.GET("/report/unreviewed/post", a.reportController.GetUnreviewedReportPostPage)
+ r.PUT("/report/review", a.reportController.ReviewReport)
// vote
r.POST("/vote/up", a.voteController.VoteUp)
@@ -276,10 +278,6 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
r.GET("/user/plugin/configs", a.userPluginController.GetUserPluginList)
r.GET("/user/plugin/config", a.userPluginController.GetUserPluginConfig)
r.PUT("/user/plugin/config", a.userPluginController.UpdatePluginUserConfig)
-
- // report
- r.GET("/reports/page", a.reportController.ListReportPage)
- r.PUT("/report", a.reportController.Handle)
}
func (a *AnswerAPIRouter) RegisterAnswerAdminAPIRouter(r *gin.RouterGroup) {
diff --git a/internal/schema/report_schema.go b/internal/schema/report_schema.go
index e853259c..45becee4 100644
--- a/internal/schema/report_schema.go
+++ b/internal/schema/report_schema.go
@@ -70,10 +70,9 @@ type ReportHandleReq struct {
// GetReportListPageDTO report list data transfer object
type GetReportListPageDTO struct {
- ObjectType string
- Status string
- Page int
- PageSize int
+ Page int
+ PageSize int
+ Status int
}
// GetReportListPageResp get report list
@@ -106,7 +105,6 @@ type GetReportListPageResp struct {
UserID string `json:"-"`
ReportedUserID string `json:"-"`
- Status int `json:"-"`
ObjectType int `json:"-"`
ReportType int `json:"-"`
FlaggedType int `json:"-"`
@@ -119,3 +117,20 @@ func (r *GetReportListPageResp) Format() {
r.CreatedAtParsed = r.CreatedAt.Unix()
r.UpdatedAtParsed = r.UpdatedAt.Unix()
}
+
+// GetUnreviewedReportPostPageReq get unreviewed report post page request
+type GetUnreviewedReportPostPageReq struct {
+ Page int `json:"page" form:"page"`
+}
+
+// ReviewReportReq review report request
+type ReviewReportReq struct {
+ ReportID string `validate:"required" json:"report_id"`
+ OperationType string `validate:"required,oneof=edit_post close_post delete_post unlist_post ignore_report" json:"operation_type"`
+ CloseType int `validate:"omitempty" json:"close_type"`
+ CloseMsg string `validate:"omitempty" json:"close_msg"`
+ Title string `validate:"omitempty,notblank,gte=6,lte=150" json:"title"`
+ Content string `validate:"omitempty,notblank,gte=6,lte=65535" json:"content"`
+ Tags []*TagItem `validate:"omitempty,dive" json:"tags"`
+ UserID string `json:"-"`
+}
diff --git a/internal/service/collection_group_service.go b/internal/service/collection/collection_group_service.go
similarity index 99%
rename from internal/service/collection_group_service.go
rename to internal/service/collection/collection_group_service.go
index 2620c54c..3f6f3db1 100644
--- a/internal/service/collection_group_service.go
+++ b/internal/service/collection/collection_group_service.go
@@ -17,7 +17,7 @@
* under the License.
*/
-package service
+package collection
import (
"context"
diff --git a/internal/service/collection_service.go b/internal/service/collection/collection_service.go
similarity index 99%
rename from internal/service/collection_service.go
rename to internal/service/collection/collection_service.go
index 1072d1ab..1820ac52 100644
--- a/internal/service/collection_service.go
+++ b/internal/service/collection/collection_service.go
@@ -17,10 +17,11 @@
* under the License.
*/
-package service
+package collection
import (
"context"
+
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
collectioncommon "github.com/apache/incubator-answer/internal/service/collection_common"
diff --git a/internal/service/answer_service.go b/internal/service/content/answer_service.go
similarity index 99%
rename from internal/service/answer_service.go
rename to internal/service/content/answer_service.go
index 303e156d..9cbcb255 100644
--- a/internal/service/answer_service.go
+++ b/internal/service/content/answer_service.go
@@ -17,7 +17,7 @@
* under the License.
*/
-package service
+package content
import (
"context"
diff --git a/internal/service/question_service.go b/internal/service/content/question_service.go
similarity index 99%
rename from internal/service/question_service.go
rename to internal/service/content/question_service.go
index a4d5ffe6..c2bfe125 100644
--- a/internal/service/question_service.go
+++ b/internal/service/content/question_service.go
@@ -17,7 +17,7 @@
* under the License.
*/
-package service
+package content
import (
"encoding/json"
@@ -513,7 +513,8 @@ func (qs *QuestionService) RemoveQuestion(ctx context.Context, req *schema.Remov
// log.Errorf("user DeleteQuestion rank rollback error %s", err.Error())
// }
qs.activityQueueService.Send(ctx, &schema.ActivityMsg{
- UserID: req.UserID,
+ UserID: questionInfo.UserID,
+ TriggerUserID: converter.StringToInt64(req.UserID),
ObjectID: questionInfo.ID,
OriginalObjectID: questionInfo.ID,
ActivityTypeKey: constant.ActQuestionDeleted,
diff --git a/internal/service/revision_service.go b/internal/service/content/revision_service.go
similarity index 99%
rename from internal/service/revision_service.go
rename to internal/service/content/revision_service.go
index 9479a2c6..da051965 100644
--- a/internal/service/revision_service.go
+++ b/internal/service/content/revision_service.go
@@ -17,7 +17,7 @@
* under the License.
*/
-package service
+package content
import (
"context"
diff --git a/internal/service/search_service.go b/internal/service/content/search_service.go
similarity index 99%
rename from internal/service/search_service.go
rename to internal/service/content/search_service.go
index 46d71374..e9f2d128 100644
--- a/internal/service/search_service.go
+++ b/internal/service/content/search_service.go
@@ -17,10 +17,11 @@
* under the License.
*/
-package service
+package content
import (
"context"
+
"github.com/apache/incubator-answer/internal/schema"
"github.com/apache/incubator-answer/internal/service/search_common"
"github.com/apache/incubator-answer/internal/service/search_parser"
diff --git a/internal/service/user_service.go b/internal/service/content/user_service.go
similarity index 99%
rename from internal/service/user_service.go
rename to internal/service/content/user_service.go
index c6d98fc2..fcf1ae0e 100644
--- a/internal/service/user_service.go
+++ b/internal/service/content/user_service.go
@@ -17,15 +17,16 @@
* under the License.
*/
-package service
+package content
import (
"context"
"encoding/json"
"fmt"
+ "time"
+
"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/service/user_notification_config"
- "time"
"github.com/apache/incubator-answer/internal/base/handler"
"github.com/apache/incubator-answer/internal/base/reason"
diff --git a/internal/service/vote_service.go b/internal/service/content/vote_service.go
similarity index 99%
rename from internal/service/vote_service.go
rename to internal/service/content/vote_service.go
index b5ce73b8..9785e30d 100644
--- a/internal/service/vote_service.go
+++ b/internal/service/content/vote_service.go
@@ -17,13 +17,14 @@
* under the License.
*/
-package service
+package content
import (
"context"
- "github.com/apache/incubator-answer/internal/service/activity_common"
"strings"
+ "github.com/apache/incubator-answer/internal/service/activity_common"
+
"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/base/handler"
"github.com/apache/incubator-answer/internal/base/pager"
diff --git a/internal/service/provider.go b/internal/service/provider.go
index 462d2ce4..5e381bf6 100644
--- a/internal/service/provider.go
+++ b/internal/service/provider.go
@@ -26,10 +26,12 @@ import (
"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/auth"
+ "github.com/apache/incubator-answer/internal/service/collection"
collectioncommon "github.com/apache/incubator-answer/internal/service/collection_common"
"github.com/apache/incubator-answer/internal/service/comment"
"github.com/apache/incubator-answer/internal/service/comment_common"
"github.com/apache/incubator-answer/internal/service/config"
+ "github.com/apache/incubator-answer/internal/service/content"
"github.com/apache/incubator-answer/internal/service/dashboard"
"github.com/apache/incubator-answer/internal/service/export"
"github.com/apache/incubator-answer/internal/service/follow"
@@ -64,16 +66,16 @@ var ProviderSetService = wire.NewSet(
comment.NewCommentService,
comment_common.NewCommentCommonService,
report.NewReportService,
- NewVoteService,
+ content.NewVoteService,
tag.NewTagService,
follow.NewFollowService,
- NewCollectionGroupService,
- NewCollectionService,
+ collection.NewCollectionGroupService,
+ collection.NewCollectionService,
action.NewCaptchaService,
auth.NewAuthService,
- NewUserService,
- NewQuestionService,
- NewAnswerService,
+ content.NewUserService,
+ content.NewQuestionService,
+ content.NewAnswerService,
export.NewEmailService,
tagcommon.NewTagCommonService,
usercommon.NewUserCommon,
@@ -82,10 +84,10 @@ var ProviderSetService = wire.NewSet(
uploader.NewUploaderService,
collectioncommon.NewCollectionCommon,
revision_common.NewRevisionService,
- NewRevisionService,
+ content.NewRevisionService,
rank.NewRankService,
search_parser.NewSearchParser,
- NewSearchService,
+ content.NewSearchService,
meta.NewMetaService,
object_info.NewObjService,
report_handle.NewReportHandle,
diff --git a/internal/service/report/report_service.go b/internal/service/report/report_service.go
index 287ad57b..72ea83bf 100644
--- a/internal/service/report/report_service.go
+++ b/internal/service/report/report_service.go
@@ -21,6 +21,8 @@ package report
import (
"encoding/json"
+
+ "github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/base/handler"
"github.com/apache/incubator-answer/internal/base/pager"
"github.com/apache/incubator-answer/internal/base/reason"
@@ -102,26 +104,21 @@ func (rs *ReportService) AddReport(ctx context.Context, req *schema.AddReportReq
return rs.reportRepo.AddReport(ctx, report)
}
-// ListReportPage list report pages
-func (rs *ReportService) ListReportPage(ctx context.Context, dto schema.GetReportListPageDTO) (pageModel *pager.PageModel, err error) {
- var (
- resp []*schema.GetReportListPageResp
- flags []entity.Report
- total int64
-
- flaggedUserIds,
- userIds []string
-
- flaggedUsers,
- users map[string]*schema.UserBasicInfo
- )
-
- flags, total, err = rs.reportRepo.GetReportListPage(ctx, dto)
+// GetUnreviewedReportPostPage get unreviewed report post page
+func (rs *ReportService) GetUnreviewedReportPostPage(ctx context.Context, req *schema.GetUnreviewedReportPostPageReq) (
+ pageModel *pager.PageModel, err error) {
+ reports, total, err := rs.reportRepo.GetReportListPage(ctx, &schema.GetReportListPageDTO{
+ Page: req.Page,
+ PageSize: 1,
+ Status: entity.ReportStatusPending,
+ })
if err != nil {
return
}
- _ = copier.Copy(&resp, flags)
+ resp := make([]*schema.GetReportListPageResp, 0)
+ _ = copier.Copy(&resp, reports)
+ var flaggedUserIds, userIds []string
for _, r := range resp {
flaggedUserIds = append(flaggedUserIds, r.ReportedUserID)
userIds = append(userIds, r.UserID)
@@ -129,13 +126,13 @@ func (rs *ReportService) ListReportPage(ctx context.Context, dto schema.GetRepor
}
// flagged users
- flaggedUsers, err = rs.commonUser.BatchUserBasicInfoByID(ctx, flaggedUserIds)
+ flaggedUsers, err := rs.commonUser.BatchUserBasicInfoByID(ctx, flaggedUserIds)
if err != nil {
return nil, err
}
// flag users
- users, err = rs.commonUser.BatchUserBasicInfoByID(ctx, userIds)
+ users, err := rs.commonUser.BatchUserBasicInfoByID(ctx, userIds)
if err != nil {
return nil, err
}
@@ -147,39 +144,30 @@ func (rs *ReportService) ListReportPage(ctx context.Context, dto schema.GetRepor
return pager.NewPageModel(total, resp), nil
}
-// HandleReported handle the reported object
-func (rs *ReportService) HandleReported(ctx context.Context, req schema.ReportHandleReq) (err error) {
- var (
- reported *entity.Report
- handleData = entity.Report{
- FlaggedContent: req.FlaggedContent,
- FlaggedType: req.FlaggedType,
- Status: entity.ReportStatusCompleted,
- }
- exist bool
- )
-
- reported, exist, err = rs.reportRepo.GetByID(ctx, req.ID)
+// ReviewReport review report
+func (rs *ReportService) ReviewReport(ctx context.Context, req *schema.ReviewReportReq) (err error) {
+ report, exist, err := rs.reportRepo.GetByID(ctx, req.ReportID)
if err != nil {
- err = errors.BadRequest(reason.ReportHandleFailed).WithError(err).WithStack()
- return
+ return err
}
if !exist {
- err = errors.NotFound(reason.ReportNotFound)
- return
+ return errors.NotFound(reason.ReportNotFound)
}
-
// check if handle or not
- if reported.Status != entity.ReportStatusPending {
- return
+ if report.Status != entity.ReportStatusPending {
+ return nil
+ }
+
+ // ignore this report
+ if req.OperationType == constant.ReportOperationIgnoreReport {
+ return rs.reportRepo.UpdateStatus(ctx, report.ID, entity.ReportStatusIgnore)
}
- if err = rs.reportHandle.HandleObject(ctx, reported, req); err != nil {
+ if err = rs.reportHandle.UpdateReportedObject(ctx, report, req); err != nil {
return
}
- err = rs.reportRepo.UpdateByID(ctx, reported.ID, handleData)
- return
+ return rs.reportRepo.UpdateStatus(ctx, report.ID, entity.ReportStatusCompleted)
}
func (rs *ReportService) decorateReportResp(ctx context.Context, resp *schema.GetReportListPageResp) {
diff --git a/internal/service/report_common/report_common.go b/internal/service/report_common/report_common.go
index e27ff162..4b504630 100644
--- a/internal/service/report_common/report_common.go
+++ b/internal/service/report_common/report_common.go
@@ -29,8 +29,9 @@ import (
// ReportRepo report repository
type ReportRepo interface {
AddReport(ctx context.Context, report *entity.Report) (err error)
- GetReportListPage(ctx context.Context, query schema.GetReportListPageDTO) (reports []entity.Report, total int64, err error)
+ GetReportListPage(ctx context.Context, query *schema.GetReportListPageDTO) (
+ reports []*entity.Report, total int64, err error)
GetByID(ctx context.Context, id string) (report *entity.Report, exist bool, err error)
- UpdateByID(ctx context.Context, id string, handleData entity.Report) (err error)
+ UpdateStatus(ctx context.Context, id string, status int) (err error)
GetReportCount(ctx context.Context) (count int64, err error)
}
diff --git a/internal/service/report_handle/report_handle.go b/internal/service/report_handle/report_handle.go
index 8b51d7fa..df6cff68 100644
--- a/internal/service/report_handle/report_handle.go
+++ b/internal/service/report_handle/report_handle.go
@@ -22,94 +22,111 @@ package report_handle
import (
"context"
- "github.com/apache/incubator-answer/internal/service/config"
- "github.com/apache/incubator-answer/internal/service/notice_queue"
-
"github.com/apache/incubator-answer/internal/base/constant"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
"github.com/apache/incubator-answer/internal/service/comment"
- questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
+ "github.com/apache/incubator-answer/internal/service/content"
+ "github.com/apache/incubator-answer/pkg/converter"
"github.com/apache/incubator-answer/pkg/obj"
)
type ReportHandle struct {
- questionCommon *questioncommon.QuestionCommon
- commentRepo comment.CommentRepo
- configService *config.ConfigService
- notificationQueueService notice_queue.NotificationQueueService
+ questionService *content.QuestionService
+ answerService *content.AnswerService
+ commentService *comment.CommentService
}
func NewReportHandle(
- questionCommon *questioncommon.QuestionCommon,
- commentRepo comment.CommentRepo,
- configService *config.ConfigService,
- notificationQueueService notice_queue.NotificationQueueService,
+ questionService *content.QuestionService,
+ answerService *content.AnswerService,
+ commentService *comment.CommentService,
) *ReportHandle {
return &ReportHandle{
- questionCommon: questionCommon,
- commentRepo: commentRepo,
- configService: configService,
- notificationQueueService: notificationQueueService,
+ questionService: questionService,
+ answerService: answerService,
+ commentService: commentService,
}
}
-// HandleObject this handle object status
-func (rh *ReportHandle) HandleObject(ctx context.Context, reported *entity.Report, req schema.ReportHandleReq) (err error) {
- reasonDeleteCfg, err := rh.configService.GetConfigByKey(ctx, "reason.needs_delete")
+// UpdateReportedObject this handle object status
+func (rh *ReportHandle) UpdateReportedObject(ctx context.Context,
+ report *entity.Report, req *schema.ReviewReportReq) (err error) {
+ objectKey, err := obj.GetObjectTypeStrByObjectID(report.ObjectID)
if err != nil {
return err
}
- reasonCloseCfg, err := rh.configService.GetConfigByKey(ctx, "reason.needs_close")
- if err != nil {
- return err
+ switch objectKey {
+ case constant.QuestionObjectType:
+ err = rh.updateReportedQuestionReport(ctx, report, req)
+ case constant.AnswerObjectType:
+ err = rh.updateReportedAnswerReport(ctx, report, req)
+ case constant.CommentObjectType:
+ err = rh.updateReportedCommentReport(ctx, report, req)
}
- var (
- objectID = reported.ObjectID
- reportedUserID = reported.ReportedUserID
- objectKey string
- )
+ return
+}
- objectKey, err = obj.GetObjectTypeStrByObjectID(objectID)
- if err != nil {
- return err
- }
- switch objectKey {
- case "question":
- switch req.FlaggedType {
- case reasonDeleteCfg.ID:
- err = rh.questionCommon.RemoveQuestion(ctx, &schema.RemoveQuestionReq{ID: objectID})
- case reasonCloseCfg.ID:
- err = rh.questionCommon.CloseQuestion(ctx, &schema.CloseQuestionReq{
- ID: objectID,
- CloseType: req.FlaggedType,
- CloseMsg: req.FlaggedContent,
- })
- }
- case "answer":
- switch req.FlaggedType {
- case reasonDeleteCfg.ID:
- err = rh.questionCommon.RemoveAnswer(ctx, objectID)
- }
- case "comment":
- switch req.FlaggedType {
- case reasonCloseCfg.ID:
- err = rh.commentRepo.RemoveComment(ctx, objectID)
- rh.sendNotification(ctx, reportedUserID, objectID, constant.NotificationYourCommentWasDeleted)
- }
+func (rh *ReportHandle) updateReportedQuestionReport(ctx context.Context,
+ report *entity.Report, req *schema.ReviewReportReq) (err error) {
+ switch req.OperationType {
+ case constant.ReportOperationUnlistPost:
+ err = rh.questionService.OperationQuestion(ctx, &schema.OperationQuestionReq{
+ ID: report.ObjectID, Operation: schema.QuestionOperationHide, UserID: req.UserID})
+ case constant.ReportOperationDeletePost:
+ err = rh.questionService.RemoveQuestion(ctx, &schema.RemoveQuestionReq{
+ ID: report.ObjectID, UserID: req.UserID, IsAdmin: true})
+ case constant.ReportOperationClosePost:
+ err = rh.questionService.CloseQuestion(ctx, &schema.CloseQuestionReq{
+ ID: report.ObjectID,
+ CloseType: req.CloseType,
+ CloseMsg: req.CloseMsg,
+ UserID: req.UserID,
+ })
+ case constant.ReportOperationEditPost:
+ _, err = rh.questionService.UpdateQuestion(ctx, &schema.QuestionUpdate{
+ ID: report.ObjectID,
+ Title: req.Title,
+ Content: req.Content,
+ HTML: converter.Markdown2HTML(req.Content),
+ Tags: req.Tags,
+ UserID: req.UserID,
+ NoNeedReview: true,
+ })
}
return
}
-// sendNotification send rank triggered notification
-func (rh *ReportHandle) sendNotification(ctx context.Context, reportedUserID, objectID, notificationAction string) {
- msg := &schema.NotificationMsg{
- TriggerUserID: reportedUserID,
- ReceiverUserID: reportedUserID,
- Type: schema.NotificationTypeInbox,
- ObjectID: objectID,
- ObjectType: constant.ReportObjectType,
- NotificationAction: notificationAction,
+func (rh *ReportHandle) updateReportedAnswerReport(ctx context.Context, report *entity.Report, req *schema.ReviewReportReq) (err error) {
+ switch req.OperationType {
+ case constant.ReportOperationDeletePost:
+ err = rh.answerService.RemoveAnswer(ctx, &schema.RemoveAnswerReq{
+ ID: report.ObjectID, UserID: req.UserID})
+ case constant.ReportOperationEditPost:
+ _, err = rh.answerService.Update(ctx, &schema.AnswerUpdateReq{
+ ID: report.ObjectID,
+ Title: req.Title,
+ Content: req.Content,
+ HTML: converter.Markdown2HTML(req.Content),
+ UserID: req.UserID,
+ NoNeedReview: true,
+ })
+ }
+ return nil
+}
+
+func (rh *ReportHandle) updateReportedCommentReport(ctx context.Context, report *entity.Report, req *schema.ReviewReportReq) (err error) {
+ switch req.OperationType {
+ case constant.ReportOperationDeletePost:
+ err = rh.commentService.RemoveComment(ctx, &schema.RemoveCommentReq{
+ CommentID: report.ObjectID, UserID: req.UserID})
+ case constant.ReportOperationEditPost:
+ _, err = rh.commentService.UpdateComment(ctx, &schema.UpdateCommentReq{
+ CommentID: report.ObjectID,
+ OriginalText: req.Content,
+ ParsedText: converter.Markdown2HTML(req.Content),
+ UserID: req.UserID,
+ })
}
- rh.notificationQueueService.Send(ctx, msg)
+ return nil
}