Skip to content

Commit b01bae8

Browse files
committed
- Added support for Scribe API docs
1 parent 2f6f509 commit b01bae8

2 files changed

Lines changed: 62 additions & 4 deletions

File tree

src/Http/Controllers/Api/TimeSeriesStatsApiController.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
use Javaabu\Stats\Support\ExactDateRange;
1010
use Javaabu\Stats\TimeSeriesStats;
1111

12+
/**
13+
* @group Stats
14+
*
15+
* Endpoints for generating statistics.
16+
*/
1217
class TimeSeriesStatsApiController extends Controller
1318
{
1419
/**
15-
* Display a listing of the resource.
20+
* Time series stats
1621
*
17-
* @param TimeSeriesStatsRequest $request
18-
* @return JsonResponse|Response
22+
* Generate time series stats for given the metric in the given date range and comparison date range. Supports outputs in multiple formats.
1923
*/
2024
public function index(TimeSeriesStatsRequest $request)
2125
{

src/Http/Requests/TimeSeriesStatsRequest.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function authorize()
2727
*/
2828
public function rules()
2929
{
30-
$user = $this->user();
30+
$user = request()->user();
3131
$filters = $this->input('filters', []);
3232

3333
$rules = [
@@ -96,4 +96,58 @@ public function rules()
9696

9797
return $rules;
9898
}
99+
100+
public function bodyParameters()
101+
{
102+
return [
103+
'mode' => [
104+
'description' => 'Which date frequency to group the data by, like `hour`, `day`, etc.',
105+
'example' => TimeSeriesModes::MONTH->value,
106+
],
107+
108+
'metric' => [
109+
'description' => 'Which metric to use for the stat.',
110+
'example' => TimeSeriesStats::allowedMetrics([], request()->user())[0] ?? '',
111+
],
112+
113+
'date_range' => [
114+
'description' => 'Preset date range to filter results by.',
115+
'example' => PresetDateRanges::THIS_YEAR->value,
116+
],
117+
118+
'date_from' => [
119+
'description' => 'Custom starting date when not using a preset date range.',
120+
],
121+
122+
'date_to' => [
123+
'description' => 'Custom ending date when not using a preset date range.',
124+
],
125+
126+
'compare' => [
127+
'description' => 'Whether to compare the stat with the comparison date range.',
128+
'example' => true,
129+
],
130+
131+
'compare_date_range' => [
132+
'description' => 'Preset date range to compare results with. If not set, the previous date range will be compared.',
133+
'example' => 'No-example'
134+
],
135+
136+
'compare_date_from' => [
137+
'description' => 'Custom starting compare date when not using a preset compare date range.',
138+
],
139+
140+
'compare_date_to' => [
141+
'description' => 'Custom ending compare date when not using a preset compare date range.',
142+
],
143+
144+
'format' => [
145+
'description' => 'Which format to return the results in.',
146+
],
147+
148+
'filters' => [
149+
'description' => 'Filters to apply to the stat.',
150+
],
151+
];
152+
}
99153
}

0 commit comments

Comments
 (0)