实现ListPlans和单测

This commit is contained in:
2025-09-14 16:52:59 +08:00
parent a5a4f6cbe2
commit 164c7a4923
2 changed files with 127 additions and 8 deletions

View File

@@ -186,9 +186,26 @@ func (c *Controller) GetPlan(ctx *gin.Context) {
// @Failure 200 {object} controller.Response "业务失败具体错误码和信息见响应体例如400, 500"
// @Router /plans [get]
func (c *Controller) ListPlans(ctx *gin.Context) {
// 占位符:此处应调用服务层或仓库层获取计划列表
c.logger.Infof("收到获取计划列表请求 (占位符)")
controller.SendResponse(ctx, controller.CodeSuccess, "获取计划列表接口占位符", ListPlansResponse{Plans: []PlanResponse{}, Total: 0})
// 1. 调用仓库层获取所有计划
plans, err := c.planRepo.ListBasicPlans()
if err != nil {
c.logger.Errorf("获取计划列表失败: %v", err)
controller.SendErrorResponse(ctx, controller.CodeInternalError, "获取计划列表时发生内部错误")
return
}
// 2. 将模型转换为响应 DTO
planResponses := make([]PlanResponse, 0, len(plans))
for _, p := range plans {
planResponses = append(planResponses, *PlanToResponse(&p))
}
// 3. 构造并发送成功响应
resp := ListPlansResponse{
Plans: planResponses,
Total: len(planResponses),
}
controller.SendResponse(ctx, controller.CodeSuccess, "获取计划列表成功", resp)
}
// UpdatePlan godoc