fix: 修复后端 JSON 反序列化与循环引用问题

- Program.cs 添加 JsonStringEnumConverter + CamelCase 策略,
  修复枚举值和 decimal 反序列化失败
- CreateHealthRecordRequest 改为 class + init 属性,
  修复 decimal? 在位置记录中的 JSON 反序列化异常
- 运动计划 /current 端点改用匿名对象投影,
  修复 EF Core 导航属性循环引用导致 JSON 无限递归
This commit is contained in:
MingNian
2026-06-02 13:01:21 +08:00
parent 6e69f1085e
commit 9ffd2631c3
3 changed files with 33 additions and 4 deletions

View File

@@ -193,7 +193,21 @@ public static class RemainingEndpoints
var today = DateOnly.FromDateTime(DateTime.Now);
var monday = today.AddDays(-(int)today.DayOfWeek + 1);
var plan = await db.ExercisePlans.Include(p => p.Items).FirstOrDefaultAsync(p => p.UserId == userId && p.WeekStartDate == monday);
return Results.Ok(new { code = 0, data = plan, message = (string?)null });
if (plan == null) return Results.Ok(new { code = 0, data = (object?)null, message = (string?)null });
return Results.Ok(new
{
code = 0,
data = new
{
plan.Id, plan.WeekStartDate, plan.CreatedAt, plan.UpdatedAt,
items = plan.Items.Select(i => new
{
i.Id, i.DayOfWeek, i.ExerciseType, i.DurationMinutes,
i.IsCompleted, i.CompletedAt, i.IsRestDay
})
},
message = (string?)null
});
});
group.MapPost("/", async (CreateExercisePlanRequest req, HttpContext http, AppDbContext db, CancellationToken ct) =>