mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/1.0.5/deltag' into test
This commit is contained in:
commit
eb19f0dc7f
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/answerdev/answer/internal/entity"
|
"github.com/answerdev/answer/internal/entity"
|
||||||
"github.com/answerdev/answer/internal/service/tag_common"
|
"github.com/answerdev/answer/internal/service/tag_common"
|
||||||
"github.com/answerdev/answer/internal/service/unique"
|
"github.com/answerdev/answer/internal/service/unique"
|
||||||
|
"github.com/answerdev/answer/pkg/converter"
|
||||||
"github.com/segmentfault/pacman/errors"
|
"github.com/segmentfault/pacman/errors"
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
@ -61,6 +62,14 @@ func (tr *tagRepo) UpdateTagSynonym(ctx context.Context, tagSlugNameList []strin
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tr *tagRepo) GetTagSynonymCount(ctx context.Context, tagID string) (count int64, err error) {
|
||||||
|
count, err = tr.data.DB.Count(&entity.Tag{MainTagID: converter.StringToInt64(tagID), Status: entity.TagStatusAvailable})
|
||||||
|
if err != nil {
|
||||||
|
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// GetTagList get tag list all
|
// GetTagList get tag list all
|
||||||
func (tr *tagRepo) GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error) {
|
func (tr *tagRepo) GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error) {
|
||||||
tagList = make([]*entity.Tag, 0)
|
tagList = make([]*entity.Tag, 0)
|
||||||
|
|
|
@ -50,14 +50,24 @@ func NewTagService(
|
||||||
|
|
||||||
// RemoveTag delete tag
|
// RemoveTag delete tag
|
||||||
func (ts *TagService) RemoveTag(ctx context.Context, req *schema.RemoveTagReq) (err error) {
|
func (ts *TagService) RemoveTag(ctx context.Context, req *schema.RemoveTagReq) (err error) {
|
||||||
|
//If the tag has associated problems, it cannot be deleted
|
||||||
tagCount, err := ts.tagCommonService.CountTagRelByTagID(ctx, req.TagID)
|
tagCount, err := ts.tagCommonService.CountTagRelByTagID(ctx, req.TagID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//If the tag has associated problems, it cannot be deleted
|
|
||||||
if tagCount > 0 {
|
if tagCount > 0 {
|
||||||
return errors.BadRequest(reason.TagIsUsedCannotDelete)
|
return errors.BadRequest(reason.TagIsUsedCannotDelete)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If the tag has associated problems, it cannot be deleted
|
||||||
|
tagSynonymCount, err := ts.tagRepo.GetTagSynonymCount(ctx, req.TagID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if tagSynonymCount > 0 {
|
||||||
|
return errors.BadRequest(reason.TagIsUsedCannotDelete)
|
||||||
|
}
|
||||||
|
|
||||||
// tagRelRepo
|
// tagRelRepo
|
||||||
err = ts.tagRepo.RemoveTag(ctx, req.TagID)
|
err = ts.tagRepo.RemoveTag(ctx, req.TagID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -38,6 +38,7 @@ type TagRepo interface {
|
||||||
RemoveTag(ctx context.Context, tagID string) (err error)
|
RemoveTag(ctx context.Context, tagID string) (err error)
|
||||||
UpdateTag(ctx context.Context, tag *entity.Tag) (err error)
|
UpdateTag(ctx context.Context, tag *entity.Tag) (err error)
|
||||||
UpdateTagSynonym(ctx context.Context, tagSlugNameList []string, mainTagID int64, mainTagSlugName string) (err error)
|
UpdateTagSynonym(ctx context.Context, tagSlugNameList []string, mainTagID int64, mainTagSlugName string) (err error)
|
||||||
|
GetTagSynonymCount(ctx context.Context, tagID string) (count int64, err error)
|
||||||
GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error)
|
GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue