Account Settings Mapper (AccountSettingsMapper) Class
Namespace: Cxt.Account.Settings.API.Mapper
Implements: IAccountSettingsMapper
The AccountSettingsMapper class is the concrete implementation of IAccountSettingsMapper. It transforms data from the data access layer format (e.g., List<AccountSettingsPreferencesDto>) into the AccountSettingsResponse model for API output.
Purpose
- Converts a flat list of account preferences (DTOs) into a hierarchical
AccountSettingsResponse. - Groups accounts by
ProfileId. - Maps
AccountSettingsPreferencesDtoproperties toAccountModelproperties. - Assembles the final
AccountSettingsResponse, including GCN, business unit, and profiles with their associated accounts.
Dependencies
- Operates directly on input
List<AccountSettingsPreferencesDto>. - Uses models from
Investec.AccountSettings.ModelsNuGet package (e.g.,AccountSettingsResponse,AccountSettingsPreferencesDto,AccountModel,AccountSettingsProfileAccountResponse). No explicit constructor dependencies.
Method Implementation
Map To Account Settings Response
csharp
public AccountSettingsResponse MapToAccountSettingsResponse(List<AccountSettingsPreferencesDto> clientAccounts)Parameters:
Parameter Type Description clientAccountsList<AccountSettingsPreferencesDto>A list of all account preferences for a client. Returns:
AccountSettingsResponse- The populated response object.Behavior:
- Initializes an
AccountSettingsResponseand lists for profiles (AccountSettingsProfileAccountResponse) and accounts (AccountModel). - Identifies distinct
ProfileIdvalues fromclientAccounts. - For each
ProfileId:- Filters
clientAccountsfor the currentProfileId. - For each DTO in the filtered list, creates and populates an
AccountModel:AccountNumberfromdto.AccountNumberAccountNamefromdto.AccountNameAccountTypefromdto.AccountTypeProductSegmentfromdto.ProductSegmentBusinessUnitfromdto.BusinessUnitAccountHidden(boolean) fromdto.AccountHidden == 1(integer).
- Adds the
AccountModelto a temporary list for the current profile. - Creates an
AccountSettingsProfileAccountResponse, sets itsProfileId, and assigns the temporary account list toAccountList. - Adds this profile response to the main list of profiles.
- Filters
- Constructs the final
AccountSettingsResponse:GcnfromclientAccounts.First().GCN.BusinessUnitNamefromclientAccounts.First().BusinessUnit.ProfileAccountsassigned the main list of profiles.
- Initializes an
Critical Assumption: Assumes
clientAccountsis not empty when accessingclientAccounts.First(). An empty list will cause a runtime exception. It also assumes all DTOs share the same GCN and Business Unit.
Key Logic
- Data Transformation: Converts flat DTO lists to nested API response structures.
- Grouping: Organizes accounts under their respective
ProfileIds. - Type Conversion: Handles
AccountHiddenconversion (integer to boolean).
This mapper is vital for structuring API output according to the AccountSettingsResponse contract.