feat(revision): enhance revision management with object status handling
diff --git a/internal/controller/revision_controller.go b/internal/controller/revision_controller.go index 13bee19..5757437 100644 --- a/internal/controller/revision_controller.go +++ b/internal/controller/revision_controller.go
@@ -69,6 +69,8 @@ objectID = uid.DeShortID(objectID) req := &schema.GetRevisionListReq{ ObjectID: objectID, + IsAdmin: middleware.GetUserIsAdminModerator(ctx), + UserID: middleware.GetLoginUserIDFromContext(ctx), } resp, err := rc.revisionListService.GetRevisionList(ctx, req)
diff --git a/internal/router/answer_api_router.go b/internal/router/answer_api_router.go index fc53ec4..c642b2a 100644 --- a/internal/router/answer_api_router.go +++ b/internal/router/answer_api_router.go
@@ -188,9 +188,6 @@ r.GET("/personal/comment/page", a.commentController.GetCommentPersonalWithPage) r.GET("/comment", a.commentController.GetComment) - // revision - r.GET("/revisions", a.revisionController.GetRevisionList) - // tag r.GET("/tags/page", a.tagController.GetTagWithPage) r.GET("/tags/following", a.tagController.GetFollowingTags) @@ -224,6 +221,7 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) { // revisions + r.GET("/revisions", a.revisionController.GetRevisionList) r.GET("/revisions/unreviewed", a.revisionController.GetUnreviewedRevisionList) r.PUT("/revisions/audit", a.revisionController.RevisionAudit) r.GET("/revisions/edit/check", a.revisionController.CheckCanUpdateRevision)
diff --git a/internal/schema/revision_schema.go b/internal/schema/revision_schema.go index 6f3246e..dad067f 100644 --- a/internal/schema/revision_schema.go +++ b/internal/schema/revision_schema.go
@@ -45,6 +45,8 @@ type GetRevisionListReq struct { // object id ObjectID string `validate:"required" comment:"object_id" form:"object_id"` + IsAdmin bool `json:"-"` + UserID string `json:"-"` } const RevisionAuditApprove = "approve"
diff --git a/internal/schema/simple_obj_info_schema.go b/internal/schema/simple_obj_info_schema.go index a9bcf3b..21a03ae 100644 --- a/internal/schema/simple_obj_info_schema.go +++ b/internal/schema/simple_obj_info_schema.go
@@ -35,6 +35,7 @@ CommentID string `json:"comment_id"` CommentStatus int `json:"comment_status"` TagID string `json:"tag_id"` + TagStatus int `json:"tag_status"` ObjectType string `json:"object_type"` Title string `json:"title"` Content string `json:"content"` @@ -49,6 +50,8 @@ return s.AnswerStatus == entity.AnswerStatusDeleted case constant.CommentObjectType: return s.CommentStatus == entity.CommentStatusDeleted + case constant.TagObjectType: + return s.TagStatus == entity.TagStatusDeleted } return false }
diff --git a/internal/service/content/revision_service.go b/internal/service/content/revision_service.go index 13ec65b..66e6181 100644 --- a/internal/service/content/revision_service.go +++ b/internal/service/content/revision_service.go
@@ -388,6 +388,23 @@ ) resp = []schema.GetRevisionResp{} + objInfo, infoErr := rs.objectInfoService.GetInfo(ctx, req.ObjectID) + if infoErr != nil { + return nil, infoErr + } + if !req.IsAdmin && objInfo.IsDeleted() && objInfo.ObjectCreatorUserID != req.UserID { + switch objInfo.ObjectType { + case constant.QuestionObjectType: + return nil, errors.NotFound(reason.QuestionNotFound) + case constant.AnswerObjectType: + return nil, errors.NotFound(reason.AnswerNotFound) + case constant.TagObjectType: + return nil, errors.NotFound(reason.TagNotFound) + default: + return nil, errors.NotFound(reason.ObjectNotFound) + } + } + _ = copier.Copy(&rev, req) revs, err = rs.revisionRepo.GetRevisionList(ctx, &rev)
diff --git a/internal/service/object_info/object_info.go b/internal/service/object_info/object_info.go index 5ef438f..6380b88 100644 --- a/internal/service/object_info/object_info.go +++ b/internal/service/object_info/object_info.go
@@ -277,11 +277,13 @@ break } objInfo = &schema.SimpleObjectInfo{ - ObjectID: tagInfo.ID, - TagID: tagInfo.ID, - ObjectType: objectType, - Title: tagInfo.SlugName, - Content: tagInfo.ParsedText, // todo trim + ObjectID: tagInfo.ID, + ObjectCreatorUserID: tagInfo.UserID, + TagID: tagInfo.ID, + TagStatus: tagInfo.Status, + ObjectType: objectType, + Title: tagInfo.SlugName, + Content: tagInfo.ParsedText, // todo trim } } if objInfo == nil {