- AI 提示词拆分为 markdown 模块(Prompts/global + modules + rag + router) - 新增 AI 同意门控(用户需同意后才能使用 AI 功能) - 新增 AI 录入草稿存储(AiEntryDraftContracts/EfAiEntryDraftStore/AiEntryDraftRecord) - 新增 AI 意图路由(ai_intent_router) - 新增医疗引用知识库(MedicalCitationKnowledge) - 重构 prompt_manager 和 ai_chat_endpoints - 优化聊天/趋势/档案/抽屉/医生端等多个页面 UI - 新增 agent 插画和趋势指标图标资源 - 删除 HANDOFF-2026-07-17.md
79 lines
3.6 KiB
C#
79 lines
3.6 KiB
C#
using Health.Application.HealthArchives;
|
|
using Health.Application.Users;
|
|
|
|
namespace Health.WebApi.Endpoints;
|
|
|
|
public static class UserEndpoints
|
|
{
|
|
public static void MapUserEndpoints(this WebApplication app)
|
|
{
|
|
var group = app.MapGroup("/api/user").RequireAuthorization();
|
|
|
|
group.MapGet("/profile", async (HttpContext http, IUserService users, CancellationToken ct) =>
|
|
{
|
|
var profile = await users.GetProfileAsync(GetUserId(http), ct);
|
|
return Results.Ok(new { code = 0, data = profile, message = (string?)null });
|
|
});
|
|
|
|
group.MapPut("/profile", async (UpdateProfileRequest req, HttpContext http, IUserService users, CancellationToken ct) =>
|
|
{
|
|
var birthDate = DateOnly.TryParse(req.BirthDate, out var parsed) ? parsed : (DateOnly?)null;
|
|
var updated = await users.UpdateProfileAsync(
|
|
GetUserId(http),
|
|
new UserProfileUpdateRequest(req.Name, req.Gender, birthDate, req.AvatarUrl),
|
|
ct);
|
|
if (!updated) return Results.Ok(new { code = 40004, message = "用户不存在" });
|
|
|
|
var profile = await users.GetProfileAsync(GetUserId(http), ct);
|
|
return Results.Ok(new { code = 0, data = profile, message = (string?)null });
|
|
});
|
|
|
|
group.MapGet("/health-archive", async (HttpContext http, IHealthArchiveService archives, CancellationToken ct) =>
|
|
{
|
|
var archive = await archives.GetAsync(GetUserId(http), ct);
|
|
return Results.Ok(new { code = 0, data = archive, message = (string?)null });
|
|
});
|
|
|
|
group.MapPut("/health-archive", async (UpdateArchiveRequest req, HttpContext http, IHealthArchiveService archives, CancellationToken ct) =>
|
|
{
|
|
var surgeryDate = DateOnly.TryParse(req.SurgeryDate, out var parsed) ? parsed : (DateOnly?)null;
|
|
var surgeries = req.Surgeries?.Select(s => new HealthArchiveSurgeryInput(
|
|
s.Type,
|
|
DateOnly.TryParse(s.Date, out var date) ? date : null)).ToList();
|
|
await archives.UpdateAsync(
|
|
GetUserId(http),
|
|
new HealthArchiveUpdateRequest(
|
|
req.Diagnosis,
|
|
req.SurgeryType,
|
|
surgeryDate,
|
|
req.Allergies,
|
|
req.DietRestrictions,
|
|
req.ChronicDiseases,
|
|
req.FamilyHistory,
|
|
surgeries,
|
|
req.SurgeryHistoryStatus),
|
|
ct);
|
|
return Results.Ok(new { code = 0, data = new { success = true }, message = (string?)null });
|
|
});
|
|
|
|
group.MapDelete("/account", async (HttpContext http, IUserService users, CancellationToken ct) =>
|
|
{
|
|
await users.DeleteAccountAsync(GetUserId(http), ct);
|
|
return Results.Ok(new { code = 0, data = new { success = true }, message = (string?)null });
|
|
});
|
|
}
|
|
|
|
private static Guid GetUserId(HttpContext http) =>
|
|
Guid.TryParse(http.User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value, out var id) ? id : Guid.Empty;
|
|
}
|
|
|
|
public sealed record UpdateProfileRequest(string? Name, string? Gender, string? BirthDate, string? AvatarUrl);
|
|
public sealed record UpdateArchiveRequest(
|
|
string? Diagnosis, string? SurgeryType, string? SurgeryDate,
|
|
List<string>? Allergies, List<string>? DietRestrictions,
|
|
List<string>? ChronicDiseases, string? FamilyHistory,
|
|
List<UpdateArchiveSurgeryRequest>? Surgeries,
|
|
string? SurgeryHistoryStatus);
|
|
|
|
public sealed record UpdateArchiveSurgeryRequest(string Type, string? Date);
|