Skip to content

Commit

Permalink
fix: delete post_tag when delete tag
Browse files Browse the repository at this point in the history
  • Loading branch information
1379 authored and 1379 committed Jan 22, 2023
1 parent e9628ac commit da45e19
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions service/impl/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,19 @@ func (t tagServiceImpl) Update(ctx context.Context, id int32, tagParam *param.Ta
}

func (t tagServiceImpl) Delete(ctx context.Context, id int32) error {
tagDAL := dal.GetQueryByCtx(ctx).Tag
deleteResult, err := tagDAL.WithContext(ctx).Where(tagDAL.ID.Value(id)).Delete()
if err != nil {
return WrapDBErr(err)
}
if deleteResult.RowsAffected != 1 {
return xerr.NoType.New("delete tag failed id=%v", id).WithMsg("delete tag failed").WithStatus(xerr.StatusInternalServerError)
}
return nil
err := dal.Transaction(ctx, func(txCtx context.Context) error {
tagDAL := dal.GetQueryByCtx(txCtx).Tag
_, err := tagDAL.WithContext(txCtx).Where(tagDAL.ID.Value(id)).Delete()
if err != nil {
return WrapDBErr(err)
}

postTagDAL := dal.GetQueryByCtx(txCtx).PostTag
_, err = tagDAL.WithContext(txCtx).Where(postTagDAL.TagID.Eq(id)).Delete()
return err
})

return err
}

func (t tagServiceImpl) ListAll(ctx context.Context, sort *param.Sort) ([]*entity.Tag, error) {
Expand Down

0 comments on commit da45e19

Please sign in to comment.