Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,4 @@
</RequirePermission>
</div>
}
</div>

@code {
private bool isLoading = true;
private List<ContractModel>? contracts;

protected override async Task OnInitializedAsync()
{
try
{
await RequirePermission(PermissionSection.Contract, PermissionFunction.List);

var result = await Mediator.Send(new ContractQueries.GetContractsQuery(CorrelationIdHelper.New(), "stubbed-token", Guid.Parse("11111111-1111-1111-1111-111111111111")));
if (result.IsSuccess) {
contracts = ModelFactory.ConvertFrom(result.Data);
}
}
finally
{
isLoading = false;
}
}
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using EstateManagementUI.BlazorServer.Factories;
using EstateManagementUI.BlazorServer.Models;
using EstateManagementUI.BlazorServer.Permissions;
using EstateManagementUI.BusinessLogic.Requests;

namespace EstateManagementUI.BlazorServer.Components.Pages.Contracts
{
public partial class Index
{
private bool isLoading = true;
private List<ContractModel>? contracts;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
{
await base.OnAfterRenderAsync(firstRender);
return;
}

try
{
await RequirePermission(PermissionSection.Contract, PermissionFunction.List);
var estateId = await this.GetEstateId();
var result = await Mediator.Send(new ContractQueries.GetContractsQuery(CorrelationIdHelper.New(), estateId));
if (result.IsSuccess)
{
contracts = ModelFactory.ConvertFrom(result.Data);
}
}
finally
{
isLoading = false;
this.StateHasChanged();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
// Load filter options
var merchantsTask = Mediator.Send(new MerchantQueries.GetMerchantsForDropDownQuery(correlationId, estateId));
var operatorsTask = Mediator.Send(new OperatorQueries.GetOperatorsQuery(correlationId, estateId));
var contractsTask = Mediator.Send(new ContractQueries.GetContractsQuery(correlationId, accessToken, estateId));
var contractsTask = Mediator.Send(new ContractQueries.GetContractsQuery(correlationId, estateId));

await Task.WhenAll(merchantsTask, operatorsTask, contractsTask);

Expand Down
4 changes: 2 additions & 2 deletions EstateManagementUI.BlazorServer/Models/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public class ContractProductTransactionFeeModel
{
public Guid TransactionFeeId { get; set; }
public string? Description { get; set; }
public string? CalculationType { get; set; }
public string? FeeType { get; set; }
public Int32 CalculationType { get; set; }
public Int32 FeeType { get; set; }
public decimal Value { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using TransactionProcessor.DataTransferObjects.Responses.Contract;

namespace EstateManagementUI.BusinessLogic.BackendAPI.DataTransferObjects
{
Expand All @@ -9,7 +10,7 @@
[JsonProperty("date")]
public DateTime Date { get; set; }
[JsonProperty("description")]
public String Description { get; set; }

Check warning on line 13 in EstateManagmentUI.BusinessLogic/BackendAPI/DataTransferObjects/DataTransferObjects.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test

Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

public class MerchantKpi
Expand Down Expand Up @@ -100,9 +101,44 @@
[JsonProperty("operator_reporting_id")]
public Int32 OperatorReportingId { get; set; }

[JsonProperty("products")]
public List<ContractProduct> Products { get; set; }

#endregion
}

public class ContractProduct
{
[JsonProperty("contract_id")]
public Guid ContractId { get; set; }
[JsonProperty("product_id")]
public Guid ProductId { get; set; }
[JsonProperty("product_name")]
public String ProductName { get; set; }
[JsonProperty("display_text")]
public String DisplayText { get; set; }
[JsonProperty("product_type")]
public Int32 ProductType { get; set; }
[JsonProperty("value")]
public Decimal? Value { get; set; }
[JsonProperty("transaction_fees")]
public List<ContractProductTransactionFee> TransactionFees { get; set; }
}

public class ContractProductTransactionFee
{
[JsonProperty("transaction_fee_id")]
public Guid TransactionFeeId { get; set; }
[JsonProperty("description")]
public string? Description { get; set; }
[JsonProperty("calculation_type")]
public Int32 CalculationType { get; set; }
[JsonProperty("fee_type")]
public Int32 FeeType { get; set; }
[JsonProperty("value")]
public Decimal Value { get; set; }
}

public class Estate
{
[JsonProperty("estate_id")]
Expand Down Expand Up @@ -242,7 +278,7 @@
[JsonProperty("device_id")]
public Guid DeviceId { get; set; }
[JsonProperty("device_identifier")]
public String DeviceIdentifier { get; set; }

Check warning on line 281 in EstateManagmentUI.BusinessLogic/BackendAPI/DataTransferObjects/DataTransferObjects.cs

View workflow job for this annotation

GitHub Actions / Build and Unit Test

Non-nullable property 'DeviceIdentifier' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
[JsonProperty("is_deleted")]
public Boolean IsDeleted { get; set; }
}
Expand Down
46 changes: 46 additions & 0 deletions EstateManagmentUI.BusinessLogic/Client/APIModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using TransactionProcessor.DataTransferObjects.Responses.Contract;
using TransactionProcessor.DataTransferObjects.Responses.Estate;
using TransactionProcessor.DataTransferObjects.Responses.Merchant;
using ContractProductTransactionFee = EstateManagementUI.BusinessLogic.BackendAPI.DataTransferObjects.ContractProductTransactionFee;

namespace EstateManagementUI.BusinessLogic.Client;

Expand Down Expand Up @@ -323,4 +324,49 @@ public static List<ContractDropDownModel> ToContractDropDown(this List<Contract>

return contracts;
}

public static List<ContractModel> ToContract(this List<Contract> apiResultData)
{
List<ContractModel> contracts = new();

foreach (Contract contract in apiResultData)
{
var c = new ContractModel
{
ContractId = contract.ContractId,
Description = contract.Description,
OperatorName = contract.OperatorName,
OperatorId = contract.OperatorId,
Products = new List<ContractProductModel>()
};

foreach (var contractProduct in contract.Products) {
var cp = new ContractProductModel {
ProductType = ((ProductType)contractProduct.ProductType).ToString(),
Value = contractProduct.Value.HasValue ? contractProduct.Value.Value.ToString("F2") : "Variable",
DisplayText = contractProduct.DisplayText,
ProductName = contractProduct.ProductName,
ContractProductId = contractProduct.ProductId,
NumberOfFees = contractProduct.TransactionFees.Count,
TransactionFees = new List<ContractProductTransactionFeeModel>()
};

foreach (ContractProductTransactionFee contractProductTransactionFee in contractProduct.TransactionFees) {
cp.TransactionFees.Add(new ContractProductTransactionFeeModel {
Value = contractProductTransactionFee.Value,
Description = contractProductTransactionFee.Description,
CalculationType = contractProductTransactionFee.CalculationType,
FeeType = contractProductTransactionFee.FeeType,
TransactionFeeId = contractProductTransactionFee.TransactionFeeId
});
}

c.Products.Add(cp);
}

contracts.Add(c);
}

return contracts;
}
}
19 changes: 19 additions & 0 deletions EstateManagmentUI.BusinessLogic/Client/ContractMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Task<Result<List<RecentContractModel>>> GetRecentContracts(ContractQueries.GetRe

Task<Result<List<ContractDropDownModel>>> GetContracts(ContractQueries.GetContractsForDropDownQuery request,
CancellationToken cancellationToken);
Task<Result<List<ContractModel>>> GetContracts(ContractQueries.GetContractsQuery request,
CancellationToken cancellationToken);
}

public partial class ApiClient : IApiClient {
Expand Down Expand Up @@ -49,5 +51,22 @@ public async Task<Result<List<ContractDropDownModel>>> GetContracts(ContractQuer

return Result.Success(contractModels);
}

public async Task<Result<List<ContractModel>>> GetContracts(ContractQueries.GetContractsQuery request,
CancellationToken cancellationToken)
{
Result<String> token = await this.GetToken(cancellationToken);
if (token.IsFailed)
return ResultHelpers.CreateFailure(token);

Result<List<Contract>> apiResult = await this.EstateReportingApiClient.GetContracts(token.Data, request.EstateId, cancellationToken);

if (apiResult.IsFailed)
return ResultHelpers.CreateFailure(apiResult);

List<ContractModel> contractModels = apiResult.Data.ToContract();

return Result.Success(contractModels);
}
}
}
12 changes: 6 additions & 6 deletions EstateManagmentUI.BusinessLogic/Client/StubTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,16 @@ public static class StubTestData {
{
TransactionFeeId = Guid.Parse("66666666-6666-6666-6666-666666666666"),
Description = "Merchant Commission",
CalculationType = "Fixed",
FeeType = "Merchant",
CalculationType = 0,
FeeType = 0,
Value = 0.50m
},
new ContractProductTransactionFeeModel
{
TransactionFeeId = Guid.Parse("77777777-7777-7777-7777-777777777777"),
Description = "Service Provider Fee",
CalculationType = "Percentage",
FeeType = "Service Provider",
CalculationType = 1,
FeeType = 1,
Value = 2.5m
}
}
Expand All @@ -303,8 +303,8 @@ public static class StubTestData {
{
TransactionFeeId = Guid.Parse("99999999-9999-9999-9999-999999999999"),
Description = "Transaction Fee",
CalculationType = "Fixed",
FeeType = "Merchant",
CalculationType = 0,
FeeType = 0,
Value = 1.00m
}
}
Expand Down
4 changes: 2 additions & 2 deletions EstateManagmentUI.BusinessLogic/Models/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public class ContractProductTransactionFeeModel
{
public Guid TransactionFeeId { get; set; }
public string? Description { get; set; }
public string? CalculationType { get; set; }
public string? FeeType { get; set; }
public Int32 CalculationType { get; set; }
public Int32 FeeType { get; set; }
public decimal Value { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public ContractRequestHandler(IApiClient apiClient)

public async Task<Result<List<ContractModel>>> Handle(ContractQueries.GetContractsQuery request,
CancellationToken cancellationToken) {
return Result.Success(StubTestData.GetMockContracts());
return await this.ApiClient.GetContracts(request, cancellationToken);
}

public async Task<Result<ContractModel>> Handle(ContractQueries.GetContractQuery request,
Expand Down
2 changes: 1 addition & 1 deletion EstateManagmentUI.BusinessLogic/Requests/Requests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public record GetAssignedOperatorsQuery(CorrelationId CorrelationId, Guid Estate
public static class ContractQueries {
public record GetRecentContractsQuery(CorrelationId CorrelationId, Guid EstateId) : IRequest<Result<List<RecentContractModel>>>;
public record GetContractsForDropDownQuery(CorrelationId CorrelationId, Guid EstateId) : IRequest<Result<List<ContractDropDownModel>>>;
public record GetContractsQuery(CorrelationId CorrelationId, string AccessToken, Guid EstateId) : IRequest<Result<List<ContractModel>>>;
public record GetContractsQuery(CorrelationId CorrelationId, Guid EstateId) : IRequest<Result<List<ContractModel>>>;
public record GetContractQuery(CorrelationId CorrelationId, string AccessToken, Guid EstateId, Guid ContractId) : IRequest<Result<ContractModel>>;
}

Expand Down
8 changes: 4 additions & 4 deletions EstateManagmentUI.BusinessLogic/Services/TestDataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,16 @@ private void InitializeDefaultData()
{
TransactionFeeId = Guid.Parse("66666666-6666-6666-6666-666666666666"),
Description = "Merchant Commission",
CalculationType = "Fixed",
FeeType = "Merchant",
CalculationType = 0,
FeeType = 0,
Value = 0.50m
},
new ContractProductTransactionFeeModel
{
TransactionFeeId = Guid.Parse("77777777-7777-7777-7777-777777777777"),
Description = "Service Provider Fee",
CalculationType = "Percentage",
FeeType = "Service Provider",
CalculationType = 1,
FeeType = 1,
Value = 2.5m
}
}
Expand Down
Loading