Skip to content

Commit 9ea13af

Browse files
committed
feat(revision): enhance revision management with object status handling
1 parent ef54781 commit 9ea13af

6 files changed

Lines changed: 32 additions & 8 deletions

File tree

internal/controller/revision_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ func (rc *RevisionController) GetRevisionList(ctx *gin.Context) {
6969
objectID = uid.DeShortID(objectID)
7070
req := &schema.GetRevisionListReq{
7171
ObjectID: objectID,
72+
IsAdmin: middleware.GetUserIsAdminModerator(ctx),
73+
UserID: middleware.GetLoginUserIDFromContext(ctx),
7274
}
7375

7476
resp, err := rc.revisionListService.GetRevisionList(ctx, req)

internal/router/answer_api_router.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ func (a *AnswerAPIRouter) RegisterUnAuthAnswerAPIRouter(r *gin.RouterGroup) {
188188
r.GET("/personal/comment/page", a.commentController.GetCommentPersonalWithPage)
189189
r.GET("/comment", a.commentController.GetComment)
190190

191-
// revision
192-
r.GET("/revisions", a.revisionController.GetRevisionList)
193-
194191
// tag
195192
r.GET("/tags/page", a.tagController.GetTagWithPage)
196193
r.GET("/tags/following", a.tagController.GetFollowingTags)
@@ -224,6 +221,7 @@ func (a *AnswerAPIRouter) RegisterAuthUserWithAnyStatusAnswerAPIRouter(r *gin.Ro
224221

225222
func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
226223
// revisions
224+
r.GET("/revisions", a.revisionController.GetRevisionList)
227225
r.GET("/revisions/unreviewed", a.revisionController.GetUnreviewedRevisionList)
228226
r.PUT("/revisions/audit", a.revisionController.RevisionAudit)
229227
r.GET("/revisions/edit/check", a.revisionController.CheckCanUpdateRevision)

internal/schema/revision_schema.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type AddRevisionDTO struct {
4545
type GetRevisionListReq struct {
4646
// object id
4747
ObjectID string `validate:"required" comment:"object_id" form:"object_id"`
48+
IsAdmin bool `json:"-"`
49+
UserID string `json:"-"`
4850
}
4951

5052
const RevisionAuditApprove = "approve"

internal/schema/simple_obj_info_schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type SimpleObjectInfo struct {
3535
CommentID string `json:"comment_id"`
3636
CommentStatus int `json:"comment_status"`
3737
TagID string `json:"tag_id"`
38+
TagStatus int `json:"tag_status"`
3839
ObjectType string `json:"object_type"`
3940
Title string `json:"title"`
4041
Content string `json:"content"`
@@ -49,6 +50,8 @@ func (s *SimpleObjectInfo) IsDeleted() bool {
4950
return s.AnswerStatus == entity.AnswerStatusDeleted
5051
case constant.CommentObjectType:
5152
return s.CommentStatus == entity.CommentStatusDeleted
53+
case constant.TagObjectType:
54+
return s.TagStatus == entity.TagStatusDeleted
5255
}
5356
return false
5457
}

internal/service/content/revision_service.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,23 @@ func (rs *RevisionService) GetRevisionList(ctx context.Context, req *schema.GetR
388388
)
389389

390390
resp = []schema.GetRevisionResp{}
391+
objInfo, infoErr := rs.objectInfoService.GetInfo(ctx, req.ObjectID)
392+
if infoErr != nil {
393+
return nil, infoErr
394+
}
395+
if !req.IsAdmin && objInfo.IsDeleted() && objInfo.ObjectCreatorUserID != req.UserID {
396+
switch objInfo.ObjectType {
397+
case constant.QuestionObjectType:
398+
return nil, errors.NotFound(reason.QuestionNotFound)
399+
case constant.AnswerObjectType:
400+
return nil, errors.NotFound(reason.AnswerNotFound)
401+
case constant.TagObjectType:
402+
return nil, errors.NotFound(reason.TagNotFound)
403+
default:
404+
return nil, errors.NotFound(reason.ObjectNotFound)
405+
}
406+
}
407+
391408
_ = copier.Copy(&rev, req)
392409

393410
revs, err = rs.revisionRepo.GetRevisionList(ctx, &rev)

internal/service/object_info/object_info.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,13 @@ func (os *ObjService) GetInfo(ctx context.Context, objectID string) (objInfo *sc
277277
break
278278
}
279279
objInfo = &schema.SimpleObjectInfo{
280-
ObjectID: tagInfo.ID,
281-
TagID: tagInfo.ID,
282-
ObjectType: objectType,
283-
Title: tagInfo.SlugName,
284-
Content: tagInfo.ParsedText, // todo trim
280+
ObjectID: tagInfo.ID,
281+
ObjectCreatorUserID: tagInfo.UserID,
282+
TagID: tagInfo.ID,
283+
TagStatus: tagInfo.Status,
284+
ObjectType: objectType,
285+
Title: tagInfo.SlugName,
286+
Content: tagInfo.ParsedText, // todo trim
285287
}
286288
}
287289
if objInfo == nil {

0 commit comments

Comments
 (0)