Skip to content

Commit 52b6d80

Browse files
committed
PM-34686 initial commmit
1 parent eb3700a commit 52b6d80

3 files changed

Lines changed: 9 additions & 35 deletions

File tree

src/Api/Dirt/Controllers/OrganizationReportsController.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,13 @@ public async Task<IActionResult> UpdateOrganizationReportAsync(Guid organization
132132
# region SummaryData Field Endpoints
133133

134134
/// <summary>
135-
/// Gets summary data for organization reports within a specified date range.
136-
/// The response is optimized for widget display by returning up to 6 entries that are
137-
/// evenly spaced across the date range, including the most recent entry.
138-
/// This allows the widget to show trends over time while ensuring the latest data point is always included.
135+
/// Gets summary data for organization reports within a specified date range.
136+
/// Returns all report summary entries within the range.
139137
/// </summary>
140-
/// <param name="organizationId"></param>
141-
/// <param name="startDate"></param>
142-
/// <param name="endDate"></param>
143-
/// <returns></returns>
138+
/// <param name="organizationId">The unique identifier of the organization.</param>
139+
/// <param name="startDate">The start of the date range to query.</param>
140+
/// <param name="endDate">The end of the date range to query.</param>
141+
/// <returns>A collection of summary data entries within the date range.</returns>
144142
/// <exception cref="NotFoundException"></exception>
145143
/// <exception cref="BadRequestException"></exception>
146144
[HttpGet("{organizationId}/data/summary")]

src/Core/Dirt/Reports/ReportFeatures/GetOrganizationReportSummaryDataByDateRangeQuery.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace Bit.Core.Dirt.Reports.ReportFeatures;
1111

1212
public class GetOrganizationReportSummaryDataByDateRangeQuery : IGetOrganizationReportSummaryDataByDateRangeQuery
1313
{
14-
private const int MaxRecordsForWidget = 6;
1514
private readonly IOrganizationReportRepository _organizationReportRepo;
1615
private readonly ILogger<GetOrganizationReportSummaryDataByDateRangeQuery> _logger;
1716
private readonly IFusionCache _cache;
@@ -53,7 +52,7 @@ public async Task<IEnumerable<OrganizationReportSummaryDataResponse>> GetOrganiz
5352
factory: async _ =>
5453
{
5554
var data = await _organizationReportRepo.GetSummaryDataByDateRangeAsync(organizationId, startDate, endDate);
56-
return GetMostRecentEntries(data);
55+
return data;
5756
},
5857
options: new FusionCacheEntryOptions(duration: OrganizationReportCacheConstants.DurationForSummaryData),
5958
tags: [cacheTag]
@@ -98,27 +97,4 @@ private static (bool IsValid, string errorMessage) ValidateRequest(Guid organiza
9897

9998
return (true, string.Empty);
10099
}
101-
102-
private static IEnumerable<OrganizationReportSummaryDataResponse> GetMostRecentEntries(IEnumerable<OrganizationReportSummaryDataResponse> data, int maxEntries = MaxRecordsForWidget)
103-
{
104-
if (data.Count() <= maxEntries)
105-
{
106-
return data;
107-
}
108-
109-
// here we need to take 10 records, evenly spaced by RevisionDate,
110-
// to cover the entire date range,
111-
// and ensure we include the most recent record as well
112-
var sortedData = data.OrderByDescending(d => d.RevisionDate).ToList();
113-
var totalRecords = sortedData.Count;
114-
var interval = (double)(totalRecords - 1) / (maxEntries - 1); // -1 the most recent record will be included by default
115-
var result = new List<OrganizationReportSummaryDataResponse>();
116-
117-
for (int i = 0; i <= maxEntries - 1; i++)
118-
{
119-
result.Add(sortedData[(int)Math.Round(i * interval)]);
120-
}
121-
122-
return result;
123-
}
124100
}

test/Core.Test/Dirt/ReportFeatures/GetOrganizationReportSummaryDataByDateRangeQueryTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ await sutProvider.GetDependency<IOrganizationReportRepository>()
6262

6363
[Theory]
6464
[BitAutoData]
65-
public async Task GetOrganizationReportSummaryDataByDateRangeAsync_ShouldReturnTopSixResults(
65+
public async Task GetOrganizationReportSummaryDataByDateRangeAsync_ShouldReturnAllResults(
6666
SutProvider<GetOrganizationReportSummaryDataByDateRangeQuery> sutProvider)
6767
{
6868
// Arrange
@@ -110,7 +110,7 @@ public async Task GetOrganizationReportSummaryDataByDateRangeAsync_ShouldReturnT
110110

111111
// Assert
112112
Assert.NotNull(result);
113-
Assert.Equal(6, result.Count());
113+
Assert.Equal(12, result.Count());
114114
await sutProvider.GetDependency<IOrganizationReportRepository>()
115115
.Received(1).GetSummaryDataByDateRangeAsync(Arg.Any<Guid>(), Arg.Any<DateTime>(), Arg.Any<DateTime>());
116116
}

0 commit comments

Comments
 (0)