Skip to content

Commit

Permalink
Merge pull request #21 from IliyanIlievPH/20
Browse files Browse the repository at this point in the history
Closes #20
  • Loading branch information
starkmsu committed Jun 10, 2020
2 parents 14e1a57 + 4310f61 commit 7ee7f88
Show file tree
Hide file tree
Showing 55 changed files with 2,635 additions and 210 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JetBrains.Annotations;
using MAVN.Service.OperationsHistory.Client.Models.Requests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,10 @@ public class PaginatedCustomerOperationsResponse : BasePagedResponse
/// List of smart voucher uses.
/// </summary>
public IEnumerable<SmartVoucherUseResponse> SmartVoucherUses { get; set; }

/// <summary>
/// List of smart voucher transfers.
/// </summary>
public IEnumerable<SmartVoucherTransferResponse> SmartVoucherTransfers { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using MAVN.Numerics;

namespace MAVN.Service.OperationsHistory.Client.Models.Responses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SmartVoucherPaymentResponse
/// <summary>
/// The id of the campaign
/// </summary>
public Guid CampaignId { get; set; }
public string CampaignId { get; set; }
/// <summary>
/// The id of the customer
/// </summary>
Expand All @@ -41,5 +41,17 @@ public class SmartVoucherPaymentResponse
/// Timestamp of the payment
/// </summary>
public DateTime Timestamp { get; set; }
/// <summary>
/// Name of the campaign
/// </summary>
public string CampaignName { get; set; }
/// <summary>
/// Name of the partner
/// </summary>
public string PartnerName { get; set; }
/// <summary>
/// Vertical of the partner
/// </summary>
public string Vertical { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;

namespace MAVN.Service.OperationsHistory.Client.Models.Responses
{
/// <summary>
/// Response model for smart voucher transfer
/// </summary>
public class SmartVoucherTransferResponse
{
/// <summary>
/// Id of the operation
/// </summary>
public string Id { get; set; }
/// <summary>
/// Timestamp
/// </summary>
public DateTime Timestamp { get; set; }
/// <summary>
/// Id of the old owner
/// </summary>
public Guid OldCustomerId { get; set; }
/// <summary>
/// Id of the new owner
/// </summary>
public Guid NewCustomerId { get; set; }
/// <summary>
/// Id of the partner
/// </summary>
public Guid PartnerId { get; set; }
/// <summary>
/// Id of the campaign
/// </summary>
public string CampaignId { get; set; }
/// <summary>
/// Short code of the voucher
/// </summary>
public string ShortCode { get; set; }
/// <summary>
/// Price of the voucher
/// </summary>
public decimal Amount { get; set; }
/// <summary>
/// Asset symbol of the currency
/// </summary>
public string AssetSymbol { get; set; }
/// <summary>
/// Name of the campaign
/// </summary>
public string CampaignName { get; set; }
/// <summary>
/// Name of the partner
/// </summary>
public string PartnerName { get; set; }
/// <summary>
/// Vertical of the partner
/// </summary>
public string Vertical { get; set; }
/// <summary>
/// Email of the receiver
/// </summary>
public string OldCustomerEmail { get; set; }
/// <summary>
/// Email of the receiver
/// </summary>
public string NewCustomerEmail { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SmartVoucherUseResponse
/// <summary>
/// Id of the campaign
/// </summary>
public Guid CampaignId { get; set; }
public string CampaignId { get; set; }
/// <summary>
/// amount of the voucher
/// </summary>
Expand All @@ -43,5 +43,17 @@ public class SmartVoucherUseResponse
/// Asset symbol (currency)
/// </summary>
public string AssetSymbol { get; set; }
/// <summary>
/// Name of the campaign
/// </summary>
public string CampaignName { get; set; }
/// <summary>
/// Name of the partner
/// </summary>
public string PartnerName { get; set; }
/// <summary>
/// Vertical of the partner
/// </summary>
public string Vertical { get; set; }
}
}
3 changes: 3 additions & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ PartnerManagementService:
CustomerProfileService:
ServiceUrl :
settings-key: CustomerProfileServiceUrl
SmartVouchersService:
ServiceUrl :
settings-key: SmartVouchersServiceUrl
SlackNotifications:
AzureQueue:
ConnectionString:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using MAVN.Numerics;

namespace MAVN.Service.OperationsHistory.Domain.Models
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using MAVN.Numerics;

namespace MAVN.Service.OperationsHistory.Domain.Models
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public enum OperationType
VoucherPurchasePayment,
SmartVoucherPayment,
SmartVoucherUse,
SmartVoucherTransfer,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public class PaginatedCustomerOperationsModel : BasePagedModel

public IEnumerable<VoucherPurchasePaymentDto> VoucherPurchasePayments { get; set; }

public IEnumerable<ISmartVoucherPayment> SmartVoucherPayments { get; set; }
public IEnumerable<SmartVoucherPaymentDto> SmartVoucherPayments { get; set; }

public IEnumerable<ISmartVoucherUse> SmartVoucherUses { get; set; }
public IEnumerable<SmartVoucherUseDto> SmartVoucherUses { get; set; }
public IEnumerable<SmartVoucherTransferDto> SmartVoucherTransfers { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace MAVN.Service.OperationsHistory.Domain.Models
{
public class PaginatedSmartVoucherPaymentsHistory : BasePagedModel
{
public IEnumerable<ISmartVoucherPayment> SmartVoucherPaymentsHistory { get; set; }
public IEnumerable<SmartVoucherPaymentDto> SmartVoucherPaymentsHistory { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using MAVN.Numerics;

namespace MAVN.Service.OperationsHistory.Domain.Models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace MAVN.Service.OperationsHistory.Domain.Models
{
public class SmartVoucherPaymentDto : ISmartVoucherPayment
public class SmartVoucherPaymentDto
{
public string PaymentRequestId { get; set; }
public string ShortCode { get; set; }
public Guid CustomerId { get; set; }
public Guid PartnerId { get; set; }
public Guid CampaignId { get; set; }
public string CampaignId { get; set; }
public string CampaignName { get; set; }
public string PartnerName { get; set; }
public string Vertical { get; set; }
public decimal Amount { get; set; }
public string AssetSymbol { get; set; }
public DateTime Timestamp { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace MAVN.Service.OperationsHistory.Domain.Models
{
public class SmartVoucherTransferDto
{
public string Id { get; set; }
public DateTime Timestamp { get; set; }
public Guid OldCustomerId { get; set; }
public Guid NewCustomerId { get; set; }
public Guid PartnerId { get; set; }
public string CampaignId { get; set; }
public string ShortCode { get; set; }
public decimal Amount { get; set; }
public string AssetSymbol { get; set; }
public string CampaignName { get; set; }
public string PartnerName { get; set; }
public string Vertical { get; set; }
public string NewCustomerEmail { get; set; }
public string OldCustomerEmail { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

namespace MAVN.Service.OperationsHistory.Domain.Models
{
public class SmartVoucherUseDto : ISmartVoucherUse
public class SmartVoucherUseDto
{
public string Id { get; set; }
public DateTime Timestamp { get; set; }
public Guid CustomerId { get; set; }
public Guid? LinkedCustomerId { get; set; }
public Guid PartnerId { get; set; }
public Guid? LocationId { get; set; }
public Guid CampaignId { get; set; }
public string CampaignId { get; set; }
public decimal Amount { get; set; }
public string AssetSymbol { get; set; }
public string CampaignName { get; set; }
public string PartnerName { get; set; }
public string Vertical { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace MAVN.Service.OperationsHistory.Domain.Repositories
{
public interface ISmartVoucherRepository
{
Task AddPaymentAsync(ISmartVoucherPayment payment);
Task AddUseAsync(ISmartVoucherUse smartVoucher);
Task AddPaymentAsync(SmartVoucherPaymentDto payment);
Task AddUseAsync(SmartVoucherUseDto smartVoucher);
Task AddTransferAsync(SmartVoucherTransferDto smartVoucher);

Task<PaginatedSmartVoucherPaymentsHistory> GetByDatesPaginatedAsync(
DateTime dateFrom,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MAVN.Service.OperationsHistory.Domain.Models;
using MAVN.Service.OperationsHistory.Domain.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,5 @@ public interface IOperationsService
Task ProcessWalletLinkingStateChangeCompletedEventAsync(LinkWalletOperationDto linkWalletOperation);

Task ProcessVoucherTokensUsedEventAsync(VoucherPurchasePaymentDto voucherPurchasePaymentOperation);

Task ProcessSmartVoucherSoldEventAsync(SmartVoucherPaymentDto smartVoucherPayment);

Task ProcessSmartVoucherUsedEventAsync(SmartVoucherUseDto smartVoucherUse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;
using MAVN.Service.OperationsHistory.Domain.Models;

namespace MAVN.Service.OperationsHistory.Domain.Services
{
public interface ISmartVoucherOperationsService
{
Task ProcessSmartVoucherSoldEventAsync(SmartVoucherPaymentDto smartVoucherPayment);
Task ProcessSmartVoucherUsedEventAsync(SmartVoucherUseDto smartVoucherUse);
Task ProcessSmartVoucherTransferredEventAsync(SmartVoucherTransferDto smartVoucherTransfer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageReference Include="MAVN.Service.PaymentManagement.Contract" Version="1.18.0" />
<PackageReference Include="MAVN.Service.PrivateBlockchainFacade.Client" Version="1.1.0" />
<PackageReference Include="MAVN.Service.PrivateBlockchainFacade.Contract" Version="1.1.0" />
<PackageReference Include="MAVN.Service.SmartVouchers.Client" Version="2.12.1" />
<PackageReference Include="MAVN.Service.SmartVouchers.Contract" Version="2.12.0" />
<PackageReference Include="MAVN.Service.Staking.Contract" Version="1.1.1" />
<PackageReference Include="MAVN.Service.Tiers.Contract" Version="1.1.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public async Task<PaginatedCustomerOperationsModel> GetByCustomerIdPaginatedAsyn
var result = await _transactionHistoryRepository.GetByCustomerIdPaginatedAsync(customerId, skip, take);

await SetCustomersEmails(result.Transfers);
await SetCustomersEmails(result.SmartVoucherTransfers);

return result;
}
Expand Down Expand Up @@ -159,6 +160,39 @@ private async Task SetCustomersEmails(IEnumerable<Transfer> transfers)
}
}

private async Task SetCustomersEmails(IEnumerable<SmartVoucherTransferDto> transfers)
{
var customerIds = new HashSet<string>();

foreach (var transfer in transfers)
{
customerIds.Add(transfer.OldCustomerId.ToString());
customerIds.Add(transfer.NewCustomerId.ToString());
}

var customerProfiles = await _customerProfileClient.CustomerProfiles.GetByIdsAsync(
customerIds.ToArray(),
includeNotVerified: true,
includeNotActive: true);

var customerEmails = customerProfiles.ToDictionary(x => x.CustomerId, x => x.Email);

foreach (var transfer in transfers)
{
var senderCustomerExists = customerEmails.TryGetValue(transfer.OldCustomerId.ToString(), out var senderEmail);
var receiverCustomerExists = customerEmails.TryGetValue(transfer.NewCustomerId.ToString(), out var receiverEmail);

if (!senderCustomerExists)
_log.Error(message: "Sender customer does not exist for already processed Smart Voucher Transfer", context: transfer.OldCustomerId);

if (!receiverCustomerExists)
_log.Error(message: "Receiver customer does not exist for already processed Smart VoucherTransfer", context: transfer.NewCustomerId);

transfer.OldCustomerEmail = senderEmail;
transfer.NewCustomerEmail = receiverEmail;
}
}

private (int skip, int take) ValidateAndCalculateSkipAndTake(int currentPage, int pageSize)
{
if (currentPage < 1)
Expand Down
Loading

0 comments on commit 7ee7f88

Please sign in to comment.