Skip to content

Commit

Permalink
Rename some classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed-Ghanam committed Oct 8, 2024
1 parent 2a7bcf9 commit 16dc240
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 170 deletions.

This file was deleted.

34 changes: 34 additions & 0 deletions src/Altinn.Profile.Integrations/Entities/IPersonContactDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#nullable enable

namespace Altinn.Profile.Integrations.Entities;

/// <summary>
/// Represents a person's contact details.
/// </summary>
public interface IPersonContactDetails
{
/// <summary>
/// Gets the national identity number of the person.
/// </summary>
string NationalIdentityNumber { get; }

/// <summary>
/// Gets a value indicating whether the person opts out of being contacted.
/// </summary>
bool? IsReserved { get; }

/// <summary>
/// Gets the mobile phone number of the person.
/// </summary>
string? MobilePhoneNumber { get; }

/// <summary>
/// Gets the email address of the person.
/// </summary>
string? EmailAddress { get; }

/// <summary>
/// Gets the language code of the person, represented as an ISO 639-1 code.
/// </summary>
string? LanguageCode { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#nullable enable

using System.Collections.Immutable;

namespace Altinn.Profile.Integrations.Entities;

/// <summary>
/// Represents the result of a lookup operation for contact details.
/// </summary>
public interface IPersonContactDetailsLookupResult
{
/// <summary>
/// Gets a list of national identity numbers that could not be matched with any person contact details.
/// </summary>
/// <value>
/// An <see cref="ImmutableList{T}"/> of <see cref="string"/> containing the unmatched national identity numbers.
/// </value>
ImmutableList<string>? UnmatchedNationalIdentityNumbers { get; }

/// <summary>
/// Gets a list of person contact details that were successfully matched during the lookup.
/// </summary>
/// <value>
/// An <see cref="ImmutableList{T}"/> of <see cref="IPersonContactDetails"/> containing the matched person contact details.
/// </value>
ImmutableList<IPersonContactDetails>? MatchedPersonContactDetails { get; }
}
49 changes: 0 additions & 49 deletions src/Altinn.Profile.Integrations/Entities/IUserContactInfo.cs

This file was deleted.

34 changes: 34 additions & 0 deletions src/Altinn.Profile.Integrations/Entities/PersonContactDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#nullable enable

namespace Altinn.Profile.Integrations.Entities;

/// <summary>
/// Represents a person's contact details.
/// </summary>
public record PersonContactDetails : IPersonContactDetails
{
/// <summary>
/// Gets the national identity number of the person.
/// </summary>
public required string NationalIdentityNumber { get; init; }

/// <summary>
/// Gets a value indicating whether the person opts out of being contacted.
/// </summary>
public bool? IsReserved { get; init; }

/// <summary>
/// Gets the mobile phone number of the person.
/// </summary>
public string? MobilePhoneNumber { get; init; }

/// <summary>
/// Gets the email address of the person.
/// </summary>
public string? EmailAddress { get; init; }

/// <summary>
/// Gets the language code of the person, represented as an ISO 639-1 code.
/// </summary>
public string? LanguageCode { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#nullable enable

using System.Collections.Immutable;

namespace Altinn.Profile.Integrations.Entities;

/// <summary>
/// Represents the result of a lookup operation for contact details.
/// </summary>
public record PersonContactDetailsLookupResult : IPersonContactDetailsLookupResult
{
/// <summary>
/// Gets a list of national identity numbers that could not be matched with any person contact details.
/// </summary>
/// <value>
/// An <see cref="ImmutableList{T}"/> of <see cref="string"/> containing the unmatched national identity numbers.
/// </value>
public ImmutableList<string>? UnmatchedNationalIdentityNumbers { get; init; }

/// <summary>
/// Gets a list of person contact details that were successfully matched during the lookup.
/// </summary>
/// <value>
/// An <see cref="ImmutableList{T}"/> of <see cref="IPersonContactDetails"/> containing the matched person contact details.
/// </value>
public ImmutableList<IPersonContactDetails>? MatchedPersonContactDetails { get; init; }
}
49 changes: 0 additions & 49 deletions src/Altinn.Profile.Integrations/Entities/UserContactInfo.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
namespace Altinn.Profile.Integrations.Mappings;

/// <summary>
/// AutoMapper profile for mapping between <see cref="Register"/> and <see cref="UserContactInfo"/>.
/// AutoMapper profile for mapping between <see cref="Person"/> and <see cref="PersonContactDetails"/>.
/// </summary>
/// <remarks>
/// This profile defines the mapping rules to convert a <see cref="Register"/> object into a <see cref="UserContactInfo"/> instance.
/// This profile defines the mapping rules to convert a <see cref="Person"/> object into a <see cref="PersonContactDetails"/> instance.
/// </remarks>
public class PersonToUserContactInfoProfile : AutoMapper.Profile
public class PersonContactDetailsProfile : AutoMapper.Profile
{
/// <summary>
/// Initializes a new instance of the <see cref="PersonToUserContactInfoProfile"/> class
/// and configures the mappings.
/// Initializes a new instance of the <see cref="PersonContactDetailsProfile"/> class and configures the mappings.
/// </summary>
public PersonToUserContactInfoProfile()
public PersonContactDetailsProfile()
{
CreateMap<Person, UserContactInfo>()
CreateMap<Person, PersonContactDetails>()
.ForMember(dest => dest.IsReserved, opt => opt.MapFrom(src => src.Reservation))
.ForMember(dest => dest.EmailAddress, opt => opt.MapFrom(src => src.EmailAddress))
.ForMember(dest => dest.LanguageCode, opt => opt.MapFrom(src => src.LanguageCode))
Expand Down
4 changes: 2 additions & 2 deletions src/Altinn.Profile.Integrations/Services/IPersonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IPersonService
/// <returns>
/// A task that represents the asynchronous operation. The task result contains the user's contact information, or <c>null</c> if not found.
/// </returns>
Task<IUserContactInfo?> GetUserContactInfoAsync(string nationalIdentityNumber);
Task<IPersonContactDetails?> GetUserContactInfoAsync(string nationalIdentityNumber);

/// <summary>
/// Asynchronously retrieves the contact information for multiple users based on their national identity numbers.
Expand All @@ -26,5 +26,5 @@ public interface IPersonService
/// <returns>
/// 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.
/// </returns>
Task<Result<IContactInfoLookupResult, bool>> GetUserContactAsync(IEnumerable<string> nationalIdentityNumbers);
Task<Result<IPersonContactDetailsLookupResult, bool>> GetUserContactAsync(IEnumerable<string> nationalIdentityNumbers);
}
12 changes: 6 additions & 6 deletions src/Altinn.Profile.Integrations/Services/PersonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public PersonService(IMapper mapper, IPersonRepository registerRepository, INati
/// <returns>
/// A task that represents the asynchronous operation. The task result contains the user's contact information, or <c>null</c> if not found.
/// </returns>
public async Task<IUserContactInfo?> GetUserContactInfoAsync(string nationalIdentityNumber)
public async Task<IPersonContactDetails?> GetUserContactInfoAsync(string nationalIdentityNumber)
{
if (!_nationalIdentityNumberChecker.IsValid(nationalIdentityNumber))
{
return null;
}

var userContactInfoEntity = await _registerRepository.GetUserContactInfoAsync([nationalIdentityNumber]);
return _mapper.Map<IUserContactInfo>(userContactInfoEntity);
return _mapper.Map<IPersonContactDetails>(userContactInfoEntity);
}

/// <summary>
Expand All @@ -57,22 +57,22 @@ 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.
/// </returns>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="nationalIdentityNumbers"/> is <c>null</c>.</exception>
public async Task<Result<IContactInfoLookupResult, bool>> GetUserContactAsync(IEnumerable<string> nationalIdentityNumbers)
public async Task<Result<IPersonContactDetailsLookupResult, bool>> GetUserContactAsync(IEnumerable<string> nationalIdentityNumbers)
{
ArgumentNullException.ThrowIfNull(nationalIdentityNumbers);

var (validnNtionalIdentityNumbers, _) = _nationalIdentityNumberChecker.Categorize(nationalIdentityNumbers);

var usersContactInfo = await _registerRepository.GetUserContactInfoAsync(validnNtionalIdentityNumbers);

var matchedUserContact = usersContactInfo.Select(_mapper.Map<UserContactInfo>);
var matchedUserContact = usersContactInfo.Select(_mapper.Map<PersonContactDetails>);

var matchedNationalIdentityNumbers = new HashSet<string>(usersContactInfo.Select(e => e.FnumberAk));
var unmatchedNationalIdentityNumbers = nationalIdentityNumbers.Where(e => !matchedNationalIdentityNumbers.Contains(e));

return new UserContactInfoLookupResult
return new PersonContactDetailsLookupResult
{
MatchedUserContact = matchedUserContact.ToImmutableList<IUserContactInfo>(),
MatchedPersonContactDetails = matchedUserContact.ToImmutableList<IPersonContactDetails>(),
UnmatchedNationalIdentityNumbers = unmatchedNationalIdentityNumbers.ToImmutableList()
};
}
Expand Down
Loading

0 comments on commit 16dc240

Please sign in to comment.