refactor: 将 DTO 文件从 internal/model 移动到 internal/model/dto 目录
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m22s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m22s
- 移动 17 个 DTO 文件到 internal/model/dto/ 目录 - 更新所有 DTO 文件的 package 声明从 model 改为 dto - 更新所有引用文件的 import 和类型引用 - Handler 层:admin 和 h5 所有处理器 - Service 层:所有业务服务 - Routes 层:所有路由定义 - Tests 层:单元测试和集成测试 - 清理未使用的 import 语句 - 验证:项目构建成功,测试编译通过,LSP 无错误
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
accountService "github.com/break/junhong_cmp_fiber/internal/service/account"
|
||||
postgresStore "github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
@@ -183,7 +184,7 @@ func TestAccountAPI_Create(t *testing.T) {
|
||||
createTestAccount(t, env.db, rootAccount)
|
||||
|
||||
t.Run("成功创建平台账号", func(t *testing.T) {
|
||||
reqBody := model.CreateAccountRequest{
|
||||
reqBody := dto.CreateAccountRequest{
|
||||
Username: "platform_user",
|
||||
Phone: "13800000001",
|
||||
Password: "Password123",
|
||||
@@ -221,7 +222,7 @@ func TestAccountAPI_Create(t *testing.T) {
|
||||
createTestAccount(t, env.db, existingAccount)
|
||||
|
||||
// 尝试创建同名账号
|
||||
reqBody := model.CreateAccountRequest{
|
||||
reqBody := dto.CreateAccountRequest{
|
||||
Username: "existing_user",
|
||||
Phone: "13800000003",
|
||||
Password: "Password123",
|
||||
@@ -242,7 +243,7 @@ func TestAccountAPI_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("非root用户缺少parent_id时返回错误", func(t *testing.T) {
|
||||
reqBody := model.CreateAccountRequest{
|
||||
reqBody := dto.CreateAccountRequest{
|
||||
Username: "no_parent_user",
|
||||
Phone: "13800000004",
|
||||
Password: "Password123",
|
||||
@@ -347,7 +348,7 @@ func TestAccountAPI_Update(t *testing.T) {
|
||||
|
||||
t.Run("成功更新账号", func(t *testing.T) {
|
||||
newUsername := "updated_user"
|
||||
reqBody := model.UpdateAccountRequest{
|
||||
reqBody := dto.UpdateAccountRequest{
|
||||
Username: &newUsername,
|
||||
}
|
||||
|
||||
@@ -480,7 +481,7 @@ func TestAccountAPI_AssignRoles(t *testing.T) {
|
||||
env.db.Create(testRole)
|
||||
|
||||
t.Run("成功分配角色", func(t *testing.T) {
|
||||
reqBody := model.AssignRolesRequest{
|
||||
reqBody := dto.AssignRolesRequest{
|
||||
RoleIDs: []uint{testRole.ID},
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
permissionService "github.com/break/junhong_cmp_fiber/internal/service/permission"
|
||||
postgresStore "github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
@@ -148,7 +149,7 @@ func TestPermissionAPI_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("成功创建权限", func(t *testing.T) {
|
||||
reqBody := model.CreatePermissionRequest{
|
||||
reqBody := dto.CreatePermissionRequest{
|
||||
PermName: "用户管理",
|
||||
PermCode: "user:manage",
|
||||
PermType: constants.PermissionTypeMenu,
|
||||
@@ -185,7 +186,7 @@ func TestPermissionAPI_Create(t *testing.T) {
|
||||
env.db.Create(existingPerm)
|
||||
|
||||
// 尝试创建相同编码的权限
|
||||
reqBody := model.CreatePermissionRequest{
|
||||
reqBody := dto.CreatePermissionRequest{
|
||||
PermName: "新权限",
|
||||
PermCode: "existing:perm",
|
||||
PermType: constants.PermissionTypeMenu,
|
||||
@@ -215,7 +216,7 @@ func TestPermissionAPI_Create(t *testing.T) {
|
||||
env.db.Create(parentPerm)
|
||||
|
||||
// 创建子权限
|
||||
reqBody := model.CreatePermissionRequest{
|
||||
reqBody := dto.CreatePermissionRequest{
|
||||
PermName: "用户列表",
|
||||
PermCode: "system:user:list",
|
||||
PermType: constants.PermissionTypeButton,
|
||||
@@ -308,7 +309,7 @@ func TestPermissionAPI_Update(t *testing.T) {
|
||||
|
||||
t.Run("成功更新权限", func(t *testing.T) {
|
||||
newName := "更新后权限"
|
||||
reqBody := model.UpdatePermissionRequest{
|
||||
reqBody := dto.UpdatePermissionRequest{
|
||||
PermName: &newName,
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
accountService "github.com/break/junhong_cmp_fiber/internal/service/account"
|
||||
postgresStore "github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
@@ -147,7 +148,7 @@ func TestPlatformAccountAPI_UpdatePassword(t *testing.T) {
|
||||
db.Create(testAccount)
|
||||
|
||||
t.Run("成功修改密码", func(t *testing.T) {
|
||||
reqBody := model.UpdatePasswordRequest{
|
||||
reqBody := dto.UpdatePasswordRequest{
|
||||
NewPassword: "NewPassword@123",
|
||||
}
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
@@ -169,7 +170,7 @@ func TestPlatformAccountAPI_UpdatePassword(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("账号不存在返回错误", func(t *testing.T) {
|
||||
reqBody := model.UpdatePasswordRequest{
|
||||
reqBody := dto.UpdatePasswordRequest{
|
||||
NewPassword: "NewPassword@123",
|
||||
}
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
@@ -221,7 +222,7 @@ func TestPlatformAccountAPI_UpdateStatus(t *testing.T) {
|
||||
db.Create(testAccount)
|
||||
|
||||
t.Run("成功禁用账号", func(t *testing.T) {
|
||||
reqBody := model.UpdateStatusRequest{
|
||||
reqBody := dto.UpdateStatusRequest{
|
||||
Status: constants.StatusDisabled,
|
||||
}
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
@@ -238,7 +239,7 @@ func TestPlatformAccountAPI_UpdateStatus(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("成功启用账号", func(t *testing.T) {
|
||||
reqBody := model.UpdateStatusRequest{
|
||||
reqBody := dto.UpdateStatusRequest{
|
||||
Status: constants.StatusEnabled,
|
||||
}
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
@@ -306,7 +307,7 @@ func TestPlatformAccountAPI_AssignRoles(t *testing.T) {
|
||||
db.Create(testRole)
|
||||
|
||||
t.Run("超级管理员禁止分配角色", func(t *testing.T) {
|
||||
reqBody := model.AssignRolesRequest{
|
||||
reqBody := dto.AssignRolesRequest{
|
||||
RoleIDs: []uint{testRole.ID},
|
||||
}
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
@@ -324,7 +325,7 @@ func TestPlatformAccountAPI_AssignRoles(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("平台用户成功分配角色", func(t *testing.T) {
|
||||
reqBody := model.AssignRolesRequest{
|
||||
reqBody := dto.AssignRolesRequest{
|
||||
RoleIDs: []uint{testRole.ID},
|
||||
}
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
@@ -341,7 +342,7 @@ func TestPlatformAccountAPI_AssignRoles(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("空数组清空所有角色", func(t *testing.T) {
|
||||
reqBody := model.AssignRolesRequest{
|
||||
reqBody := dto.AssignRolesRequest{
|
||||
RoleIDs: []uint{},
|
||||
}
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
roleService "github.com/break/junhong_cmp_fiber/internal/service/role"
|
||||
postgresStore "github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
@@ -165,7 +166,7 @@ func TestRoleAPI_Create(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("成功创建角色", func(t *testing.T) {
|
||||
reqBody := model.CreateRoleRequest{
|
||||
reqBody := dto.CreateRoleRequest{
|
||||
RoleName: "测试角色",
|
||||
RoleDesc: "这是一个测试角色",
|
||||
RoleType: constants.RoleTypePlatform,
|
||||
@@ -277,7 +278,7 @@ func TestRoleAPI_Update(t *testing.T) {
|
||||
|
||||
t.Run("成功更新角色", func(t *testing.T) {
|
||||
newName := "更新后角色"
|
||||
reqBody := model.UpdateRoleRequest{
|
||||
reqBody := dto.UpdateRoleRequest{
|
||||
RoleName: &newName,
|
||||
}
|
||||
|
||||
@@ -398,7 +399,7 @@ func TestRoleAPI_AssignPermissions(t *testing.T) {
|
||||
env.db.Create(testPerm)
|
||||
|
||||
t.Run("成功分配权限", func(t *testing.T) {
|
||||
reqBody := model.AssignPermissionsRequest{
|
||||
reqBody := dto.AssignPermissionsRequest{
|
||||
PermIDs: []uint{testPerm.ID},
|
||||
}
|
||||
|
||||
@@ -540,7 +541,7 @@ func TestRoleAPI_UpdateStatus(t *testing.T) {
|
||||
env.db.Create(testRole)
|
||||
|
||||
t.Run("成功禁用角色", func(t *testing.T) {
|
||||
reqBody := model.UpdateRoleStatusRequest{
|
||||
reqBody := dto.UpdateRoleStatusRequest{
|
||||
Status: constants.StatusDisabled,
|
||||
}
|
||||
|
||||
@@ -564,7 +565,7 @@ func TestRoleAPI_UpdateStatus(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("成功启用角色", func(t *testing.T) {
|
||||
reqBody := model.UpdateRoleStatusRequest{
|
||||
reqBody := dto.UpdateRoleStatusRequest{
|
||||
Status: constants.StatusEnabled,
|
||||
}
|
||||
|
||||
@@ -588,7 +589,7 @@ func TestRoleAPI_UpdateStatus(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("角色不存在返回错误", func(t *testing.T) {
|
||||
reqBody := model.UpdateRoleStatusRequest{
|
||||
reqBody := dto.UpdateRoleStatusRequest{
|
||||
Status: constants.StatusEnabled,
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/auth"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/config"
|
||||
@@ -147,7 +148,7 @@ func TestShopAccount_CreateAccount(t *testing.T) {
|
||||
env := setupShopAccountTestEnv(t)
|
||||
defer env.teardown()
|
||||
|
||||
reqBody := model.CreateShopAccountRequest{
|
||||
reqBody := dto.CreateShopAccountRequest{
|
||||
ShopID: env.testShop.ID,
|
||||
Username: "agent001",
|
||||
Phone: "13800138001",
|
||||
@@ -193,7 +194,7 @@ func TestShopAccount_CreateAccount_InvalidShop(t *testing.T) {
|
||||
env := setupShopAccountTestEnv(t)
|
||||
defer env.teardown()
|
||||
|
||||
reqBody := model.CreateShopAccountRequest{
|
||||
reqBody := dto.CreateShopAccountRequest{
|
||||
ShopID: 99999, // 不存在的商户ID
|
||||
Username: "agent002",
|
||||
Phone: "13800138002",
|
||||
@@ -262,7 +263,7 @@ func TestShopAccount_UpdateAccount(t *testing.T) {
|
||||
account := testutil.CreateAgentUser(t, env.db, env.testShop.ID)
|
||||
|
||||
// 更新账号用户名
|
||||
reqBody := model.UpdateShopAccountRequest{
|
||||
reqBody := dto.UpdateShopAccountRequest{
|
||||
Username: "updated_agent",
|
||||
}
|
||||
|
||||
@@ -303,7 +304,7 @@ func TestShopAccount_UpdatePassword(t *testing.T) {
|
||||
|
||||
// 重置密码
|
||||
newPassword := "newpassword456"
|
||||
reqBody := model.UpdateShopAccountPasswordRequest{
|
||||
reqBody := dto.UpdateShopAccountPasswordRequest{
|
||||
NewPassword: newPassword,
|
||||
}
|
||||
|
||||
@@ -349,7 +350,7 @@ func TestShopAccount_UpdateStatus(t *testing.T) {
|
||||
require.Equal(t, 1, account.Status)
|
||||
|
||||
// 禁用账号
|
||||
reqBody := model.UpdateShopAccountStatusRequest{
|
||||
reqBody := dto.UpdateShopAccountStatusRequest{
|
||||
Status: 2, // 禁用
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/auth"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/config"
|
||||
@@ -141,7 +142,7 @@ func TestShopManagement_CreateShop(t *testing.T) {
|
||||
env := setupShopManagementTestEnv(t)
|
||||
defer env.teardown()
|
||||
|
||||
reqBody := model.CreateShopRequest{
|
||||
reqBody := dto.CreateShopRequest{
|
||||
ShopName: "测试商户",
|
||||
ShopCode: "TEST001",
|
||||
InitUsername: "testuser",
|
||||
@@ -191,7 +192,7 @@ func TestShopManagement_CreateShop_DuplicateCode(t *testing.T) {
|
||||
defer env.teardown()
|
||||
|
||||
// 通过 API 创建第一个商户
|
||||
firstReq := model.CreateShopRequest{
|
||||
firstReq := dto.CreateShopRequest{
|
||||
ShopName: "商户1",
|
||||
ShopCode: "DUP001",
|
||||
InitUsername: "dupuser1",
|
||||
@@ -210,7 +211,7 @@ func TestShopManagement_CreateShop_DuplicateCode(t *testing.T) {
|
||||
require.Equal(t, 0, firstResult.Code, "第一个商户应该创建成功")
|
||||
|
||||
// 尝试创建编码重复的商户
|
||||
reqBody := model.CreateShopRequest{
|
||||
reqBody := dto.CreateShopRequest{
|
||||
ShopName: "商户2",
|
||||
ShopCode: "DUP001", // 使用相同编码
|
||||
InitUsername: "dupuser2",
|
||||
@@ -281,7 +282,7 @@ func TestShopManagement_UpdateShop(t *testing.T) {
|
||||
shop := testutil.CreateTestShop(t, env.db, "原始商户", "ORIG001", 1, nil)
|
||||
|
||||
// 更新商户
|
||||
reqBody := model.UpdateShopRequest{
|
||||
reqBody := dto.UpdateShopRequest{
|
||||
ShopName: "更新后的商户",
|
||||
Status: 1,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user