51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\LinkConverterService;
|
|
use App\Services\HistoryService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ConvertApiController extends Controller
|
|
{
|
|
protected LinkConverterService $linkConverterService;
|
|
protected HistoryService $historyService;
|
|
|
|
public function __construct(LinkConverterService $linkConverterService, HistoryService $historyService)
|
|
{
|
|
$this->linkConverterService = $linkConverterService;
|
|
$this->historyService = $historyService;
|
|
}
|
|
|
|
public function convert(Request $request)
|
|
{
|
|
$request->validate([
|
|
'url' => 'required|url',
|
|
]);
|
|
|
|
$result = $this->linkConverterService->process($request->input('url'));
|
|
|
|
if ($result->isSuccess) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $result,
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => $result->errorMessage,
|
|
'data' => $result,
|
|
], 400);
|
|
}
|
|
|
|
public function history()
|
|
{
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $this->historyService->getPaginated(20),
|
|
]);
|
|
}
|
|
}
|