fix: doctor can see patient-created follow-ups, camelCase JSON support
- FollowUpService: doctor query includes unassigned (DoctorId=null) follow-ups - FollowUpController: doctor creates follow-up with correct patientId and sets DoctorId - FollowUpCreateRequest/UpdateRequest: changed from positional record to class for System.Text.Json compat - Program.cs: added PropertyNameCaseInsensitive for camelCase JSON deserialization
This commit is contained in:
@@ -16,7 +16,7 @@ public class FollowUpService(AppDbContext db)
|
|||||||
public async Task<List<FollowUp>> GetDoctorFollowUpsAsync(Guid doctorId)
|
public async Task<List<FollowUp>> GetDoctorFollowUpsAsync(Guid doctorId)
|
||||||
=> await db.FollowUps
|
=> await db.FollowUps
|
||||||
.Include(f => f.Patient)
|
.Include(f => f.Patient)
|
||||||
.Where(f => f.DoctorId == doctorId)
|
.Where(f => f.DoctorId == doctorId || f.DoctorId == null)
|
||||||
.OrderBy(f => f.ScheduledAt)
|
.OrderBy(f => f.ScheduledAt)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,17 @@ public class FollowUpController(FollowUpService followUpService) : ControllerBas
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> AddFollowUp([FromBody] FollowUpCreateRequest request)
|
public async Task<IActionResult> AddFollowUp([FromBody] FollowUpCreateRequest request)
|
||||||
{
|
{
|
||||||
var followUp = await followUpService.AddAsync(UserId, request.Title, request.Description,
|
var patientId = UserId;
|
||||||
request.ScheduledAt, request.ReminderEnabled);
|
Guid? doctorId = null;
|
||||||
|
|
||||||
|
if (Role == "doctor" && request.PatientId.HasValue)
|
||||||
|
{
|
||||||
|
patientId = request.PatientId.Value;
|
||||||
|
doctorId = UserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
var followUp = await followUpService.AddAsync(patientId, request.Title, request.Description,
|
||||||
|
request.ScheduledAt, request.ReminderEnabled, doctorId);
|
||||||
return Ok(new { followUp.Id, followUp.Title, followUp.Status });
|
return Ok(new { followUp.Id, followUp.Title, followUp.Status });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +70,20 @@ public class FollowUpController(FollowUpService followUpService) : ControllerBas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record FollowUpCreateRequest(string Title, string? Description, DateTime ScheduledAt, bool ReminderEnabled = true);
|
public class FollowUpCreateRequest
|
||||||
|
{
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string? Description { get; set; }
|
||||||
|
public DateTime ScheduledAt { get; set; }
|
||||||
|
public bool ReminderEnabled { get; set; } = true;
|
||||||
|
public Guid? PatientId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public record FollowUpUpdateRequest(
|
public class FollowUpUpdateRequest
|
||||||
string? Title, string? Description, DateTime? ScheduledAt, string? Status, string? Notes);
|
{
|
||||||
|
public string? Title { get; set; }
|
||||||
|
public string? Description { get; set; }
|
||||||
|
public DateTime? ScheduledAt { get; set; }
|
||||||
|
public string? Status { get; set; }
|
||||||
|
public string? Notes { get; set; }
|
||||||
|
}
|
||||||
|
|||||||
@@ -74,7 +74,11 @@ builder.Services.AddCors(options =>
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers()
|
||||||
|
.AddJsonOptions(options =>
|
||||||
|
{
|
||||||
|
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user