Skip to content

Commit

Permalink
feat(webserver): if no date provided for dashboard, then use default …
Browse files Browse the repository at this point in the history
…timewindow
  • Loading branch information
Skraye committed Jan 29, 2025
1 parent acdb46c commit efa2d44
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,23 @@ public PagedResults<Map<String, Object>> dashboardChart(
@Parameter(description = "The chart id") @PathVariable String chartId,
@Parameter(description = "The filters to apply, some can override chart definition like labels & namespace") @Body GlobalFilter globalFilter
) throws IOException {
ZonedDateTime startDate = globalFilter.getStartDate();
String tenantId = tenantService.resolveTenant();
Dashboard dashboard = dashboardRepository.get(tenantId, id).orElse(null);
if (dashboard == null) {
return null;
}

ZonedDateTime endDate = globalFilter.getEndDate();
ZonedDateTime startDate = globalFilter.getStartDate();
if (startDate == null || endDate == null) {
throw new IllegalArgumentException("`startDate` and `endDate` filters are required.");
endDate = ZonedDateTime.now();
startDate = endDate.minus(dashboard.getTimeWindow().getDefaultDuration());
}

if (endDate.isBefore(startDate)) {
throw new IllegalArgumentException("`endDate` must be after `startDate`.");
}

String tenantId = tenantService.resolveTenant();
Dashboard dashboard = dashboardRepository.get(tenantId, id).orElse(null);
if (dashboard == null) {
return null;
}

Duration windowDuration = Duration.ofSeconds(endDate.minus(Duration.ofSeconds(startDate.toEpochSecond())).toEpochSecond());
if (windowDuration.compareTo(dashboard.getTimeWindow().getMax()) > 0) {
throw new IllegalArgumentException("The queried window is larger than the max allowed one.");
Expand Down

0 comments on commit efa2d44

Please sign in to comment.