mirror of https://gitee.com/answerdev/answer.git
update tag revision
This commit is contained in:
parent
977f9999a9
commit
7506806b67
|
@ -121,9 +121,10 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
|||
questionRepo := question.NewQuestionRepo(dataData, uniqueIDRepo)
|
||||
tagCommonRepo := tag_common.NewTagCommonRepo(dataData, uniqueIDRepo)
|
||||
tagRelRepo := tag.NewTagRelRepo(dataData)
|
||||
tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo)
|
||||
revisionRepo := revision.NewRevisionRepo(dataData, uniqueIDRepo)
|
||||
revisionService := revision_common.NewRevisionService(revisionRepo, userRepo)
|
||||
tagCommonService := tag_common2.NewTagCommonService(tagCommonRepo, tagRelRepo, revisionService, siteInfoCommonService)
|
||||
tagCommonService := tag_common2.NewTagCommonService(tagCommonRepo, tagRelRepo, tagRepo, revisionService, siteInfoCommonService)
|
||||
objService := object_info.NewObjService(answerRepo, questionRepo, commentCommonRepo, tagCommonRepo, tagCommonService)
|
||||
voteRepo := activity_common.NewVoteRepo(dataData, activityRepo)
|
||||
commentService := comment2.NewCommentService(commentRepo, commentCommonRepo, userCommon, objService, voteRepo)
|
||||
|
@ -135,7 +136,6 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
|||
serviceVoteRepo := activity.NewVoteRepo(dataData, uniqueIDRepo, configRepo, activityRepo, userRankRepo, voteRepo)
|
||||
voteService := service.NewVoteService(serviceVoteRepo, uniqueIDRepo, configRepo, questionRepo, answerRepo, commentCommonRepo, objService)
|
||||
voteController := controller.NewVoteController(voteService)
|
||||
tagRepo := tag.NewTagRepo(dataData, uniqueIDRepo)
|
||||
followRepo := activity_common.NewFollowRepo(dataData, uniqueIDRepo, activityRepo)
|
||||
tagService := tag2.NewTagService(tagRepo, tagCommonService, revisionService, followRepo, siteInfoCommonService)
|
||||
tagController := controller.NewTagController(tagService, tagCommonService, rankService)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/base/data"
|
||||
"github.com/answerdev/answer/internal/base/reason"
|
||||
"github.com/answerdev/answer/internal/entity"
|
||||
"github.com/answerdev/answer/internal/service/tag"
|
||||
"github.com/answerdev/answer/internal/service/tag_common"
|
||||
"github.com/answerdev/answer/internal/service/unique"
|
||||
"github.com/segmentfault/pacman/errors"
|
||||
"xorm.io/builder"
|
||||
|
@ -22,7 +22,7 @@ type tagRepo struct {
|
|||
func NewTagRepo(
|
||||
data *data.Data,
|
||||
uniqueIDRepo unique.UniqueIDRepo,
|
||||
) tag.TagRepo {
|
||||
) tag_common.TagRepo {
|
||||
return &tagRepo{
|
||||
data: data,
|
||||
uniqueIDRepo: uniqueIDRepo,
|
||||
|
|
|
@ -15,12 +15,14 @@ import (
|
|||
"github.com/answerdev/answer/internal/service/object_info"
|
||||
questioncommon "github.com/answerdev/answer/internal/service/question_common"
|
||||
"github.com/answerdev/answer/internal/service/revision"
|
||||
"github.com/answerdev/answer/internal/service/tag"
|
||||
"github.com/answerdev/answer/internal/service/tag_common"
|
||||
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
|
||||
usercommon "github.com/answerdev/answer/internal/service/user_common"
|
||||
"github.com/answerdev/answer/pkg/converter"
|
||||
"github.com/answerdev/answer/pkg/obj"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/segmentfault/pacman/errors"
|
||||
"github.com/segmentfault/pacman/log"
|
||||
)
|
||||
|
||||
// RevisionService user service
|
||||
|
@ -32,7 +34,7 @@ type RevisionService struct {
|
|||
objectInfoService *object_info.ObjService
|
||||
questionRepo questioncommon.QuestionRepo
|
||||
answerRepo answercommon.AnswerRepo
|
||||
tagRepo tag.TagRepo
|
||||
tagRepo tag_common.TagRepo
|
||||
tagCommon *tagcommon.TagCommonService
|
||||
}
|
||||
|
||||
|
@ -44,7 +46,7 @@ func NewRevisionService(
|
|||
objectInfoService *object_info.ObjService,
|
||||
questionRepo questioncommon.QuestionRepo,
|
||||
answerRepo answercommon.AnswerRepo,
|
||||
tagRepo tag.TagRepo,
|
||||
tagRepo tag_common.TagRepo,
|
||||
tagCommon *tagcommon.TagCommonService,
|
||||
|
||||
) *RevisionService {
|
||||
|
@ -168,14 +170,48 @@ func (rs *RevisionService) RevisionAudit(ctx context.Context, req *schema.Revisi
|
|||
if ok {
|
||||
tag := &entity.Tag{}
|
||||
tag.ID = taginfo.TagID
|
||||
tag.DisplayName = taginfo.DisplayName
|
||||
tag.SlugName = taginfo.SlugName
|
||||
tag.OriginalText = taginfo.OriginalText
|
||||
tag.ParsedText = taginfo.ParsedText
|
||||
saveerr := rs.tagRepo.UpdateTag(ctx, tag)
|
||||
if saveerr != nil {
|
||||
return saveerr
|
||||
}
|
||||
|
||||
tagInfo, exist, err := rs.tagCommon.GetTagByID(ctx, taginfo.TagID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exist {
|
||||
return errors.BadRequest(reason.TagNotFound)
|
||||
}
|
||||
if tagInfo.MainTagID == 0 && len(tagInfo.SlugName) > 0 {
|
||||
log.Debugf("tag %s update slug_name", tagInfo.SlugName)
|
||||
tagList, err := rs.tagRepo.GetTagList(ctx, &entity.Tag{MainTagID: converter.StringToInt64(tagInfo.ID)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateTagSlugNames := make([]string, 0)
|
||||
for _, tag := range tagList {
|
||||
updateTagSlugNames = append(updateTagSlugNames, tag.SlugName)
|
||||
}
|
||||
err = rs.tagRepo.UpdateTagSynonym(ctx, updateTagSlugNames, converter.StringToInt64(tagInfo.ID), tagInfo.MainTagSlugName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
activity_queue.AddActivity(&schema.ActivityMsg{
|
||||
UserID: revisioninfo.UserID,
|
||||
ObjectID: taginfo.TagID,
|
||||
OriginalObjectID: taginfo.TagID,
|
||||
ActivityTypeKey: constant.ActTagEdited,
|
||||
RevisionID: revisioninfo.ID,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
err = rs.revisionRepo.UpdateStatus(ctx, req.ID, entity.RevisionReviewPassStatus)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/service/activity_queue"
|
||||
"github.com/answerdev/answer/internal/service/revision_common"
|
||||
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||
"github.com/answerdev/answer/internal/service/tag_common"
|
||||
tagcommonser "github.com/answerdev/answer/internal/service/tag_common"
|
||||
"github.com/answerdev/answer/pkg/htmltext"
|
||||
|
||||
"github.com/answerdev/answer/internal/base/pager"
|
||||
|
@ -23,17 +23,10 @@ import (
|
|||
"github.com/segmentfault/pacman/log"
|
||||
)
|
||||
|
||||
type TagRepo interface {
|
||||
RemoveTag(ctx context.Context, tagID string) (err error)
|
||||
UpdateTag(ctx context.Context, tag *entity.Tag) (err error)
|
||||
UpdateTagSynonym(ctx context.Context, tagSlugNameList []string, mainTagID int64, mainTagSlugName string) (err error)
|
||||
GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error)
|
||||
}
|
||||
|
||||
// TagService user service
|
||||
type TagService struct {
|
||||
tagRepo TagRepo
|
||||
tagCommonService *tag_common.TagCommonService
|
||||
tagRepo tagcommonser.TagRepo
|
||||
tagCommonService *tagcommonser.TagCommonService
|
||||
revisionService *revision_common.RevisionService
|
||||
followCommon activity_common.FollowRepo
|
||||
siteInfoService *siteinfo_common.SiteInfoCommonService
|
||||
|
@ -41,8 +34,8 @@ type TagService struct {
|
|||
|
||||
// NewTagService new tag service
|
||||
func NewTagService(
|
||||
tagRepo TagRepo,
|
||||
tagCommonService *tag_common.TagCommonService,
|
||||
tagRepo tagcommonser.TagRepo,
|
||||
tagCommonService *tagcommonser.TagCommonService,
|
||||
revisionService *revision_common.RevisionService,
|
||||
followCommon activity_common.FollowRepo,
|
||||
siteInfoService *siteinfo_common.SiteInfoCommonService) *TagService {
|
||||
|
@ -68,66 +61,7 @@ func (ts *TagService) RemoveTag(ctx context.Context, tagID string) (err error) {
|
|||
|
||||
// UpdateTag update tag
|
||||
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{}
|
||||
_ = copier.Copy(tag, req)
|
||||
tag.ID = req.TagID
|
||||
err = ts.tagRepo.UpdateTag(ctx, tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tagInfo, exist, err := ts.tagCommonService.GetTagByID(ctx, req.TagID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exist {
|
||||
return errors.BadRequest(reason.TagNotFound)
|
||||
}
|
||||
if tagInfo.MainTagID == 0 && len(req.SlugName) > 0 {
|
||||
log.Debugf("tag %s update slug_name", tagInfo.SlugName)
|
||||
tagList, err := ts.tagRepo.GetTagList(ctx, &entity.Tag{MainTagID: converter.StringToInt64(tagInfo.ID)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateTagSlugNames := make([]string, 0)
|
||||
for _, tag := range tagList {
|
||||
updateTagSlugNames = append(updateTagSlugNames, tag.SlugName)
|
||||
}
|
||||
err = ts.tagRepo.UpdateTagSynonym(ctx, updateTagSlugNames, converter.StringToInt64(tagInfo.ID), tagInfo.MainTagSlugName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
revisionDTO := &schema.AddRevisionDTO{
|
||||
UserID: req.UserID,
|
||||
ObjectID: tag.ID,
|
||||
Title: tag.SlugName,
|
||||
Log: req.EditSummary,
|
||||
}
|
||||
tagInfoJson, _ := json.Marshal(tagInfo)
|
||||
revisionDTO.Content = string(tagInfoJson)
|
||||
revisionID, err := ts.revisionService.AddRevision(ctx, revisionDTO, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
activity_queue.AddActivity(&schema.ActivityMsg{
|
||||
UserID: req.UserID,
|
||||
ObjectID: tag.ID,
|
||||
OriginalObjectID: tag.ID,
|
||||
ActivityTypeKey: constant.ActTagEdited,
|
||||
RevisionID: revisionID,
|
||||
})
|
||||
return
|
||||
return ts.tagCommonService.UpdateTag(ctx, req)
|
||||
}
|
||||
|
||||
// GetTagInfo get tag one
|
||||
|
|
|
@ -15,6 +15,8 @@ import (
|
|||
"github.com/answerdev/answer/internal/service/activity_queue"
|
||||
"github.com/answerdev/answer/internal/service/revision_common"
|
||||
"github.com/answerdev/answer/internal/service/siteinfo_common"
|
||||
"github.com/answerdev/answer/pkg/converter"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/segmentfault/pacman/errors"
|
||||
"github.com/segmentfault/pacman/log"
|
||||
)
|
||||
|
@ -33,6 +35,13 @@ type TagCommonRepo interface {
|
|||
UpdateTagQuestionCount(ctx context.Context, tagID string, questionCount int) (err error)
|
||||
}
|
||||
|
||||
type TagRepo interface {
|
||||
RemoveTag(ctx context.Context, tagID string) (err error)
|
||||
UpdateTag(ctx context.Context, tag *entity.Tag) (err error)
|
||||
UpdateTagSynonym(ctx context.Context, tagSlugNameList []string, mainTagID int64, mainTagSlugName string) (err error)
|
||||
GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error)
|
||||
}
|
||||
|
||||
type TagRelRepo interface {
|
||||
AddTagRelList(ctx context.Context, tagList []*entity.TagRel) (err error)
|
||||
RemoveTagRelListByIDs(ctx context.Context, ids []int64) (err error)
|
||||
|
@ -48,6 +57,7 @@ type TagCommonService struct {
|
|||
revisionService *revision_common.RevisionService
|
||||
tagCommonRepo TagCommonRepo
|
||||
tagRelRepo TagRelRepo
|
||||
tagRepo TagRepo
|
||||
siteInfoService *siteinfo_common.SiteInfoCommonService
|
||||
}
|
||||
|
||||
|
@ -55,12 +65,14 @@ type TagCommonService struct {
|
|||
func NewTagCommonService(
|
||||
tagCommonRepo TagCommonRepo,
|
||||
tagRelRepo TagRelRepo,
|
||||
tagRepo TagRepo,
|
||||
revisionService *revision_common.RevisionService,
|
||||
siteInfoService *siteinfo_common.SiteInfoCommonService,
|
||||
) *TagCommonService {
|
||||
return &TagCommonService{
|
||||
tagCommonRepo: tagCommonRepo,
|
||||
tagRelRepo: tagRelRepo,
|
||||
tagRepo: tagRepo,
|
||||
revisionService: revisionService,
|
||||
siteInfoService: siteInfoService,
|
||||
}
|
||||
|
@ -584,3 +596,66 @@ func (ts *TagCommonService) CreateOrUpdateTagRelList(ctx context.Context, object
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ts *TagCommonService) 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{}
|
||||
_ = copier.Copy(tag, req)
|
||||
tag.ID = req.TagID
|
||||
err = ts.tagRepo.UpdateTag(ctx, tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tagInfo, exist, err := ts.GetTagByID(ctx, req.TagID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exist {
|
||||
return errors.BadRequest(reason.TagNotFound)
|
||||
}
|
||||
if tagInfo.MainTagID == 0 && len(req.SlugName) > 0 {
|
||||
log.Debugf("tag %s update slug_name", tagInfo.SlugName)
|
||||
tagList, err := ts.tagRepo.GetTagList(ctx, &entity.Tag{MainTagID: converter.StringToInt64(tagInfo.ID)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateTagSlugNames := make([]string, 0)
|
||||
for _, tag := range tagList {
|
||||
updateTagSlugNames = append(updateTagSlugNames, tag.SlugName)
|
||||
}
|
||||
err = ts.tagRepo.UpdateTagSynonym(ctx, updateTagSlugNames, converter.StringToInt64(tagInfo.ID), tagInfo.MainTagSlugName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
revisionDTO := &schema.AddRevisionDTO{
|
||||
UserID: req.UserID,
|
||||
ObjectID: tag.ID,
|
||||
Title: tag.SlugName,
|
||||
Log: req.EditSummary,
|
||||
}
|
||||
tagInfoJson, _ := json.Marshal(tagInfo)
|
||||
revisionDTO.Content = string(tagInfoJson)
|
||||
revisionID, err := ts.revisionService.AddRevision(ctx, revisionDTO, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
activity_queue.AddActivity(&schema.ActivityMsg{
|
||||
UserID: req.UserID,
|
||||
ObjectID: tag.ID,
|
||||
OriginalObjectID: tag.ID,
|
||||
ActivityTypeKey: constant.ActTagEdited,
|
||||
RevisionID: revisionID,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue