Merge branch 'feat/1.0.5/deltag' into test

This commit is contained in:
aichy126 2023-02-14 15:54:32 +08:00
commit eb19f0dc7f
3 changed files with 21 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/service/tag_common"
"github.com/answerdev/answer/internal/service/unique"
"github.com/answerdev/answer/pkg/converter"
"github.com/segmentfault/pacman/errors"
"xorm.io/builder"
)
@ -61,6 +62,14 @@ func (tr *tagRepo) UpdateTagSynonym(ctx context.Context, tagSlugNameList []strin
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
func (tr *tagRepo) GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error) {
tagList = make([]*entity.Tag, 0)

View File

@ -50,14 +50,24 @@ func NewTagService(
// RemoveTag delete tag
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)
if err != nil {
return err
}
//If the tag has associated problems, it cannot be deleted
if tagCount > 0 {
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
err = ts.tagRepo.RemoveTag(ctx, req.TagID)
if err != nil {

View File

@ -38,6 +38,7 @@ 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)
GetTagSynonymCount(ctx context.Context, tagID string) (count int64, err error)
GetTagList(ctx context.Context, tag *entity.Tag) (tagList []*entity.Tag, err error)
}