Add generateCombinedReport Method and Rename Existing Method

This commit introduces two major updates to the BenchmarkService class:

1. Renamed the `generateReport` method to `generateSingleReport` for better clarity and specificity.

2. Added a new method called `generateCombinedReport` that takes a list of test run IDs and generates a combined report by posting to the `/reports/query` endpoint.

These changes aim to improve the modularity and readability of the code, while also extending its functionality to handle combined reports.
This commit is contained in:
hunteraraujo
2023-09-18 17:15:44 -07:00
parent da9fd926c8
commit 0e069c2679

View File

@@ -8,28 +8,30 @@ class BenchmarkService {
BenchmarkService(this.api); BenchmarkService(this.api);
/// Generates a report using POST REST API at the /reports URL. /// Generates a single report using POST REST API at the /reports URL.
/// ///
/// [reportRequestBody] is a Map representing the request body for generating a report. /// [reportRequestBody] is a Map representing the request body for generating a single report.
Future<Map<String, dynamic>> generateReport( Future<Map<String, dynamic>> generateSingleReport(
ReportRequestBody reportRequestBody) async { ReportRequestBody reportRequestBody) async {
try { try {
return await api.post('reports', reportRequestBody.toJson(), return await api.post('reports', reportRequestBody.toJson(),
apiType: ApiType.benchmark); apiType: ApiType.benchmark);
} catch (e) { } catch (e) {
throw Exception('Failed to generate report: $e'); throw Exception('Failed to generate single report: $e');
} }
} }
/// Polls for updates using the GET REST API at the /updates?last_update_time=TIMESTAMP URL. /// Generates a combined report using POST REST API at the /reports/query URL.
/// ///
/// [lastUpdateTime] is the UNIX UTC timestamp for last update time. /// [testRunIds] is a list of strings representing the test run IDs to be combined into a single report.
Future<Map<String, dynamic>> pollUpdates(int lastUpdateTime) async { Future<Map<String, dynamic>> generateCombinedReport(
List<String> testRunIds) async {
try { try {
return await api.get('updates?last_update_time=$lastUpdateTime', final Map<String, dynamic> requestBody = {'test_run_ids': testRunIds};
return await api.post('reports/query', requestBody,
apiType: ApiType.benchmark); apiType: ApiType.benchmark);
} catch (e) { } catch (e) {
throw Exception('Failed to poll updates: $e'); throw Exception('Failed to generate combined report: $e');
} }
} }
} }