Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed-Ghanam committed Oct 7, 2024
1 parent 3aa73a6 commit 3723e74
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Altinn.Profile/UseCases/UserContactDetailsRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ public UserContactDetailsRetriever(IPersonService registerService)
/// A task representing the asynchronous operation. The task result contains a <see cref="Result{TValue, TError}"/>
/// where the value is <see cref="UserContactDetailsLookupResult"/> and the error is <see cref="bool"/>.
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="lookupCriteria"/> is null.</exception>
public async Task<Result<UserContactDetailsLookupResult, bool>> RetrieveAsync(UserContactPointLookup lookupCriteria)
{
ArgumentNullException.ThrowIfNull(lookupCriteria);

if (lookupCriteria?.NationalIdentityNumbers == null || lookupCriteria.NationalIdentityNumbers.Count == 0)
{
return false;
Expand All @@ -45,7 +48,7 @@ public async Task<Result<UserContactDetailsLookupResult, bool>> RetrieveAsync(Us
var userContactDetails = await _registerService.GetUserContactAsync(lookupCriteria.NationalIdentityNumbers);

return userContactDetails.Match(
MapToUserContactDetailsResult,
MapToUserContactDetailsLookupResult,
_ => false);
}

Expand Down Expand Up @@ -74,9 +77,12 @@ private UserContactDetails MapToUserContactDetails(IUserContactInfo userContactD
/// </summary>
/// <param name="userContactResult">The user contact details lookup result.</param>
/// <returns>A <see cref="Result{TValue, TError}"/> containing the mapped user contact details.</returns>
private Result<UserContactDetailsLookupResult, bool> MapToUserContactDetailsResult(IUserContactInfoLookupResult userContactResult)
/// <exception cref="ArgumentNullException">Thrown when <paramref name="userContactResult"/> is null.</exception>
private Result<UserContactDetailsLookupResult, bool> MapToUserContactDetailsLookupResult(IUserContactInfoLookupResult userContactResult)
{
var unmatchedNationalIdentityNumbers = userContactResult?.UnmatchedNationalIdentityNumbers ?? null;
ArgumentNullException.ThrowIfNull(userContactResult);

var unmatchedNationalIdentityNumbers = userContactResult?.UnmatchedNationalIdentityNumbers;
var matchedUserContactDetails = userContactResult?.MatchedUserContact?.Select(MapToUserContactDetails).ToImmutableList();

return new UserContactDetailsLookupResult(matchedUserContactDetails, unmatchedNationalIdentityNumbers);
Expand Down

0 comments on commit 3723e74

Please sign in to comment.