Compare commits

...

3 commits

Author SHA1 Message Date
Jabir
ab514bfcf5 wip 2023-11-03 12:01:21 +01:00
Jabir
a6f2a4fac7 first prototype sending api request 2023-11-03 11:58:43 +01:00
Jabir
900ffdb56f WIP 2023-11-03 11:49:11 +01:00
2 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers\Api\Printer;
use App\Http\Resources\Printer\ListPrinterResource;
use App\Models\Printer;
use App\Http\Responses\ApiResponse;
use Illuminate\Support\Facades\Http;
class ClearQueuePrinterController
{
public function __invoke(string $id)
{
//todo fetch printer from request instead of doing it on controller
$printer = Printer::find($id);
//todo validate from rquest class
$data = request()->input('params');
$baseUrl = 'http://' .$printer->config->networkFormat();
//todo create service class to send requests
$httpClient = Http::withHeaders([
// 'Accept-Language' => $integrationProfile->api_credentials['language'],
// 'Authorization' => $authToken,
]);
$url = $baseUrl . '/server/job_queue/job';
$query = [];
$method = 'delete';
$response = $httpClient->{$method}($url, $method === 'get' ? $query : $data);
dd($response);
return ApiResponse::handle();
}
}

View file

@ -1,5 +1,6 @@
<?php <?php
use App\Http\Controllers\Api\Printer\ClearQueuePrinterController;
use App\Http\Controllers\Api\Printer\GetPrinterController; use App\Http\Controllers\Api\Printer\GetPrinterController;
use App\Http\Controllers\Api\Printer\ListPrinterController; use App\Http\Controllers\Api\Printer\ListPrinterController;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -22,3 +23,4 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
Route::get('/printers', ListPrinterController::class); Route::get('/printers', ListPrinterController::class);
Route::get('/printers/{id}', GetPrinterController::class); Route::get('/printers/{id}', GetPrinterController::class);
Route::post('/printers/{id}/clear-queue', ClearQueuePrinterController::class);