mirror of https://gitee.com/answerdev/answer.git
update tag revision
This commit is contained in:
parent
d1f951d066
commit
977f9999a9
|
@ -90,6 +90,8 @@ backend:
|
||||||
other: "Please enter at least one required tag."
|
other: "Please enter at least one required tag."
|
||||||
not_contain_synonym_tags:
|
not_contain_synonym_tags:
|
||||||
other: "Should not contain synonym tags."
|
other: "Should not contain synonym tags."
|
||||||
|
cannot_update:
|
||||||
|
other: "No permission to update."
|
||||||
theme:
|
theme:
|
||||||
not_found:
|
not_found:
|
||||||
other: "Theme not found."
|
other: "Theme not found."
|
||||||
|
|
|
@ -41,6 +41,7 @@ const (
|
||||||
ObjectNotFound = "error.object.not_found"
|
ObjectNotFound = "error.object.not_found"
|
||||||
TagNotFound = "error.tag.not_found"
|
TagNotFound = "error.tag.not_found"
|
||||||
TagNotContainSynonym = "error.tag.not_contain_synonym_tags"
|
TagNotContainSynonym = "error.tag.not_contain_synonym_tags"
|
||||||
|
TagCannotUpdate = "error.tag.cannot_update"
|
||||||
RankFailToMeetTheCondition = "error.rank.fail_to_meet_the_condition"
|
RankFailToMeetTheCondition = "error.rank.fail_to_meet_the_condition"
|
||||||
ThemeNotFound = "error.theme.not_found"
|
ThemeNotFound = "error.theme.not_found"
|
||||||
LangNotFound = "error.lang.not_found"
|
LangNotFound = "error.lang.not_found"
|
||||||
|
|
|
@ -190,6 +190,16 @@ func (as *AnswerService) Insert(ctx context.Context, req *schema.AnswerAddReq) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq) (string, error) {
|
func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq) (string, error) {
|
||||||
|
var canUpdate bool
|
||||||
|
_, existUnreviewed, err := as.revisionService.ExistUnreviewedByObjectID(ctx, req.ID)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if existUnreviewed {
|
||||||
|
err = errors.BadRequest(reason.AnswerCannotUpdate)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
questionInfo, exist, err := as.questionRepo.GetQuestion(ctx, req.QuestionID)
|
questionInfo, exist, err := as.questionRepo.GetQuestion(ctx, req.QuestionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -197,7 +207,7 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
|
||||||
if !exist {
|
if !exist {
|
||||||
return "", errors.BadRequest(reason.QuestionNotFound)
|
return "", errors.BadRequest(reason.QuestionNotFound)
|
||||||
}
|
}
|
||||||
if !req.IsAdmin {
|
|
||||||
answerInfo, exist, err := as.answerRepo.GetByID(ctx, req.ID)
|
answerInfo, exist, err := as.answerRepo.GetByID(ctx, req.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -205,10 +215,6 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
|
||||||
if !exist {
|
if !exist {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
if answerInfo.UserID != req.UserID {
|
|
||||||
return "", errors.BadRequest(reason.AnswerCannotUpdate)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
insertData := new(entity.Answer)
|
insertData := new(entity.Answer)
|
||||||
|
@ -218,6 +224,18 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
|
||||||
insertData.OriginalText = req.Content
|
insertData.OriginalText = req.Content
|
||||||
insertData.ParsedText = req.HTML
|
insertData.ParsedText = req.HTML
|
||||||
insertData.UpdatedAt = now
|
insertData.UpdatedAt = now
|
||||||
|
|
||||||
|
revisionDTO := &schema.AddRevisionDTO{
|
||||||
|
UserID: req.UserID,
|
||||||
|
ObjectID: req.ID,
|
||||||
|
Title: "",
|
||||||
|
Log: req.EditSummary,
|
||||||
|
}
|
||||||
|
|
||||||
|
if answerInfo.UserID != req.UserID && !req.IsAdmin {
|
||||||
|
revisionDTO.Status = entity.RevisionUnreviewedStatus
|
||||||
|
} else {
|
||||||
|
canUpdate = true
|
||||||
if err = as.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "update_time"}); err != nil {
|
if err = as.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "update_time"}); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -225,20 +243,17 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return insertData.ID, err
|
return insertData.ID, err
|
||||||
}
|
}
|
||||||
revisionDTO := &schema.AddRevisionDTO{
|
as.notificationUpdateAnswer(ctx, questionInfo.UserID, insertData.ID, req.UserID)
|
||||||
UserID: req.UserID,
|
revisionDTO.Status = entity.RevisionReviewPassStatus
|
||||||
ObjectID: req.ID,
|
|
||||||
Title: "",
|
|
||||||
Log: req.EditSummary,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
infoJSON, _ := json.Marshal(insertData)
|
infoJSON, _ := json.Marshal(insertData)
|
||||||
revisionDTO.Content = string(infoJSON)
|
revisionDTO.Content = string(infoJSON)
|
||||||
revisionID, err := as.revisionService.AddRevision(ctx, revisionDTO, true)
|
revisionID, err := as.revisionService.AddRevision(ctx, revisionDTO, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return insertData.ID, err
|
return insertData.ID, err
|
||||||
}
|
}
|
||||||
as.notificationUpdateAnswer(ctx, questionInfo.UserID, insertData.ID, req.UserID)
|
if canUpdate {
|
||||||
|
|
||||||
activity_queue.AddActivity(&schema.ActivityMsg{
|
activity_queue.AddActivity(&schema.ActivityMsg{
|
||||||
UserID: insertData.UserID,
|
UserID: insertData.UserID,
|
||||||
ObjectID: insertData.ID,
|
ObjectID: insertData.ID,
|
||||||
|
@ -246,6 +261,8 @@ func (as *AnswerService) Update(ctx context.Context, req *schema.AnswerUpdateReq
|
||||||
ActivityTypeKey: constant.ActAnswerEdited,
|
ActivityTypeKey: constant.ActAnswerEdited,
|
||||||
RevisionID: revisionID,
|
RevisionID: revisionID,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return insertData.ID, nil
|
return insertData.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/answerdev/answer/internal/base/constant"
|
"github.com/answerdev/answer/internal/base/constant"
|
||||||
|
"github.com/answerdev/answer/internal/base/reason"
|
||||||
"github.com/answerdev/answer/internal/entity"
|
"github.com/answerdev/answer/internal/entity"
|
||||||
"github.com/answerdev/answer/internal/schema"
|
"github.com/answerdev/answer/internal/schema"
|
||||||
"github.com/answerdev/answer/internal/service/activity_queue"
|
"github.com/answerdev/answer/internal/service/activity_queue"
|
||||||
answercommon "github.com/answerdev/answer/internal/service/answer_common"
|
answercommon "github.com/answerdev/answer/internal/service/answer_common"
|
||||||
|
"github.com/answerdev/answer/internal/service/notice_queue"
|
||||||
"github.com/answerdev/answer/internal/service/object_info"
|
"github.com/answerdev/answer/internal/service/object_info"
|
||||||
questioncommon "github.com/answerdev/answer/internal/service/question_common"
|
questioncommon "github.com/answerdev/answer/internal/service/question_common"
|
||||||
"github.com/answerdev/answer/internal/service/revision"
|
"github.com/answerdev/answer/internal/service/revision"
|
||||||
|
@ -18,6 +20,7 @@ import (
|
||||||
usercommon "github.com/answerdev/answer/internal/service/user_common"
|
usercommon "github.com/answerdev/answer/internal/service/user_common"
|
||||||
"github.com/answerdev/answer/pkg/obj"
|
"github.com/answerdev/answer/pkg/obj"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
|
"github.com/segmentfault/pacman/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RevisionService user service
|
// RevisionService user service
|
||||||
|
@ -126,9 +129,38 @@ func (rs *RevisionService) RevisionAudit(ctx context.Context, req *schema.Revisi
|
||||||
insertData.OriginalText = answerinfo.Content
|
insertData.OriginalText = answerinfo.Content
|
||||||
insertData.ParsedText = answerinfo.HTML
|
insertData.ParsedText = answerinfo.HTML
|
||||||
insertData.UpdatedAt = now
|
insertData.UpdatedAt = now
|
||||||
if saveerr := rs.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "update_time"}); err != nil {
|
saveerr := rs.answerRepo.UpdateAnswer(ctx, insertData, []string{"original_text", "parsed_text", "update_time"})
|
||||||
|
if saveerr != nil {
|
||||||
return saveerr
|
return saveerr
|
||||||
}
|
}
|
||||||
|
saveerr = rs.questionCommon.UpdataPostTime(ctx, answerinfo.QuestionID)
|
||||||
|
if saveerr != nil {
|
||||||
|
return saveerr
|
||||||
|
}
|
||||||
|
questionInfo, exist, err := rs.questionRepo.GetQuestion(ctx, answerinfo.QuestionID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exist {
|
||||||
|
return errors.BadRequest(reason.QuestionNotFound)
|
||||||
|
}
|
||||||
|
msg := &schema.NotificationMsg{
|
||||||
|
TriggerUserID: revisioninfo.UserID,
|
||||||
|
ReceiverUserID: questionInfo.UserID,
|
||||||
|
Type: schema.NotificationTypeInbox,
|
||||||
|
ObjectID: answerinfo.ID,
|
||||||
|
}
|
||||||
|
msg.ObjectType = constant.AnswerObjectType
|
||||||
|
msg.NotificationAction = constant.UpdateAnswer
|
||||||
|
notice_queue.AddNotification(msg)
|
||||||
|
|
||||||
|
activity_queue.AddActivity(&schema.ActivityMsg{
|
||||||
|
UserID: revisioninfo.UserID,
|
||||||
|
ObjectID: insertData.ID,
|
||||||
|
OriginalObjectID: insertData.ID,
|
||||||
|
ActivityTypeKey: constant.ActAnswerEdited,
|
||||||
|
RevisionID: revisioninfo.ID,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
case constant.TagObjectType:
|
case constant.TagObjectType:
|
||||||
|
|
|
@ -68,6 +68,15 @@ func (ts *TagService) RemoveTag(ctx context.Context, tagID string) (err error) {
|
||||||
|
|
||||||
// UpdateTag update tag
|
// UpdateTag update tag
|
||||||
func (ts *TagService) UpdateTag(ctx context.Context, req *schema.UpdateTagReq) (err error) {
|
func (ts *TagService) UpdateTag(ctx context.Context, req *schema.UpdateTagReq) (err error) {
|
||||||
|
_, existUnreviewed, err := ts.revisionService.ExistUnreviewedByObjectID(ctx, req.TagID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if existUnreviewed {
|
||||||
|
err = errors.BadRequest(reason.AnswerCannotUpdate)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
tag := &entity.Tag{}
|
tag := &entity.Tag{}
|
||||||
_ = copier.Copy(tag, req)
|
_ = copier.Copy(tag, req)
|
||||||
tag.ID = req.TagID
|
tag.ID = req.TagID
|
||||||
|
|
Loading…
Reference in New Issue