Skip to content

Commit d18d01b

Browse files
Added balance to GetMerchant response
1 parent 16f8110 commit d18d01b

4 files changed

Lines changed: 35 additions & 4 deletions

File tree

EstateManagement.DataTransferObjects/Responses/MerchantResponse.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ public class MerchantResponse
6767
/// </value>
6868
public List<MerchantOperatorResponse> Operators { get; set; }
6969

70+
/// <summary>
71+
/// Gets or sets the available balance.
72+
/// </summary>
73+
/// <value>
74+
/// The available balance.
75+
/// </value>
76+
public Decimal AvailableBalance { get; set; }
77+
78+
/// <summary>
79+
/// Gets or sets the balance.
80+
/// </summary>
81+
/// <value>
82+
/// The balance.
83+
/// </value>
84+
public Decimal Balance { get; set; }
85+
7086
#endregion
7187
}
7288
}

EstateManagement/Controllers/MerchantController.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,14 @@ public async Task<IActionResult> GetMerchant([FromRoute] Guid estateId, [FromRou
208208
throw new NotFoundException($"Merchant not found with estate Id {estateId} and merchant Id {merchantId}");
209209
}
210210

211-
return this.Ok(this.ModelFactory.ConvertFrom(merchant));
211+
MerchantBalance merchantBalance = await this.EstateManagementManager.GetMerchantBalance(estateId, merchantId, cancellationToken);
212+
213+
if (merchantBalance == null)
214+
{
215+
throw new NotFoundException($"Merchant Balance details not found with estate Id {estateId} and merchant Id {merchantId}");
216+
}
217+
218+
return this.Ok(this.ModelFactory.ConvertFrom(merchant, merchantBalance));
212219
}
213220

214221
/// <summary>

EstateManagement/Factories/IModelFactory.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ public interface IModelFactory
2323
/// Converts from.
2424
/// </summary>
2525
/// <param name="merchant">The merchant.</param>
26+
/// <param name="merchantBalance">The merchant balance.</param>
2627
/// <returns></returns>
27-
MerchantResponse ConvertFrom(Merchant merchant);
28+
MerchantResponse ConvertFrom(Merchant merchant, MerchantBalance merchantBalance = null);
2829

2930
/// <summary>
3031
/// Converts from.
3132
/// </summary>
32-
/// <param name="merchant">The merchant.</param>
33+
/// <param name="merchantBalance">The merchant balance.</param>
3334
/// <returns></returns>
3435
MerchantBalanceResponse ConvertFrom(MerchantBalance merchantBalance);
3536

EstateManagement/Factories/ModelFactory.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public EstateResponse ConvertFrom(Estate estate)
6363
/// </summary>
6464
/// <param name="merchant">The merchant.</param>
6565
/// <returns></returns>
66-
public MerchantResponse ConvertFrom(Merchant merchant)
66+
public MerchantResponse ConvertFrom(Merchant merchant, MerchantBalance merchantBalance = null)
6767
{
6868
if (merchant == null)
6969
{
@@ -131,6 +131,13 @@ public MerchantResponse ConvertFrom(Merchant merchant)
131131
}));
132132
}
133133

134+
// Only include the balance if the dto fed in is not null
135+
if (merchantBalance != null)
136+
{
137+
merchantResponse.AvailableBalance = merchantBalance.AvailableBalance;
138+
merchantResponse.Balance = merchantBalance.Balance;
139+
}
140+
134141
return merchantResponse;
135142
}
136143

0 commit comments

Comments
 (0)