From 2a7bcf973944131b68eadaa91fb4f92b648e880a Mon Sep 17 00:00:00 2001 From: Ahmed-Ghanam Date: Tue, 8 Oct 2024 11:58:27 +0200 Subject: [PATCH] Rename a number of classes --- ...pResult.cs => IContactInfoLookupResult.cs} | 2 +- .../Entities/UserContactInfoLookupResult.cs | 2 +- .../Services/IPersonService.cs | 2 +- .../Services/PersonService.cs | 2 +- ...troller.cs => ContactDetailsController.cs} | 25 ++--- .../ContactDetailsInternalController.cs | 56 ++++++++++++ .../UserContactDetailsInternalController.cs | 51 ----------- ...serContactDetails.cs => ContactDetails.cs} | 14 +-- .../Models/ContactDetailsLookupResult.cs | 39 ++++++++ .../Models/UserContactDetailsLookupResult.cs | 39 -------- src/Altinn.Profile/Program.cs | 2 +- .../UseCases/ContactDetailsRetriever.cs | 91 +++++++++++++++++++ .../UseCases/IContactDetailsRetriever.cs | 22 +++++ .../UseCases/IUserContactDetailsRetriever.cs | 19 ---- .../UseCases/UserContactDetailsRetriever.cs | 90 ------------------ .../UserContactDetailsRetrieverTests.cs | 4 +- 16 files changed, 236 insertions(+), 224 deletions(-) rename src/Altinn.Profile.Integrations/Entities/{IUserContactInfoLookupResult.cs => IContactInfoLookupResult.cs} (93%) rename src/Altinn.Profile/Controllers/{UserContactDetailsController.cs => ContactDetailsController.cs} (54%) create mode 100644 src/Altinn.Profile/Controllers/ContactDetailsInternalController.cs delete mode 100644 src/Altinn.Profile/Controllers/UserContactDetailsInternalController.cs rename src/Altinn.Profile/Models/{UserContactDetails.cs => ContactDetails.cs} (61%) create mode 100644 src/Altinn.Profile/Models/ContactDetailsLookupResult.cs delete mode 100644 src/Altinn.Profile/Models/UserContactDetailsLookupResult.cs create mode 100644 src/Altinn.Profile/UseCases/ContactDetailsRetriever.cs create mode 100644 src/Altinn.Profile/UseCases/IContactDetailsRetriever.cs delete mode 100644 src/Altinn.Profile/UseCases/IUserContactDetailsRetriever.cs delete mode 100644 src/Altinn.Profile/UseCases/UserContactDetailsRetriever.cs diff --git a/src/Altinn.Profile.Integrations/Entities/IUserContactInfoLookupResult.cs b/src/Altinn.Profile.Integrations/Entities/IContactInfoLookupResult.cs similarity index 93% rename from src/Altinn.Profile.Integrations/Entities/IUserContactInfoLookupResult.cs rename to src/Altinn.Profile.Integrations/Entities/IContactInfoLookupResult.cs index cc7c423..256acbd 100644 --- a/src/Altinn.Profile.Integrations/Entities/IUserContactInfoLookupResult.cs +++ b/src/Altinn.Profile.Integrations/Entities/IContactInfoLookupResult.cs @@ -7,7 +7,7 @@ namespace Altinn.Profile.Integrations.Entities; /// /// Defines the result of a user contact information lookup. /// -public interface IUserContactInfoLookupResult +public interface IContactInfoLookupResult { /// /// Gets a list of user contact information that was successfully matched during the lookup. diff --git a/src/Altinn.Profile.Integrations/Entities/UserContactInfoLookupResult.cs b/src/Altinn.Profile.Integrations/Entities/UserContactInfoLookupResult.cs index 20e1c73..d124ff9 100644 --- a/src/Altinn.Profile.Integrations/Entities/UserContactInfoLookupResult.cs +++ b/src/Altinn.Profile.Integrations/Entities/UserContactInfoLookupResult.cs @@ -7,7 +7,7 @@ namespace Altinn.Profile.Integrations.Entities; /// /// Represents the result of a user contact information lookup, containing matched and unmatched entries. /// -public record UserContactInfoLookupResult : IUserContactInfoLookupResult +public record UserContactInfoLookupResult : IContactInfoLookupResult { /// /// Gets a list of user contact information that was successfully matched during the lookup. diff --git a/src/Altinn.Profile.Integrations/Services/IPersonService.cs b/src/Altinn.Profile.Integrations/Services/IPersonService.cs index e09b42b..0920e05 100644 --- a/src/Altinn.Profile.Integrations/Services/IPersonService.cs +++ b/src/Altinn.Profile.Integrations/Services/IPersonService.cs @@ -26,5 +26,5 @@ public interface IPersonService /// /// A task that represents the asynchronous operation. The task result contains a collection of user contact information, or an empty collection if none are found. /// - Task> GetUserContactAsync(IEnumerable nationalIdentityNumbers); + Task> GetUserContactAsync(IEnumerable nationalIdentityNumbers); } diff --git a/src/Altinn.Profile.Integrations/Services/PersonService.cs b/src/Altinn.Profile.Integrations/Services/PersonService.cs index 1c4e9fb..ee8376f 100644 --- a/src/Altinn.Profile.Integrations/Services/PersonService.cs +++ b/src/Altinn.Profile.Integrations/Services/PersonService.cs @@ -57,7 +57,7 @@ public PersonService(IMapper mapper, IPersonRepository registerRepository, INati /// A task that represents the asynchronous operation. The task result contains a collection of user contact information, or an empty collection if none are found. /// /// Thrown if is null. - public async Task> GetUserContactAsync(IEnumerable nationalIdentityNumbers) + public async Task> GetUserContactAsync(IEnumerable nationalIdentityNumbers) { ArgumentNullException.ThrowIfNull(nationalIdentityNumbers); diff --git a/src/Altinn.Profile/Controllers/UserContactDetailsController.cs b/src/Altinn.Profile/Controllers/ContactDetailsController.cs similarity index 54% rename from src/Altinn.Profile/Controllers/UserContactDetailsController.cs rename to src/Altinn.Profile/Controllers/ContactDetailsController.cs index ffffb99..3520069 100644 --- a/src/Altinn.Profile/Controllers/UserContactDetailsController.cs +++ b/src/Altinn.Profile/Controllers/ContactDetailsController.cs @@ -11,41 +11,44 @@ namespace Altinn.Profile.Controllers; /// -/// Controller to retrieve users contact details. +/// Controller to retrieve the contact details for one or more persons. /// [Authorize] [ApiController] [Consumes("application/json")] [Produces("application/json")] [Route("profile/api/v1/contact/details")] -public class UserContactDetailsController : ControllerBase +public class ContactDetailsController : ControllerBase { - private readonly IUserContactDetailsRetriever _contactDetailsRetriever; + private readonly IContactDetailsRetriever _contactDetailsRetriever; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// The use case for retrieving user contact details. + /// The use case for retrieving the contact details. /// Thrown when the is null. - public UserContactDetailsController(IUserContactDetailsRetriever contactDetailsRetriever) + public ContactDetailsController(IContactDetailsRetriever contactDetailsRetriever) { _contactDetailsRetriever = contactDetailsRetriever ?? throw new ArgumentNullException(nameof(contactDetailsRetriever)); } /// - /// Retrieves the contact details for users based on their national identity numbers. + /// Retrieves the contact details for persons based on their national identity numbers. /// /// A collection of national identity numbers. - /// A task that represents the asynchronous operation, containing a response with users' contact details. + /// + /// A task that represents the asynchronous operation, containing a response with persons' contact details. + /// Returns a with status 200 OK if successful. + /// [HttpPost("lookup")] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(typeof(UserContactDetailsLookupResult), StatusCodes.Status200OK)] - public async Task> PostLookup([FromBody] UserContactPointLookup request) + [ProducesResponseType(typeof(ContactDetailsLookupResult), StatusCodes.Status200OK)] + public async Task> PostLookup([FromBody] UserContactPointLookup request) { var result = await _contactDetailsRetriever.RetrieveAsync(request); - return result.Match>( + return result.Match>( success => Ok(success), failure => Problem("Unable to retrieve contact details.")); } diff --git a/src/Altinn.Profile/Controllers/ContactDetailsInternalController.cs b/src/Altinn.Profile/Controllers/ContactDetailsInternalController.cs new file mode 100644 index 0000000..28b56a0 --- /dev/null +++ b/src/Altinn.Profile/Controllers/ContactDetailsInternalController.cs @@ -0,0 +1,56 @@ +using System; +using System.Threading.Tasks; + +using Altinn.Profile.Models; +using Altinn.Profile.UseCases; + +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Altinn.Profile.Controllers; + +/// +/// Controller to retrieve the contact details for one or more persons. +/// This controller is intended for internal consumption (e.g., Authorization) requiring neither authenticated user token nor access token authorization. +/// +[ApiController] +[Consumes("application/json")] +[Produces("application/json")] +[ApiExplorerSettings(IgnoreApi = true)] +[Route("profile/api/v1/internal/contact/details")] +public class ContactDetailsInternalController : ControllerBase +{ + private readonly IContactDetailsRetriever _contactDetailsRetriever; + + /// + /// Initializes a new instance of the class. + /// + /// The use case for retrieving the contact details. + /// Thrown when the is null. + public ContactDetailsInternalController(IContactDetailsRetriever contactDetailsRetriever) + { + _contactDetailsRetriever = contactDetailsRetriever ?? throw new ArgumentNullException(nameof(contactDetailsRetriever)); + } + + /// + /// Retrieves the contact details for persons based on their national identity numbers. + /// + /// A collection of national identity numbers. + /// + /// A task that represents the asynchronous operation, containing a response with persons' contact details. + /// Returns a with status 200 OK if successful, + /// 400 Bad Request if the request is invalid, or 404 Not Found if no contact details are found. + /// + [HttpPost("lookup")] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(ContactDetailsLookupResult), StatusCodes.Status200OK)] + public async Task> PostLookup([FromBody] UserContactPointLookup request) + { + var result = await _contactDetailsRetriever.RetrieveAsync(request); + + return result.Match>( + success => Ok(success), + failure => Problem("Unable to retrieve contact details.")); + } +} diff --git a/src/Altinn.Profile/Controllers/UserContactDetailsInternalController.cs b/src/Altinn.Profile/Controllers/UserContactDetailsInternalController.cs deleted file mode 100644 index 5ccb5d8..0000000 --- a/src/Altinn.Profile/Controllers/UserContactDetailsInternalController.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Threading.Tasks; - -using Altinn.Profile.Models; -using Altinn.Profile.UseCases; - -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; - -namespace Altinn.Profile.Controllers; - -/// -/// Controller to retrieve users contact details for internal consumption (e.g. Authorization) requiring neither authenticated user token nor access token authorization. -/// -[ApiController] -[Consumes("application/json")] -[Produces("application/json")] -[ApiExplorerSettings(IgnoreApi = true)] -[Route("profile/api/v1/internal/contact/details")] -public class UserContactDetailsInternalController : ControllerBase -{ - private readonly IUserContactDetailsRetriever _contactDetailsRetriever; - - /// - /// Initializes a new instance of the class. - /// - /// The use case for retrieving user contact details. - /// Thrown when the is null. - public UserContactDetailsInternalController(IUserContactDetailsRetriever contactDetailsRetriever) - { - _contactDetailsRetriever = contactDetailsRetriever ?? throw new ArgumentNullException(nameof(contactDetailsRetriever)); - } - - /// - /// Retrieves the contact details for users based on their national identity numbers. - /// - /// A collection of national identity numbers. - /// A task that represents the asynchronous operation, containing a response with users' contact details. - [HttpPost("lookup")] - [ProducesResponseType(StatusCodes.Status404NotFound)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(typeof(UserContactDetailsLookupResult), StatusCodes.Status200OK)] - public async Task> PostLookup([FromBody] UserContactPointLookup request) - { - var result = await _contactDetailsRetriever.RetrieveAsync(request); - - return result.Match>( - success => Ok(success), - failure => Problem("Unable to retrieve contact details.")); - } -} diff --git a/src/Altinn.Profile/Models/UserContactDetails.cs b/src/Altinn.Profile/Models/ContactDetails.cs similarity index 61% rename from src/Altinn.Profile/Models/UserContactDetails.cs rename to src/Altinn.Profile/Models/ContactDetails.cs index 13d12c9..bba8c59 100644 --- a/src/Altinn.Profile/Models/UserContactDetails.cs +++ b/src/Altinn.Profile/Models/ContactDetails.cs @@ -5,36 +5,36 @@ namespace Altinn.Profile.Models; /// -/// Represents a user's contact information, including national identity number, contact methods, language preference, and opt-out status. +/// Represents the contact information for a single person, including national identity number, contact methods, language preference, and opt-out status. /// -public record UserContactDetails +public record ContactDetails { /// - /// Gets the national identity number of the user. + /// Gets the national identity number of the person. /// [JsonPropertyName("nationalIdentityNumber")] public required string NationalIdentityNumber { get; init; } /// - /// Gets a value indicating whether the user has opted out of being contacted. + /// Gets a value indicating whether the person has opted out of being contacted. /// [JsonPropertyName("reservation")] public bool? Reservation { get; init; } /// - /// Gets the mobile phone number of the user. + /// Gets the mobile phone number of the person. /// [JsonPropertyName("mobilePhoneNumber")] public string? MobilePhoneNumber { get; init; } /// - /// Gets the email address of the user. + /// Gets the email address of the person. /// [JsonPropertyName("emailAddress")] public string? EmailAddress { get; init; } /// - /// Gets the language code preferred by the user for communication. + /// Gets the language code preferred by the person for communication. /// [JsonPropertyName("languageCode")] public string? LanguageCode { get; init; } diff --git a/src/Altinn.Profile/Models/ContactDetailsLookupResult.cs b/src/Altinn.Profile/Models/ContactDetailsLookupResult.cs new file mode 100644 index 0000000..1a9d4a6 --- /dev/null +++ b/src/Altinn.Profile/Models/ContactDetailsLookupResult.cs @@ -0,0 +1,39 @@ +#nullable enable + +using System.Collections.Immutable; +using System.Text.Json.Serialization; + +namespace Altinn.Profile.Models; + +/// +/// Represents the results of a contact details lookup operation. +/// +public record ContactDetailsLookupResult +{ + /// + /// Gets a list of contact details that were successfully matched based on the national identity number. + /// + [JsonPropertyName("matchedContactDetails")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ImmutableList? MatchedContactDetails { get; init; } + + /// + /// Gets a list of national identity numbers that could not be matched with any contact details. + /// + [JsonPropertyName("unmatchedNationalIdentityNumbers")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ImmutableList? UnmatchedNationalIdentityNumbers { get; init; } + + /// + /// Initializes a new instance of the record. + /// + /// The list of contact details that were successfully matched based on the national identity number. + /// The list of national identity numbers that could not be matched with any contact details. + public ContactDetailsLookupResult( + ImmutableList matchedContactDetails, + ImmutableList unmatchedNationalIdentityNumbers) + { + MatchedContactDetails = matchedContactDetails; + UnmatchedNationalIdentityNumbers = unmatchedNationalIdentityNumbers; + } +} diff --git a/src/Altinn.Profile/Models/UserContactDetailsLookupResult.cs b/src/Altinn.Profile/Models/UserContactDetailsLookupResult.cs deleted file mode 100644 index 83654b0..0000000 --- a/src/Altinn.Profile/Models/UserContactDetailsLookupResult.cs +++ /dev/null @@ -1,39 +0,0 @@ -#nullable enable - -using System.Collections.Immutable; -using System.Text.Json.Serialization; - -namespace Altinn.Profile.Models; - -/// -/// Represents the results of a user contact details lookup operation. -/// -public record UserContactDetailsLookupResult -{ - /// - /// Gets a list of user contact details that were successfully matched based on the national identity number. - /// - [JsonPropertyName("matchedUserContactDetails")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public ImmutableList? MatchedUserContactDetails { get; init; } - - /// - /// Gets a list of national identity numbers that could not be matched with user contact details. - /// - [JsonPropertyName("unmatchedNationalIdentityNumbers")] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public ImmutableList? UnmatchedNationalIdentityNumbers { get; init; } - - /// - /// Initializes a new instance of the record. - /// - /// The list of contact details that were matched based on the national identity number. - /// The list of national identity numbers that could not be matched with user contact details. - public UserContactDetailsLookupResult( - ImmutableList matchedUserContactDetails, - ImmutableList unmatchedNationalIdentityNumbers) - { - MatchedUserContactDetails = matchedUserContactDetails; - UnmatchedNationalIdentityNumbers = unmatchedNationalIdentityNumbers; - } -} diff --git a/src/Altinn.Profile/Program.cs b/src/Altinn.Profile/Program.cs index 50caefd..752fcbc 100644 --- a/src/Altinn.Profile/Program.cs +++ b/src/Altinn.Profile/Program.cs @@ -170,7 +170,7 @@ void ConfigureServices(IServiceCollection services, IConfiguration config) services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddScoped(); + services.AddScoped(); services.AddAuthentication(JwtCookieDefaults.AuthenticationScheme) .AddJwtCookie(JwtCookieDefaults.AuthenticationScheme, options => diff --git a/src/Altinn.Profile/UseCases/ContactDetailsRetriever.cs b/src/Altinn.Profile/UseCases/ContactDetailsRetriever.cs new file mode 100644 index 0000000..38386f5 --- /dev/null +++ b/src/Altinn.Profile/UseCases/ContactDetailsRetriever.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; + +using Altinn.Profile.Core; +using Altinn.Profile.Integrations.Entities; +using Altinn.Profile.Integrations.Services; +using Altinn.Profile.Models; + +namespace Altinn.Profile.UseCases; + +/// +/// Provides an implementation for retrieving the contact details for one or more persons. +/// +public class ContactDetailsRetriever : IContactDetailsRetriever +{ + private readonly IPersonService _personService; + + /// + /// Initializes a new instance of the class. + /// + /// The person service for retrieving contact details. + /// Thrown when is null. + public ContactDetailsRetriever(IPersonService personService) + { + _personService = personService ?? throw new ArgumentNullException(nameof(personService)); + } + + /// + /// Asynchronously retrieves the contact details for one or more persons based on the specified lookup criteria. + /// + /// The criteria used to look up contact details, including the national identity numbers of the persons. + /// + /// A task representing the asynchronous operation. + /// The task result contains a object, where represents the successful outcome and indicates a failure. + /// + /// Thrown when is null. + public async Task> RetrieveAsync(UserContactPointLookup lookupCriteria) + { + ArgumentNullException.ThrowIfNull(lookupCriteria); + + if (lookupCriteria?.NationalIdentityNumbers == null || lookupCriteria.NationalIdentityNumbers.Count == 0) + { + return false; + } + + var contactDetails = await _personService.GetUserContactAsync(lookupCriteria.NationalIdentityNumbers); + + return contactDetails.Match( + MapToContactDetailsLookupResult, + _ => false); + } + + /// + /// Maps the person contact details to a . + /// + /// The person contact details to map. + /// The mapped . + /// Thrown when is null. + private ContactDetails MapToContactDetails(IUserContactInfo personContactDetails) + { + ArgumentNullException.ThrowIfNull(personContactDetails); + + return new ContactDetails + { + Reservation = personContactDetails.IsReserved, + EmailAddress = personContactDetails.EmailAddress, + LanguageCode = personContactDetails.LanguageCode, + MobilePhoneNumber = personContactDetails.MobilePhoneNumber, + NationalIdentityNumber = personContactDetails.NationalIdentityNumber + }; + } + + /// + /// Maps the person contact details lookup result to a . + /// + /// The lookup result containing the person contact details. + /// + /// A containing a if the mapping is successful, or false if the mapping fails. + /// + /// Thrown when is null. + private Result MapToContactDetailsLookupResult(IContactInfoLookupResult personContactDetailsLookupResult) + { + ArgumentNullException.ThrowIfNull(personContactDetailsLookupResult); + + var matchedContactDetails = personContactDetailsLookupResult.MatchedUserContact?.Select(MapToContactDetails).ToImmutableList(); + + return new ContactDetailsLookupResult(matchedContactDetails, personContactDetailsLookupResult?.UnmatchedNationalIdentityNumbers); + } +} diff --git a/src/Altinn.Profile/UseCases/IContactDetailsRetriever.cs b/src/Altinn.Profile/UseCases/IContactDetailsRetriever.cs new file mode 100644 index 0000000..b3ff503 --- /dev/null +++ b/src/Altinn.Profile/UseCases/IContactDetailsRetriever.cs @@ -0,0 +1,22 @@ +using System.Threading.Tasks; + +using Altinn.Profile.Core; +using Altinn.Profile.Models; + +namespace Altinn.Profile.UseCases; + +/// +/// Defines a use case for retrieving the contact details for one or more persons. +/// +public interface IContactDetailsRetriever +{ + /// + /// Asynchronously retrieves the contact details for one or more persons based on the specified lookup criteria. + /// + /// The criteria used to look up contact details, including the national identity numbers of the persons. + /// + /// A task representing the asynchronous operation. + /// The task result contains a object, where represents the successful outcome and indicates a failure. + /// + Task> RetrieveAsync(UserContactPointLookup lookupCriteria); +} diff --git a/src/Altinn.Profile/UseCases/IUserContactDetailsRetriever.cs b/src/Altinn.Profile/UseCases/IUserContactDetailsRetriever.cs deleted file mode 100644 index 912200b..0000000 --- a/src/Altinn.Profile/UseCases/IUserContactDetailsRetriever.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Threading.Tasks; - -using Altinn.Profile.Core; -using Altinn.Profile.Models; - -namespace Altinn.Profile.UseCases; - -/// -/// Defines a use case for retrieving user contact details. -/// -public interface IUserContactDetailsRetriever -{ - /// - /// Asynchronously retrieves the contact details for one or more users based on the specified lookup criteria. - /// - /// The user contact point lookup criteria, which includes national identity numbers. - /// A task representing the asynchronous operation. The task result contains the outcome of the user contact details retrieval. - Task> RetrieveAsync(UserContactPointLookup lookupCriteria); -} diff --git a/src/Altinn.Profile/UseCases/UserContactDetailsRetriever.cs b/src/Altinn.Profile/UseCases/UserContactDetailsRetriever.cs deleted file mode 100644 index 1b97c48..0000000 --- a/src/Altinn.Profile/UseCases/UserContactDetailsRetriever.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections.Immutable; -using System.Linq; -using System.Threading.Tasks; - -using Altinn.Profile.Core; -using Altinn.Profile.Integrations.Entities; -using Altinn.Profile.Integrations.Services; -using Altinn.Profile.Models; - -namespace Altinn.Profile.UseCases; - -/// -/// Provides an implementation for retrieving user contact details based on specified lookup criteria. -/// -public class UserContactDetailsRetriever : IUserContactDetailsRetriever -{ - private readonly IPersonService _registerService; - - /// - /// Initializes a new instance of the class. - /// - /// The register service for retrieving user contact details. - /// Thrown when is null. - public UserContactDetailsRetriever(IPersonService registerService) - { - _registerService = registerService ?? throw new ArgumentNullException(nameof(registerService)); - } - - /// - /// Asynchronously retrieves the contact details for one or more users based on the specified lookup criteria. - /// - /// The user contact point lookup criteria, which includes national identity numbers. - /// - /// A task representing the asynchronous operation. The task result contains a - /// where the value is and the error is . - /// - /// Thrown when is null. - public async Task> RetrieveAsync(UserContactPointLookup lookupCriteria) - { - ArgumentNullException.ThrowIfNull(lookupCriteria); - - if (lookupCriteria?.NationalIdentityNumbers == null || lookupCriteria.NationalIdentityNumbers.Count == 0) - { - return false; - } - - var userContactDetails = await _registerService.GetUserContactAsync(lookupCriteria.NationalIdentityNumbers); - - return userContactDetails.Match( - MapToUserContactDetailsLookupResult, - _ => false); - } - - /// - /// Maps an to a . - /// - /// The user contact details to map. - /// The mapped . - /// Thrown when is null. - private UserContactDetails MapToUserContactDetails(IUserContactInfo userContactDetails) - { - ArgumentNullException.ThrowIfNull(userContactDetails); - - return new UserContactDetails - { - Reservation = userContactDetails.IsReserved, - EmailAddress = userContactDetails.EmailAddress, - LanguageCode = userContactDetails.LanguageCode, - MobilePhoneNumber = userContactDetails.MobilePhoneNumber, - NationalIdentityNumber = userContactDetails.NationalIdentityNumber - }; - } - - /// - /// Maps the user contact details lookup result to a . - /// - /// The user contact details lookup result. - /// A containing the mapped user contact details. - /// Thrown when is null. - private Result MapToUserContactDetailsLookupResult(IUserContactInfoLookupResult userContactResult) - { - ArgumentNullException.ThrowIfNull(userContactResult); - - var unmatchedNationalIdentityNumbers = userContactResult?.UnmatchedNationalIdentityNumbers; - var matchedUserContactDetails = userContactResult?.MatchedUserContact?.Select(MapToUserContactDetails).ToImmutableList(); - - return new UserContactDetailsLookupResult(matchedUserContactDetails, unmatchedNationalIdentityNumbers); - } -} diff --git a/test/Altinn.Profile.Tests/Profile.Integrations/UserContactDetailsRetrieverTests.cs b/test/Altinn.Profile.Tests/Profile.Integrations/UserContactDetailsRetrieverTests.cs index 218e116..ae8e0cc 100644 --- a/test/Altinn.Profile.Tests/Profile.Integrations/UserContactDetailsRetrieverTests.cs +++ b/test/Altinn.Profile.Tests/Profile.Integrations/UserContactDetailsRetrieverTests.cs @@ -18,12 +18,12 @@ namespace Altinn.Profile.Tests.Profile.Integrations; public class UserContactDetailsRetrieverTests { private readonly Mock _mockRegisterService; - private readonly UserContactDetailsRetriever _retriever; + private readonly ContactDetailsRetriever _retriever; public UserContactDetailsRetrieverTests() { _mockRegisterService = new Mock(); - _retriever = new UserContactDetailsRetriever(_mockRegisterService.Object); + _retriever = new ContactDetailsRetriever(_mockRegisterService.Object); } [Fact]