Skip to content

Commit

Permalink
Introduce a DTO class for UserContactPoints as received from Profile API
Browse files Browse the repository at this point in the history
  • Loading branch information
hggutvik committed Nov 13, 2024
1 parent a94354e commit 0d03814
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Altinn.Notifications.Core.Models.ContactPoints;
using Altinn.Notifications.Integrations.Profile.Models;

namespace Altinn.Notifications.Integrations.Profile.Mappers;

/// <summary>
/// Extension class to map from DTO / Profile API model to domain model for UserContactPoints
/// </summary>
public static class UserContactPointsDTOMapperExtension

Check warning on line 9 in src/Altinn.Notifications.Integrations/Profile/Mappers/UserContactPointsDTOMapperExtension.cs

View workflow job for this annotation

GitHub Actions / Build, test & analyze

Rename class 'UserContactPointsDTOMapperExtension' to match pascal case naming rules, consider using 'UserContactPointsDtoMapperExtension'. (https://rules.sonarsource.com/csharp/RSPEC-101)

Check warning on line 9 in src/Altinn.Notifications.Integrations/Profile/Mappers/UserContactPointsDTOMapperExtension.cs

View workflow job for this annotation

GitHub Actions / Build, test & analyze

Rename class 'UserContactPointsDTOMapperExtension' to match pascal case naming rules, consider using 'UserContactPointsDtoMapperExtension'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
/// <summary>
/// Maps the DTO model to domain model
/// </summary>
/// <param name="userContactPointDto">This DTO object</param>
/// <returns>The UserContactPoints object mapped from this DTO object</returns>
public static UserContactPoints ToUserContactPoint(this UserContactPointsDTO userContactPointDto)
{
return new UserContactPoints
{
UserId = userContactPointDto.UserId ?? 0,
NationalIdentityNumber = userContactPointDto.NationalIdentityNumber ?? string.Empty,
IsReserved = userContactPointDto.IsReserved,
MobileNumber = userContactPointDto.MobileNumber ?? string.Empty,
Email = userContactPointDto.Email ?? string.Empty
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Altinn.Notifications.Integrations.Profile.Models;

/// <summary>
/// Data transfer object for the API model describing the availability of contact points for a user, received from the ProfileClient
/// </summary>
public class UserContactPointsDTO

Check warning on line 6 in src/Altinn.Notifications.Integrations/Profile/Models/UserContactPointsDTO.cs

View workflow job for this annotation

GitHub Actions / Build, test & analyze

Rename class 'UserContactPointsDTO' to match pascal case naming rules, consider using 'UserContactPointsDto'. (https://rules.sonarsource.com/csharp/RSPEC-101)

Check warning on line 6 in src/Altinn.Notifications.Integrations/Profile/Models/UserContactPointsDTO.cs

View workflow job for this annotation

GitHub Actions / Build, test & analyze

Rename class 'UserContactPointsDTO' to match pascal case naming rules, consider using 'UserContactPointsDto'. (https://rules.sonarsource.com/csharp/RSPEC-101)
{
/// <summary>
/// Gets or sets the ID of the user
/// </summary>
public int? UserId { get; set; }

/// <summary>
/// Gets or sets the national identityt number of the user
/// </summary>
public string? NationalIdentityNumber { get; set; }

/// <summary>
/// Gets or sets a boolean indicating whether the user has reserved themselves from electronic communication
/// </summary>
public bool IsReserved { get; set; }

/// <summary>
/// Gets or sets the mobile number
/// </summary>
public string? MobileNumber { get; set; }

/// <summary>
/// Gets or sets the email address
/// </summary>
public string? Email { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Altinn.Notifications.Core.Shared;
using Altinn.Notifications.Integrations.Configuration;
using Altinn.Notifications.Integrations.Profile;
using Altinn.Notifications.Integrations.Profile.Mappers;
using Altinn.Notifications.Integrations.Profile.Models;
using Altinn.Notifications.Integrations.Register;

using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -47,8 +49,9 @@ public async Task<List<UserContactPoints>> GetUserContactPoints(List<string> nat
}

string responseContent = await response.Content.ReadAsStringAsync();
List<UserContactPoints> contactPoints = JsonSerializer.Deserialize<UserContactPointsList>(responseContent, JsonSerializerOptionsProvider.Options)!.ContactPointsList;
return contactPoints!;
List<UserContactPointsDTO> contactPoints = JsonSerializer.Deserialize<UserContactPointsList>(responseContent, JsonSerializerOptionsProvider.Options)!.ContactPointsList;

return contactPoints.Select(contactPointDto => contactPointDto.ToUserContactPoint()).ToList();
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Altinn.Notifications.Core.Models.ContactPoints;
using Altinn.Notifications.Integrations.Profile.Models;

namespace Altinn.Notifications.Integrations.Profile;

Expand All @@ -10,5 +11,5 @@ public class UserContactPointsList
/// <summary>
/// A list containing contact points for users
/// </summary>
public List<UserContactPoints> ContactPointsList { get; set; } = [];
public List<UserContactPointsDTO> ContactPointsList { get; set; } = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Altinn.Notifications.Integrations.Clients;
using Altinn.Notifications.Integrations.Configuration;
using Altinn.Notifications.Integrations.Profile;
using Altinn.Notifications.Integrations.Profile.Models;
using Altinn.Notifications.Integrations.Register;

using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -128,15 +129,15 @@ private Task<HttpResponseMessage> GetUserProfileResponse(UserContactPointLookup
switch (lookup.NationalIdentityNumbers[0])
{
case "empty-list":
contentData = new UserContactPointsList() { ContactPointsList = new List<UserContactPoints>() };
contentData = new UserContactPointsList() { ContactPointsList = new List<UserContactPointsDTO>() };
break;
case "populated-list":
contentData = new UserContactPointsList()
{
ContactPointsList =
[
new UserContactPoints() { NationalIdentityNumber = "01025101038", Email = string.Empty },
new UserContactPoints() { NationalIdentityNumber = "01025101037", Email = string.Empty }
new UserContactPointsDTO() { NationalIdentityNumber = "01025101038", Email = string.Empty },
new UserContactPointsDTO() { NationalIdentityNumber = "01025101037", Email = string.Empty }
]
};
break;
Expand Down

0 comments on commit 0d03814

Please sign in to comment.