Implement US-13 patient authentication and persistent ownership
This commit is contained in:
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);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace PatientProfileService.Application;
|
||||
|
||||
public interface PatientRepository
|
||||
{
|
||||
Task<Patient?> FindByAccountIdAsync(string accountId, CancellationToken cancellationToken);
|
||||
Task<Patient> SaveAsync(Patient patient, CancellationToken cancellationToken);
|
||||
Task<Patient?> FindByIdAsync(Guid patientId, CancellationToken cancellationToken);
|
||||
Task<bool> UpdateProfileAsync(Guid patientId, string name, string? contactInfo, CancellationToken cancellationToken);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace PatientProfileService.Application;
|
||||
|
||||
public sealed class ProfileAlreadyExistsException : Exception
|
||||
{
|
||||
}
|
||||
Reference in new issue
Block a user