Implement US-13 patient authentication and persistent ownership

This commit is contained in:
Steffen committed 2026-10-05 11:10:22 +02:00
1 parent ebf50827d6
commit 0ce9b2b168
36 files changed
+1203 -28

No files matched your search

@@ -5,17 +5,21 @@ namespace PatientProfileService.Application;
public sealed class PatientApplicationService(PatientRepository repository)
{
public Task<Patient> CreatePatientAsync(CreatePatientRequest request, CancellationToken cancellationToken)
public async Task<Patient> CreatePatientAsync(CreatePatientRequest request, string accountId, CancellationToken cancellationToken)
{
ArgumentException.ThrowIfNullOrWhiteSpace(request.Name);
ArgumentException.ThrowIfNullOrWhiteSpace(accountId);
if (await repository.FindByAccountIdAsync(accountId, cancellationToken) is not null)
throw new ProfileAlreadyExistsException();
if (request.DateOfBirth is null)
throw new ArgumentException("A date of birth is required.", nameof(request));
// The documented TIMESTAMP columns store UTC without a time-zone component.
var now = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Unspecified);
return repository.SaveAsync(new Patient
return await repository.SaveAsync(new Patient
{
PatientId = Guid.NewGuid(),
AccountId = accountId,
Name = request.Name,
DateOfBirth = request.DateOfBirth.Value,
ContactInfo = request.ContactInfo,
@@ -24,6 +28,9 @@ public sealed class PatientApplicationService(PatientRepository repository)
}, cancellationToken);
}
public Task<Patient?> GetByAccountAsync(string accountId, CancellationToken cancellationToken) =>
repository.FindByAccountIdAsync(accountId, cancellationToken);
public Task<Patient?> GetPatientAsync(Guid patientId, CancellationToken cancellationToken) =>
repository.FindByIdAsync(patientId, cancellationToken);