Skip to content

Commit

Permalink
Rename a number of classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed-Ghanam committed Oct 8, 2024
1 parent e64c189 commit 2a7bcf9
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Altinn.Profile.Integrations.Entities;
/// <summary>
/// Defines the result of a user contact information lookup.
/// </summary>
public interface IUserContactInfoLookupResult
public interface IContactInfoLookupResult
{
/// <summary>
/// Gets a list of user contact information that was successfully matched during the lookup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Altinn.Profile.Integrations.Entities;
/// <summary>
/// Represents the result of a user contact information lookup, containing matched and unmatched entries.
/// </summary>
public record UserContactInfoLookupResult : IUserContactInfoLookupResult
public record UserContactInfoLookupResult : IContactInfoLookupResult
{
/// <summary>
/// Gets a list of user contact information that was successfully matched during the lookup.
Expand Down
2 changes: 1 addition & 1 deletion src/Altinn.Profile.Integrations/Services/IPersonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IUserContactInfoLookupResult, bool>> GetUserContactAsync(IEnumerable<string> nationalIdentityNumbers);
Task<Result<IContactInfoLookupResult, bool>> GetUserContactAsync(IEnumerable<string> nationalIdentityNumbers);
}
2 changes: 1 addition & 1 deletion src/Altinn.Profile.Integrations/Services/PersonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </returns>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="nationalIdentityNumbers"/> is <c>null</c>.</exception>
public async Task<Result<IUserContactInfoLookupResult, bool>> GetUserContactAsync(IEnumerable<string> nationalIdentityNumbers)
public async Task<Result<IContactInfoLookupResult, bool>> GetUserContactAsync(IEnumerable<string> nationalIdentityNumbers)
{
ArgumentNullException.ThrowIfNull(nationalIdentityNumbers);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,44 @@
namespace Altinn.Profile.Controllers;

/// <summary>
/// Controller to retrieve users contact details.
/// Controller to retrieve the contact details for one or more persons.
/// </summary>
[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;

/// <summary>
/// Initializes a new instance of the <see cref="UserContactDetailsController"/> class.
/// Initializes a new instance of the <see cref="ContactDetailsController"/> class.
/// </summary>
/// <param name="contactDetailsRetriever">The use case for retrieving user contact details.</param>
/// <param name="contactDetailsRetriever">The use case for retrieving the contact details.</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="contactDetailsRetriever"/> is null.</exception>
public UserContactDetailsController(IUserContactDetailsRetriever contactDetailsRetriever)
public ContactDetailsController(IContactDetailsRetriever contactDetailsRetriever)
{
_contactDetailsRetriever = contactDetailsRetriever ?? throw new ArgumentNullException(nameof(contactDetailsRetriever));
}

/// <summary>
/// Retrieves the contact details for users based on their national identity numbers.
/// Retrieves the contact details for persons based on their national identity numbers.
/// </summary>
/// <param name="request">A collection of national identity numbers.</param>
/// <returns>A task that represents the asynchronous operation, containing a response with users' contact details.</returns>
/// <returns>
/// A task that represents the asynchronous operation, containing a response with persons' contact details.
/// Returns a <see cref="ContactDetailsLookupResult"/> with status 200 OK if successful.
/// </returns>
[HttpPost("lookup")]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(UserContactDetailsLookupResult), StatusCodes.Status200OK)]
public async Task<ActionResult<UserContactDetailsLookupResult>> PostLookup([FromBody] UserContactPointLookup request)
[ProducesResponseType(typeof(ContactDetailsLookupResult), StatusCodes.Status200OK)]
public async Task<ActionResult<ContactDetailsLookupResult>> PostLookup([FromBody] UserContactPointLookup request)
{
var result = await _contactDetailsRetriever.RetrieveAsync(request);

return result.Match<ActionResult<UserContactDetailsLookupResult>>(
return result.Match<ActionResult<ContactDetailsLookupResult>>(
success => Ok(success),
failure => Problem("Unable to retrieve contact details."));
}
Expand Down
56 changes: 56 additions & 0 deletions src/Altinn.Profile/Controllers/ContactDetailsInternalController.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// 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.
/// </summary>
[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;

/// <summary>
/// Initializes a new instance of the <see cref="ContactDetailsInternalController"/> class.
/// </summary>
/// <param name="contactDetailsRetriever">The use case for retrieving the contact details.</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="contactDetailsRetriever"/> is null.</exception>
public ContactDetailsInternalController(IContactDetailsRetriever contactDetailsRetriever)
{
_contactDetailsRetriever = contactDetailsRetriever ?? throw new ArgumentNullException(nameof(contactDetailsRetriever));
}

/// <summary>
/// Retrieves the contact details for persons based on their national identity numbers.
/// </summary>
/// <param name="request">A collection of national identity numbers.</param>
/// <returns>
/// A task that represents the asynchronous operation, containing a response with persons' contact details.
/// Returns a <see cref="ContactDetailsLookupResult"/> with status 200 OK if successful,
/// 400 Bad Request if the request is invalid, or 404 Not Found if no contact details are found.
/// </returns>
[HttpPost("lookup")]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ContactDetailsLookupResult), StatusCodes.Status200OK)]
public async Task<ActionResult<ContactDetailsLookupResult>> PostLookup([FromBody] UserContactPointLookup request)
{
var result = await _contactDetailsRetriever.RetrieveAsync(request);

return result.Match<ActionResult<ContactDetailsLookupResult>>(
success => Ok(success),
failure => Problem("Unable to retrieve contact details."));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@
namespace Altinn.Profile.Models;

/// <summary>
/// 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.
/// </summary>
public record UserContactDetails
public record ContactDetails
{
/// <summary>
/// Gets the national identity number of the user.
/// Gets the national identity number of the person.
/// </summary>
[JsonPropertyName("nationalIdentityNumber")]
public required string NationalIdentityNumber { get; init; }

/// <summary>
/// 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.
/// </summary>
[JsonPropertyName("reservation")]
public bool? Reservation { get; init; }

/// <summary>
/// Gets the mobile phone number of the user.
/// Gets the mobile phone number of the person.
/// </summary>
[JsonPropertyName("mobilePhoneNumber")]
public string? MobilePhoneNumber { get; init; }

/// <summary>
/// Gets the email address of the user.
/// Gets the email address of the person.
/// </summary>
[JsonPropertyName("emailAddress")]
public string? EmailAddress { get; init; }

/// <summary>
/// Gets the language code preferred by the user for communication.
/// Gets the language code preferred by the person for communication.
/// </summary>
[JsonPropertyName("languageCode")]
public string? LanguageCode { get; init; }
Expand Down
39 changes: 39 additions & 0 deletions src/Altinn.Profile/Models/ContactDetailsLookupResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#nullable enable

using System.Collections.Immutable;
using System.Text.Json.Serialization;

namespace Altinn.Profile.Models;

/// <summary>
/// Represents the results of a contact details lookup operation.
/// </summary>
public record ContactDetailsLookupResult
{
/// <summary>
/// Gets a list of contact details that were successfully matched based on the national identity number.
/// </summary>
[JsonPropertyName("matchedContactDetails")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ImmutableList<ContactDetails>? MatchedContactDetails { get; init; }

/// <summary>
/// Gets a list of national identity numbers that could not be matched with any contact details.
/// </summary>
[JsonPropertyName("unmatchedNationalIdentityNumbers")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ImmutableList<string>? UnmatchedNationalIdentityNumbers { get; init; }

/// <summary>
/// Initializes a new instance of the <see cref="ContactDetailsLookupResult"/> record.
/// </summary>
/// <param name="matchedContactDetails">The list of contact details that were successfully matched based on the national identity number.</param>
/// <param name="unmatchedNationalIdentityNumbers">The list of national identity numbers that could not be matched with any contact details.</param>
public ContactDetailsLookupResult(
ImmutableList<ContactDetails> matchedContactDetails,
ImmutableList<string> unmatchedNationalIdentityNumbers)
{
MatchedContactDetails = matchedContactDetails;
UnmatchedNationalIdentityNumbers = unmatchedNationalIdentityNumbers;
}
}
39 changes: 0 additions & 39 deletions src/Altinn.Profile/Models/UserContactDetailsLookupResult.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Altinn.Profile/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void ConfigureServices(IServiceCollection services, IConfiguration config)
services.AddSingleton<IAuthorizationHandler, AccessTokenHandler>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<IPublicSigningKeyProvider, PublicSigningKeyProvider>();
services.AddScoped<IUserContactDetailsRetriever, UserContactDetailsRetriever>();
services.AddScoped<IContactDetailsRetriever, ContactDetailsRetriever>();

services.AddAuthentication(JwtCookieDefaults.AuthenticationScheme)
.AddJwtCookie(JwtCookieDefaults.AuthenticationScheme, options =>
Expand Down
Loading

0 comments on commit 2a7bcf9

Please sign in to comment.