diff --git a/app/Http/Controllers/V3/CMMSMachinesController.php b/app/Http/Controllers/V3/CMMSMachinesController.php index b25ca2a7..fcef7b57 100644 --- a/app/Http/Controllers/V3/CMMSMachinesController.php +++ b/app/Http/Controllers/V3/CMMSMachinesController.php @@ -8,6 +8,8 @@ use App\Http\Traits\ApiResponse; use App\Models\CMMSMachine; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Collection; +use Illuminate\Support\Facades\DB; class CMMSMachinesController extends Controller { @@ -39,4 +41,11 @@ class CMMSMachinesController extends Controller return $this->successResponse($matchedSearchedMachines); } + + public function carTypes(): Collection + { + return DB::table('cmms_machines') + ->distinct() + ->pluck('car_type'); + } } diff --git a/app/Services/FMS/GetErrorRateService.php b/app/Services/FMS/GetErrorRateService.php new file mode 100644 index 00000000..bcf02c4e --- /dev/null +++ b/app/Services/FMS/GetErrorRateService.php @@ -0,0 +1,71 @@ +url = config('fms_web_services.Vehicle_Activity.url'); + $this->password = config('fms_web_services.Vehicle_Activity.password'); + $this->username = config('fms_web_services.Vehicle_Activity.username'); + $this->channelName = 'fms_vehicle_activity'; + } + + public function setInputParameters(array $inputs): void + { + $this->inputParameters = $inputs; + } + + /** + * @throws Exception + */ + public function run(): array + { + try { + return $this->sendRequest(); + } + catch (Exception $e) { + Log::channel($this->channelName) + ->error(get_class($this), + [ + 'message' => $e->getMessage(), + ] + ); + + throw $e; + } + } + + public function sendRequest(): array + { + $inputData = $this->makeInputParameters(); + + return Http::withBody($inputData) + ->throw() + ->withoutVerifying() + ->post($this->url) + ->json(); + } + + private function makeInputParameters(): string + { + $inputData = $this->inputParameters + array( + "username" => $this->username, + "password" => $this->password, + "minStopDuration" => 1, + ); + + return json_encode($inputData); + } +} diff --git a/routes/v3.php b/routes/v3.php index 50eb8330..717202a6 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -180,6 +180,7 @@ Route::prefix('cmms_machines') Route::get('/', 'index')->name('index'); Route::get('/list', 'list')->name('list'); Route::get('/search', 'search')->name('search'); + Route::get('/car_types', 'carTypes')->name('carTypes'); }); Route::prefix('rahdaran')