refactor(account): 移除卡类型字段、优化账号列表查询和权限检查
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m18s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m18s
- 移除 IoT 卡和号卡的 card_type 字段(数据库迁移) - 优化账号列表查询,支持按店铺和企业筛选 - 账号响应增加店铺名称和企业名称字段 - 实现批量加载店铺和企业名称,避免 N+1 查询 - 更新权限检查中间件,完善权限验证逻辑 - 更新相关测试用例,确保功能正确性
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
// 用于权限检查时查询店铺信息和下级店铺ID
|
||||
type ShopStoreInterface interface {
|
||||
GetByID(ctx context.Context, id uint) (*model.Shop, error)
|
||||
GetByIDs(ctx context.Context, ids []uint) ([]*model.Shop, error)
|
||||
GetSubordinateShopIDs(ctx context.Context, shopID uint) ([]uint, error)
|
||||
}
|
||||
|
||||
@@ -19,6 +20,7 @@ type ShopStoreInterface interface {
|
||||
// 用于权限检查时查询企业信息
|
||||
type EnterpriseStoreInterface interface {
|
||||
GetByID(ctx context.Context, id uint) (*model.Enterprise, error)
|
||||
GetByIDs(ctx context.Context, ids []uint) ([]*model.Enterprise, error)
|
||||
}
|
||||
|
||||
// CanManageShop 检查当前用户是否有权管理目标店铺的账号
|
||||
|
||||
@@ -23,6 +23,14 @@ func (m *MockShopStore) GetByID(ctx context.Context, id uint) (*model.Shop, erro
|
||||
return args.Get(0).(*model.Shop), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *MockShopStore) GetByIDs(ctx context.Context, ids []uint) ([]*model.Shop, error) {
|
||||
args := m.Called(ctx, ids)
|
||||
if args.Get(0) == nil {
|
||||
return nil, args.Error(1)
|
||||
}
|
||||
return args.Get(0).([]*model.Shop), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *MockShopStore) GetSubordinateShopIDs(ctx context.Context, shopID uint) ([]uint, error) {
|
||||
args := m.Called(ctx, shopID)
|
||||
if args.Get(0) == nil {
|
||||
@@ -43,6 +51,14 @@ func (m *MockEnterpriseStore) GetByID(ctx context.Context, id uint) (*model.Ente
|
||||
return args.Get(0).(*model.Enterprise), args.Error(1)
|
||||
}
|
||||
|
||||
func (m *MockEnterpriseStore) GetByIDs(ctx context.Context, ids []uint) ([]*model.Enterprise, error) {
|
||||
args := m.Called(ctx, ids)
|
||||
if args.Get(0) == nil {
|
||||
return nil, args.Error(1)
|
||||
}
|
||||
return args.Get(0).([]*model.Enterprise), args.Error(1)
|
||||
}
|
||||
|
||||
func TestCanManageShop_SuperAdmin(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, constants.ContextKeyUserType, constants.UserTypeSuperAdmin)
|
||||
|
||||
Reference in New Issue
Block a user