Skip to content

Commit

Permalink
Merge pull request #23 from IliyanIlievPH/master
Browse files Browse the repository at this point in the history
Do not filter by partnerIds if array is null or empty
  • Loading branch information
starkmsu committed Jun 25, 2020
2 parents 77e6de7 + 522b6c1 commit 92feae0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public interface ISmartVouchersApi
/// <summary>
/// Get total voucher operations statistics per Partner
/// </summary>
/// <param name="partnerIds"></param>
/// <param name="request"></param>
/// <returns></returns>
[Post("/api/smartvouchers/totals")]
Task<IList<VoucherStatisticsResponse>> GetTotalStatisticsAsync([Body] Guid[] partnerIds);
Task<IList<VoucherStatisticsResponse>> GetTotalStatisticsAsync([Body] VoucherStatisticsRequest request);

/// <summary>
/// Get daily voucher statistics
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace MAVN.Service.DashboardStatistics.Client.Models.VoucherStatistic
{
/// <summary>
/// Request to get voucher statistics
/// </summary>
public class VoucherStatisticsRequest
{
/// <summary>
/// Collection of partner ids
/// </summary>
public Guid[] PartnerIds { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class VouchersDailyStatisticsRequest : BasePeriodRequestModel
/// <summary>
/// Collection of partner ids
/// </summary>
[Required]
public Guid[] PartnerIds { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ public async Task<IReadOnlyList<IPartnerVouchersDailyStats>> GetByPartnerIdsAndP
{
using (var context = _contextFactory.CreateDataContext())
{
var result = await context.PartnerVouchersDailyStatistics
.Where(x => partnerIds.Contains(x.PartnerId) && x.Date >= fromDate.Date && x.Date <= toDate.Date)
.ToListAsync();
var query = context.PartnerVouchersDailyStatistics
.Where(x => x.Date >= fromDate.Date && x.Date <= toDate.Date);

if (partnerIds != null && partnerIds.Any())
query = query.Where(x => partnerIds.Contains(x.PartnerId));

var result = await query.ToListAsync();
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ public async Task<IList<VoucherOperationsStatistic>> GetByPartnerIds(Guid[] part
{
using (var context = _contextFactory.CreateDataContext())
{
var entities = await context.VoucherOperationsStatistics
.Where(x => partnerIds.Contains(x.Id))
var query = context.VoucherOperationsStatistics.AsQueryable();

if (partnerIds != null && partnerIds.Any())
query = query.Where(x => partnerIds.Contains(x.PartnerId));

var result = await query
.Select(x => _mapper.Map<VoucherOperationsStatistic>(x))
.ToListAsync();

return entities.Select(x => _mapper.Map<VoucherOperationsStatistic>(x)).ToList();
return result;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
Expand Down Expand Up @@ -29,9 +27,9 @@ public class SmartVouchersController : Controller, ISmartVouchersApi
[HttpPost]
[Route("totals")]
[ProducesResponseType(typeof(IList<VoucherStatisticsResponse>), (int)HttpStatusCode.OK)]
public async Task<IList<VoucherStatisticsResponse>> GetTotalStatisticsAsync([FromBody][Required] Guid[] partnerIds)
public async Task<IList<VoucherStatisticsResponse>> GetTotalStatisticsAsync([FromBody] VoucherStatisticsRequest request)
{
var currenciesStatistic = await _partnerStatisticService.GetCurrenciesStatistic(partnerIds);
var currenciesStatistic = await _partnerStatisticService.GetCurrenciesStatistic(request.PartnerIds);

return currenciesStatistic.Select(x => _mapper.Map<VoucherStatisticsResponse>(x)).ToList();
}
Expand Down

0 comments on commit 92feae0

Please sign in to comment.