fix: 修复分页字段/角色DTO/套餐详情/批量分配Bug,新增C端测试登录接口和Hurl价格验证测试
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
- 修复B-2:27个分页DTO字段名统一(list→items, page_size→size,删除total_pages) - 修复B-1:角色接口统一返回DTO(id小写,消除GORM大写字段名) - 修复C-1:套餐详情接口(GET /packages/:id)补充代理佣金字段 - 修复C-2:批量分配已存在记录由500改为静默跳过 - 修复C-3:创建系列授权响应在事务提交后构建,packages数组不再为空 - 新增C端开发测试登录接口(POST /api/c/v1/auth/dev-login,仅logging.development=true时生效) - 新增Hurl测试:card-price-verification-flow.hurl(导入卡→分配→C端价格验证) - 新增测试Excel数据文件和dev.env测试变量
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
@@ -34,7 +35,7 @@ func New(roleStore *postgres.RoleStore, permissionStore *postgres.PermissionStor
|
||||
}
|
||||
|
||||
// Create 创建角色
|
||||
func (s *Service) Create(ctx context.Context, req *dto.CreateRoleRequest) (*model.Role, error) {
|
||||
func (s *Service) Create(ctx context.Context, req *dto.CreateRoleRequest) (*dto.RoleResponse, error) {
|
||||
// 获取当前用户 ID
|
||||
currentUserID := middleware.GetUserIDFromContext(ctx)
|
||||
if currentUserID == 0 {
|
||||
@@ -62,11 +63,11 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateRoleRequest) (*mode
|
||||
return nil, errors.Wrap(errors.CodeInternalError, err, "创建角色失败")
|
||||
}
|
||||
|
||||
return role, nil
|
||||
return toResponse(role), nil
|
||||
}
|
||||
|
||||
// Get 获取角色
|
||||
func (s *Service) Get(ctx context.Context, id uint) (*model.Role, error) {
|
||||
func (s *Service) Get(ctx context.Context, id uint) (*dto.RoleResponse, error) {
|
||||
role, err := s.roleStore.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
@@ -74,11 +75,11 @@ func (s *Service) Get(ctx context.Context, id uint) (*model.Role, error) {
|
||||
}
|
||||
return nil, errors.Wrap(errors.CodeInternalError, err, "获取角色失败")
|
||||
}
|
||||
return role, nil
|
||||
return toResponse(role), nil
|
||||
}
|
||||
|
||||
// Update 更新角色
|
||||
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateRoleRequest) (*model.Role, error) {
|
||||
func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateRoleRequest) (*dto.RoleResponse, error) {
|
||||
// 获取当前用户 ID
|
||||
currentUserID := middleware.GetUserIDFromContext(ctx)
|
||||
if currentUserID == 0 {
|
||||
@@ -120,7 +121,7 @@ func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdateRoleReques
|
||||
return nil, errors.Wrap(errors.CodeInternalError, err, "更新角色失败")
|
||||
}
|
||||
|
||||
return role, nil
|
||||
return toResponse(role), nil
|
||||
}
|
||||
|
||||
// Delete 软删除角色
|
||||
@@ -293,6 +294,21 @@ func (s *Service) UpdateStatus(ctx context.Context, id uint, status int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// toResponse 将 model.Role 转换为 dto.RoleResponse
|
||||
func toResponse(role *model.Role) *dto.RoleResponse {
|
||||
return &dto.RoleResponse{
|
||||
ID: role.ID,
|
||||
RoleName: role.RoleName,
|
||||
RoleDesc: role.RoleDesc,
|
||||
RoleType: role.RoleType,
|
||||
Status: role.Status,
|
||||
Creator: role.Creator,
|
||||
Updater: role.Updater,
|
||||
CreatedAt: role.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: role.UpdatedAt.Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
|
||||
func contains(availableForRoleTypes, roleTypeStr string) bool {
|
||||
types := strings.Split(availableForRoleTypes, ",")
|
||||
for _, t := range types {
|
||||
|
||||
Reference in New Issue
Block a user