Commit 7dff14cf4c994598ad1bb0f6a12c87d19cf1cd97
1 parent
a6a20feca3
Exists in
master
and in
4 other branches
Change OD, MLTD event api endpoints to plain counts within timeframe
Showing 3 changed files with 39 additions and 8 deletions
api/app/Http/Controllers/V1/Components/MltdController.php
View file @
7dff14c
... | ... | @@ -80,12 +80,26 @@ |
80 | 80 | ]; |
81 | 81 | } |
82 | 82 | |
83 | - public function last(Request $request, $x) | |
83 | + public function count(Request $request) | |
84 | 84 | { |
85 | - if (!Schema::hasTable('mltd')) { | |
86 | - return []; | |
85 | + if ($request->has('start')) { | |
86 | + $start = Carbon::parse($request->get('start')); | |
87 | + } else { | |
88 | + $start = Carbon::now()->subHour(); | |
87 | 89 | } |
88 | - return DB::table('mltd')->orderBy('created_on', 'desc')->limit($x)->get()->toArray(); | |
90 | + | |
91 | + if ($request->has('end')) | |
92 | + $end = Carbon::parse($request->get('end')); | |
93 | + else { | |
94 | + $end = Carbon::now(); | |
95 | + } | |
96 | + | |
97 | + return [ | |
98 | + 'count' => | |
99 | + DB::table('mltd') | |
100 | + ->whereBetween('created_on', [$start, $end]) | |
101 | + ->count() | |
102 | + ]; | |
89 | 103 | } |
90 | 104 | } |
api/app/Http/Controllers/V1/Components/OdController.php
View file @
7dff14c
... | ... | @@ -83,9 +83,26 @@ |
83 | 83 | return $response; |
84 | 84 | } |
85 | 85 | |
86 | - public function last(Request $request, $x) | |
86 | + public function count(Request $request) | |
87 | 87 | { |
88 | - return DB::table('od')->orderBy('created_on', 'desc')->limit($x)->get()->toArray(); | |
88 | + if ($request->has('start')) { | |
89 | + $start = Carbon::parse($request->get('start')); | |
90 | + } else { | |
91 | + $start = Carbon::now()->subHour(); | |
92 | + } | |
93 | + | |
94 | + if ($request->has('end')) | |
95 | + $end = Carbon::parse($request->get('end')); | |
96 | + else { | |
97 | + $end = Carbon::now(); | |
98 | + } | |
99 | + | |
100 | + return [ | |
101 | + 'count' => | |
102 | + DB::table('od') | |
103 | + ->whereBetween('incident_date', [$start, $end]) | |
104 | + ->count() | |
105 | + ]; | |
89 | 106 | } |
90 | 107 | } |
api/routes/api.php
View file @
7dff14c
... | ... | @@ -32,14 +32,14 @@ |
32 | 32 | Route::get('status', 'V1\Components\MltdController@status'); |
33 | 33 | Route::get('stop/{pid}', 'V1\Components\MltdController@stop'); |
34 | 34 | Route::get('{train_id}/{top}', 'V1\Components\MltdController@train'); |
35 | - Route::get('events/last/{x}','V1\Components\MltdController@last'); | |
35 | + Route::get('events/count','V1\Components\MltdController@count'); | |
36 | 36 | }); |
37 | 37 | Route::group(['prefix' => 'od'], function () { |
38 | 38 | Route::get('start', 'V1\Components\OdController@start'); |
39 | 39 | Route::get('status', 'V1\Components\OdController@status'); |
40 | 40 | Route::get('stop/{pid}', 'V1\Components\OdController@stop'); |
41 | 41 | Route::post('analyze/{pid}', 'V1\Components\OdController@analyze'); |
42 | - Route::get('events/last/{x}','V1\Components\OdController@last'); | |
42 | + Route::get('events/count','V1\Components\OdController@count'); | |
43 | 43 | }); |
44 | 44 | }); |
45 | 45 |