From be4bc4ab1f1f60707263a9c0a1cdc59ccfbd86d3 Mon Sep 17 00:00:00 2001 From: zhu327 Date: Tue, 26 Dec 2023 20:25:05 +0800 Subject: [PATCH 1/4] update: delete subject template group when delete subject --- .../dao/mock/subject_template_group.go | 14 +++++++ pkg/database/dao/subject_template_group.go | 9 +++- pkg/service/group.go | 10 +++++ pkg/service/group_test.go | 42 +++++++++++++++++-- 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/pkg/database/dao/mock/subject_template_group.go b/pkg/database/dao/mock/subject_template_group.go index d9d8ce65..ace33a92 100644 --- a/pkg/database/dao/mock/subject_template_group.go +++ b/pkg/database/dao/mock/subject_template_group.go @@ -49,6 +49,20 @@ func (mr *MockSubjectTemplateGroupManagerMockRecorder) BulkCreateWithTx(tx, rela return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkCreateWithTx", reflect.TypeOf((*MockSubjectTemplateGroupManager)(nil).BulkCreateWithTx), tx, relations) } +// BulkDeleteBySubjectPKs mocks base method. +func (m *MockSubjectTemplateGroupManager) BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BulkDeleteBySubjectPKs", tx, subjectPKs) + ret0, _ := ret[0].(error) + return ret0 +} + +// BulkDeleteBySubjectPKs indicates an expected call of BulkDeleteBySubjectPKs. +func (mr *MockSubjectTemplateGroupManagerMockRecorder) BulkDeleteBySubjectPKs(tx, subjectPKs interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkDeleteBySubjectPKs", reflect.TypeOf((*MockSubjectTemplateGroupManager)(nil).BulkDeleteBySubjectPKs), tx, subjectPKs) +} + // BulkDeleteWithTx mocks base method. func (m *MockSubjectTemplateGroupManager) BulkDeleteWithTx(tx *sqlx.Tx, relations []dao.SubjectTemplateGroup) error { m.ctrl.T.Helper() diff --git a/pkg/database/dao/subject_template_group.go b/pkg/database/dao/subject_template_group.go index 6961ccdc..66463edd 100644 --- a/pkg/database/dao/subject_template_group.go +++ b/pkg/database/dao/subject_template_group.go @@ -34,6 +34,7 @@ type SubjectTemplateGroup struct { type SubjectTemplateGroupManager interface { GetTemplateGroupMemberCount(groupPK, templateID int64) (int64, error) + GetMaxExpiredAtBySubjectGroup(subjectPK, groupPK int64, excludeTemplateID int64) (int64, error) ListPagingTemplateGroupMember( groupPK, templateID int64, limit, offset int64, @@ -46,7 +47,7 @@ type SubjectTemplateGroupManager interface { BulkUpdateExpiredAtWithTx(tx *sqlx.Tx, relations []SubjectTemplateGroup) error BulkUpdateExpiredAtByRelationWithTx(tx *sqlx.Tx, relations []SubjectRelation) error BulkDeleteWithTx(tx *sqlx.Tx, relations []SubjectTemplateGroup) error - GetMaxExpiredAtBySubjectGroup(subjectPK, groupPK int64, excludeTemplateID int64) (int64, error) + BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error } type subjectTemplateGroupManager struct { @@ -235,3 +236,9 @@ func (m *subjectTemplateGroupManager) ListThinRelationWithMaxExpiredAtByGroupPK( return relations, err } + +func (m *subjectTemplateGroupManager) BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error { + sql := `DELETE FROM subject_template_group + WHERE subject_pk in (?)` + return database.SqlxDeleteWithTx(tx, sql, subjectPKs) +} diff --git a/pkg/service/group.go b/pkg/service/group.go index 2eb775c9..f5d648ce 100644 --- a/pkg/service/group.go +++ b/pkg/service/group.go @@ -899,6 +899,16 @@ func (l *groupService) BulkDeleteBySubjectPKsWithTx(tx *sqlx.Tx, subjectPKs []in err, "manager.BulkDeleteBySubjectPKs subject_pks=`%+v` fail", subjectPKs) } + // 批量删除subject template group + err = l.subjectTemplateGroupManager.BulkDeleteBySubjectPKs(tx, subjectPKs) + if err != nil { + return errorWrapf( + err, + "subjectTemplateGroupManager.BulkDeleteBySubjectPKsWithTx subjectPKs=`%+v` fail", + subjectPKs, + ) + } + // 批量删除用户的subject system group err = l.subjectSystemGroupManager.DeleteBySubjectPKsWithTx(tx, subjectPKs) if err != nil { diff --git a/pkg/service/group_test.go b/pkg/service/group_test.go index 77e7e47e..59f2d8af 100644 --- a/pkg/service/group_test.go +++ b/pkg/service/group_test.go @@ -94,6 +94,28 @@ var _ = Describe("GroupService", func() { assert.Contains(GinkgoT(), err.Error(), "BulkDeleteBySubjectPKs") }) + It("manager.BulkDeleteBySubjectPKs fail", func() { + mockSubjectService := mock.NewMockSubjectGroupManager(ctl) + + mockSubjectService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + nil, + ).AnyTimes() + + mockSubjectTemplateGroupService := mock.NewMockSubjectTemplateGroupManager(ctl) + mockSubjectTemplateGroupService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + errors.New("error"), + ).AnyTimes() + + manager := &groupService{ + manager: mockSubjectService, + subjectTemplateGroupManager: mockSubjectTemplateGroupService, + } + + err := manager.BulkDeleteBySubjectPKsWithTx(nil, []int64{1, 2}) + assert.Error(GinkgoT(), err) + assert.Contains(GinkgoT(), err.Error(), "subjectTemplateGroupManager.BulkDeleteBySubjectPKsWithTx") + }) + It("subjectSystemGroupManager.DeleteBySubjectPKsWithTx fail", func() { mockSubjectService := mock.NewMockSubjectGroupManager(ctl) @@ -101,14 +123,20 @@ var _ = Describe("GroupService", func() { nil, ).AnyTimes() + mockSubjectTemplateGroupService := mock.NewMockSubjectTemplateGroupManager(ctl) + mockSubjectTemplateGroupService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + nil, + ).AnyTimes() + mockSubjectSystemGroupService := mock.NewMockSubjectSystemGroupManager(ctl) mockSubjectSystemGroupService.EXPECT().DeleteBySubjectPKsWithTx(gomock.Any(), []int64{1, 2}).Return( errors.New("error"), ).AnyTimes() manager := &groupService{ - manager: mockSubjectService, - subjectSystemGroupManager: mockSubjectSystemGroupService, + manager: mockSubjectService, + subjectSystemGroupManager: mockSubjectSystemGroupService, + subjectTemplateGroupManager: mockSubjectTemplateGroupService, } err := manager.BulkDeleteBySubjectPKsWithTx(nil, []int64{1, 2}) @@ -123,14 +151,20 @@ var _ = Describe("GroupService", func() { nil, ).AnyTimes() + mockSubjectTemplateGroupService := mock.NewMockSubjectTemplateGroupManager(ctl) + mockSubjectTemplateGroupService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + nil, + ).AnyTimes() + mockSubjectSystemGroupService := mock.NewMockSubjectSystemGroupManager(ctl) mockSubjectSystemGroupService.EXPECT().DeleteBySubjectPKsWithTx(gomock.Any(), []int64{1, 2}).Return( nil, ).AnyTimes() manager := &groupService{ - manager: mockSubjectService, - subjectSystemGroupManager: mockSubjectSystemGroupService, + manager: mockSubjectService, + subjectSystemGroupManager: mockSubjectSystemGroupService, + subjectTemplateGroupManager: mockSubjectTemplateGroupService, } err := manager.BulkDeleteBySubjectPKsWithTx(nil, []int64{1, 2}) From 25f539b65f6adb359e6f5588dd74d51b89e5c49c Mon Sep 17 00:00:00 2001 From: zhu327 Date: Thu, 28 Dec 2023 11:53:13 +0800 Subject: [PATCH 2/4] fix group delete --- pkg/database/dao/group_resource_policy.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/database/dao/group_resource_policy.go b/pkg/database/dao/group_resource_policy.go index 647c2dba..1f6e44a0 100644 --- a/pkg/database/dao/group_resource_policy.go +++ b/pkg/database/dao/group_resource_policy.go @@ -216,6 +216,10 @@ func (m *groupResourcePolicyManager) BulkDeleteByGroupPKsWithTx( tx *sqlx.Tx, groupPKs []int64, ) error { + if len(groupPKs) == 0 { + return nil + } + sql := `DELETE FROM rbac_group_resource_policy WHERE group_pk IN (?)` return database.SqlxDeleteWithTx(tx, sql, groupPKs) } From 6e4da90715379dbb99a293f868841f45b3796eb3 Mon Sep 17 00:00:00 2001 From: zhu327 Date: Thu, 28 Dec 2023 18:07:25 +0800 Subject: [PATCH 3/4] fix: update by cr --- pkg/database/dao/mock/subject_group.go | 24 +++++++++---------- .../dao/mock/subject_template_group.go | 12 +++++----- pkg/database/dao/subject_group.go | 12 +++++----- pkg/database/dao/subject_template_group.go | 4 ++-- pkg/service/group.go | 6 ++--- pkg/service/group_test.go | 14 +++++------ 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/pkg/database/dao/mock/subject_group.go b/pkg/database/dao/mock/subject_group.go index 25405af0..154d6eac 100644 --- a/pkg/database/dao/mock/subject_group.go +++ b/pkg/database/dao/mock/subject_group.go @@ -64,32 +64,32 @@ func (mr *MockSubjectGroupManagerMockRecorder) BulkDeleteByGroupMembersWithTx(tx return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkDeleteByGroupMembersWithTx", reflect.TypeOf((*MockSubjectGroupManager)(nil).BulkDeleteByGroupMembersWithTx), tx, groupPK, subjectPKs) } -// BulkDeleteByGroupPKs mocks base method. -func (m *MockSubjectGroupManager) BulkDeleteByGroupPKs(tx *sqlx.Tx, groupPKs []int64) error { +// BulkDeleteByGroupPKsWithTx mocks base method. +func (m *MockSubjectGroupManager) BulkDeleteByGroupPKsWithTx(tx *sqlx.Tx, groupPKs []int64) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BulkDeleteByGroupPKs", tx, groupPKs) + ret := m.ctrl.Call(m, "BulkDeleteByGroupPKsWithTx", tx, groupPKs) ret0, _ := ret[0].(error) return ret0 } -// BulkDeleteByGroupPKs indicates an expected call of BulkDeleteByGroupPKs. -func (mr *MockSubjectGroupManagerMockRecorder) BulkDeleteByGroupPKs(tx, groupPKs interface{}) *gomock.Call { +// BulkDeleteByGroupPKsWithTx indicates an expected call of BulkDeleteByGroupPKsWithTx. +func (mr *MockSubjectGroupManagerMockRecorder) BulkDeleteByGroupPKsWithTx(tx, groupPKs interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkDeleteByGroupPKs", reflect.TypeOf((*MockSubjectGroupManager)(nil).BulkDeleteByGroupPKs), tx, groupPKs) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkDeleteByGroupPKsWithTx", reflect.TypeOf((*MockSubjectGroupManager)(nil).BulkDeleteByGroupPKsWithTx), tx, groupPKs) } -// BulkDeleteBySubjectPKs mocks base method. -func (m *MockSubjectGroupManager) BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error { +// BulkDeleteBySubjectPKsWithTx mocks base method. +func (m *MockSubjectGroupManager) BulkDeleteBySubjectPKsWithTx(tx *sqlx.Tx, subjectPKs []int64) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BulkDeleteBySubjectPKs", tx, subjectPKs) + ret := m.ctrl.Call(m, "BulkDeleteBySubjectPKsWithTx", tx, subjectPKs) ret0, _ := ret[0].(error) return ret0 } -// BulkDeleteBySubjectPKs indicates an expected call of BulkDeleteBySubjectPKs. -func (mr *MockSubjectGroupManagerMockRecorder) BulkDeleteBySubjectPKs(tx, subjectPKs interface{}) *gomock.Call { +// BulkDeleteBySubjectPKsWithTx indicates an expected call of BulkDeleteBySubjectPKsWithTx. +func (mr *MockSubjectGroupManagerMockRecorder) BulkDeleteBySubjectPKsWithTx(tx, subjectPKs interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkDeleteBySubjectPKs", reflect.TypeOf((*MockSubjectGroupManager)(nil).BulkDeleteBySubjectPKs), tx, subjectPKs) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkDeleteBySubjectPKsWithTx", reflect.TypeOf((*MockSubjectGroupManager)(nil).BulkDeleteBySubjectPKsWithTx), tx, subjectPKs) } // BulkUpdateExpiredAtWithTx mocks base method. diff --git a/pkg/database/dao/mock/subject_template_group.go b/pkg/database/dao/mock/subject_template_group.go index ace33a92..f9ca1159 100644 --- a/pkg/database/dao/mock/subject_template_group.go +++ b/pkg/database/dao/mock/subject_template_group.go @@ -49,18 +49,18 @@ func (mr *MockSubjectTemplateGroupManagerMockRecorder) BulkCreateWithTx(tx, rela return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkCreateWithTx", reflect.TypeOf((*MockSubjectTemplateGroupManager)(nil).BulkCreateWithTx), tx, relations) } -// BulkDeleteBySubjectPKs mocks base method. -func (m *MockSubjectTemplateGroupManager) BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error { +// BulkDeleteBySubjectPKsWithTx mocks base method. +func (m *MockSubjectTemplateGroupManager) BulkDeleteBySubjectPKsWithTx(tx *sqlx.Tx, subjectPKs []int64) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BulkDeleteBySubjectPKs", tx, subjectPKs) + ret := m.ctrl.Call(m, "BulkDeleteBySubjectPKsWithTx", tx, subjectPKs) ret0, _ := ret[0].(error) return ret0 } -// BulkDeleteBySubjectPKs indicates an expected call of BulkDeleteBySubjectPKs. -func (mr *MockSubjectTemplateGroupManagerMockRecorder) BulkDeleteBySubjectPKs(tx, subjectPKs interface{}) *gomock.Call { +// BulkDeleteBySubjectPKsWithTx indicates an expected call of BulkDeleteBySubjectPKsWithTx. +func (mr *MockSubjectTemplateGroupManagerMockRecorder) BulkDeleteBySubjectPKsWithTx(tx, subjectPKs interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkDeleteBySubjectPKs", reflect.TypeOf((*MockSubjectTemplateGroupManager)(nil).BulkDeleteBySubjectPKs), tx, subjectPKs) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BulkDeleteBySubjectPKsWithTx", reflect.TypeOf((*MockSubjectTemplateGroupManager)(nil).BulkDeleteBySubjectPKsWithTx), tx, subjectPKs) } // BulkDeleteWithTx mocks base method. diff --git a/pkg/database/dao/subject_group.go b/pkg/database/dao/subject_group.go index ea8524e1..5efbab4b 100644 --- a/pkg/database/dao/subject_group.go +++ b/pkg/database/dao/subject_group.go @@ -68,8 +68,8 @@ type SubjectGroupManager interface { FilterGroupPKsHasMemberBeforeExpiredAt(groupPKs []int64, expiredAt int64) ([]int64, error) BulkCreateWithTx(tx *sqlx.Tx, relations []SubjectRelation) error - BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error - BulkDeleteByGroupPKs(tx *sqlx.Tx, groupPKs []int64) error + BulkDeleteBySubjectPKsWithTx(tx *sqlx.Tx, subjectPKs []int64) error + BulkDeleteByGroupPKsWithTx(tx *sqlx.Tx, groupPKs []int64) error BulkUpdateExpiredAtWithTx(tx *sqlx.Tx, relations []SubjectRelation) error ListGroupMember(groupPK int64) ([]SubjectRelation, error) @@ -352,16 +352,16 @@ func (m *subjectGroupManager) BulkCreateWithTx(tx *sqlx.Tx, relations []SubjectR return m.bulkInsertWithTx(tx, relations) } -// BulkDeleteBySubjectPKs ... -func (m *subjectGroupManager) BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error { +// BulkDeleteBySubjectPKsWithTx ... +func (m *subjectGroupManager) BulkDeleteBySubjectPKsWithTx(tx *sqlx.Tx, subjectPKs []int64) error { if len(subjectPKs) == 0 { return nil } return m.bulkDeleteBySubjectPKs(tx, subjectPKs) } -// BulkDeleteByGroupPKs ... -func (m *subjectGroupManager) BulkDeleteByGroupPKs(tx *sqlx.Tx, groupPKs []int64) error { +// BulkDeleteByGroupPKsWithTx ... +func (m *subjectGroupManager) BulkDeleteByGroupPKsWithTx(tx *sqlx.Tx, groupPKs []int64) error { if len(groupPKs) == 0 { return nil } diff --git a/pkg/database/dao/subject_template_group.go b/pkg/database/dao/subject_template_group.go index 66463edd..6ed3471a 100644 --- a/pkg/database/dao/subject_template_group.go +++ b/pkg/database/dao/subject_template_group.go @@ -47,7 +47,7 @@ type SubjectTemplateGroupManager interface { BulkUpdateExpiredAtWithTx(tx *sqlx.Tx, relations []SubjectTemplateGroup) error BulkUpdateExpiredAtByRelationWithTx(tx *sqlx.Tx, relations []SubjectRelation) error BulkDeleteWithTx(tx *sqlx.Tx, relations []SubjectTemplateGroup) error - BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error + BulkDeleteBySubjectPKsWithTx(tx *sqlx.Tx, subjectPKs []int64) error } type subjectTemplateGroupManager struct { @@ -237,7 +237,7 @@ func (m *subjectTemplateGroupManager) ListThinRelationWithMaxExpiredAtByGroupPK( return relations, err } -func (m *subjectTemplateGroupManager) BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error { +func (m *subjectTemplateGroupManager) BulkDeleteBySubjectPKsWithTx(tx *sqlx.Tx, subjectPKs []int64) error { sql := `DELETE FROM subject_template_group WHERE subject_pk in (?)` return database.SqlxDeleteWithTx(tx, sql, subjectPKs) diff --git a/pkg/service/group.go b/pkg/service/group.go index f5d648ce..dfa3716f 100644 --- a/pkg/service/group.go +++ b/pkg/service/group.go @@ -879,7 +879,7 @@ func (l *groupService) BulkDeleteByGroupPKsWithTx(tx *sqlx.Tx, groupPKs []int64) errorWrapf := errorx.NewLayerFunctionErrorWrapf(GroupSVC, "BulkDeleteByGroupPKsWithTx") // 批量用户组删除成员关系 subjectRelation - err := l.manager.BulkDeleteByGroupPKs(tx, groupPKs) + err := l.manager.BulkDeleteByGroupPKsWithTx(tx, groupPKs) if err != nil { return errorWrapf( err, "manager.BulkDeleteByGroupPKs group_pks=`%+v` fail", groupPKs) @@ -893,14 +893,14 @@ func (l *groupService) BulkDeleteBySubjectPKsWithTx(tx *sqlx.Tx, subjectPKs []in errorWrapf := errorx.NewLayerFunctionErrorWrapf(GroupSVC, "BulkDeleteBySubjectPKsWithTx") // 批量其加入的用户组关系 subjectRelation - err := l.manager.BulkDeleteBySubjectPKs(tx, subjectPKs) + err := l.manager.BulkDeleteBySubjectPKsWithTx(tx, subjectPKs) if err != nil { return errorWrapf( err, "manager.BulkDeleteBySubjectPKs subject_pks=`%+v` fail", subjectPKs) } // 批量删除subject template group - err = l.subjectTemplateGroupManager.BulkDeleteBySubjectPKs(tx, subjectPKs) + err = l.subjectTemplateGroupManager.BulkDeleteBySubjectPKsWithTx(tx, subjectPKs) if err != nil { return errorWrapf( err, diff --git a/pkg/service/group_test.go b/pkg/service/group_test.go index 59f2d8af..f05a28e7 100644 --- a/pkg/service/group_test.go +++ b/pkg/service/group_test.go @@ -81,7 +81,7 @@ var _ = Describe("GroupService", func() { It("manager.BulkDeleteBySubjectPKs fail", func() { mockSubjectService := mock.NewMockSubjectGroupManager(ctl) - mockSubjectService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + mockSubjectService.EXPECT().BulkDeleteBySubjectPKsWithTx(gomock.Any(), []int64{1, 2}).Return( errors.New("error"), ).AnyTimes() @@ -97,12 +97,12 @@ var _ = Describe("GroupService", func() { It("manager.BulkDeleteBySubjectPKs fail", func() { mockSubjectService := mock.NewMockSubjectGroupManager(ctl) - mockSubjectService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + mockSubjectService.EXPECT().BulkDeleteBySubjectPKsWithTx(gomock.Any(), []int64{1, 2}).Return( nil, ).AnyTimes() mockSubjectTemplateGroupService := mock.NewMockSubjectTemplateGroupManager(ctl) - mockSubjectTemplateGroupService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + mockSubjectTemplateGroupService.EXPECT().BulkDeleteBySubjectPKsWithTx(gomock.Any(), []int64{1, 2}).Return( errors.New("error"), ).AnyTimes() @@ -119,12 +119,12 @@ var _ = Describe("GroupService", func() { It("subjectSystemGroupManager.DeleteBySubjectPKsWithTx fail", func() { mockSubjectService := mock.NewMockSubjectGroupManager(ctl) - mockSubjectService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + mockSubjectService.EXPECT().BulkDeleteBySubjectPKsWithTx(gomock.Any(), []int64{1, 2}).Return( nil, ).AnyTimes() mockSubjectTemplateGroupService := mock.NewMockSubjectTemplateGroupManager(ctl) - mockSubjectTemplateGroupService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + mockSubjectTemplateGroupService.EXPECT().BulkDeleteBySubjectPKsWithTx(gomock.Any(), []int64{1, 2}).Return( nil, ).AnyTimes() @@ -147,12 +147,12 @@ var _ = Describe("GroupService", func() { It("ok", func() { mockSubjectService := mock.NewMockSubjectGroupManager(ctl) - mockSubjectService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + mockSubjectService.EXPECT().BulkDeleteBySubjectPKsWithTx(gomock.Any(), []int64{1, 2}).Return( nil, ).AnyTimes() mockSubjectTemplateGroupService := mock.NewMockSubjectTemplateGroupManager(ctl) - mockSubjectTemplateGroupService.EXPECT().BulkDeleteBySubjectPKs(gomock.Any(), []int64{1, 2}).Return( + mockSubjectTemplateGroupService.EXPECT().BulkDeleteBySubjectPKsWithTx(gomock.Any(), []int64{1, 2}).Return( nil, ).AnyTimes() From c1802d9177b51d651a9c895cb3ebbe1ede85a078 Mon Sep 17 00:00:00 2001 From: zhu327 Date: Thu, 28 Dec 2023 18:09:05 +0800 Subject: [PATCH 4/4] fix: update by cr --- pkg/database/dao/subject_template_group.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/database/dao/subject_template_group.go b/pkg/database/dao/subject_template_group.go index 6ed3471a..315f9f67 100644 --- a/pkg/database/dao/subject_template_group.go +++ b/pkg/database/dao/subject_template_group.go @@ -238,6 +238,10 @@ func (m *subjectTemplateGroupManager) ListThinRelationWithMaxExpiredAtByGroupPK( } func (m *subjectTemplateGroupManager) BulkDeleteBySubjectPKsWithTx(tx *sqlx.Tx, subjectPKs []int64) error { + if len(subjectPKs) == 0 { + return nil + } + sql := `DELETE FROM subject_template_group WHERE subject_pk in (?)` return database.SqlxDeleteWithTx(tx, sql, subjectPKs)