113 lines
2.6 KiB
PHP
113 lines
2.6 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Http\Controllers\Api;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Http\Resources\JobCollection;
|
||
|
|
use App\Http\Resources\JobResource;
|
||
|
|
use App\Models\Job;
|
||
|
|
use App\Services\JobSearchService;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class JobController extends Controller
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
private JobSearchService $searchService
|
||
|
|
) {}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display a listing of jobs with filtering and search
|
||
|
|
*/
|
||
|
|
public function index(Request $request)
|
||
|
|
{
|
||
|
|
$filters = $request->only([
|
||
|
|
'keywords',
|
||
|
|
'search',
|
||
|
|
'location',
|
||
|
|
'category_id',
|
||
|
|
'job_type',
|
||
|
|
'experience_level',
|
||
|
|
'remote',
|
||
|
|
'salary_min',
|
||
|
|
'salary_max',
|
||
|
|
'posted_within',
|
||
|
|
'source_id',
|
||
|
|
'company',
|
||
|
|
'sort',
|
||
|
|
]);
|
||
|
|
|
||
|
|
$perPage = min($request->input('per_page', 15), 100);
|
||
|
|
|
||
|
|
$jobs = $this->searchService->search($filters, $perPage);
|
||
|
|
|
||
|
|
return new JobCollection($jobs);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display the specified job
|
||
|
|
*/
|
||
|
|
public function show(int $id)
|
||
|
|
{
|
||
|
|
$job = Job::with(['source', 'category', 'jobLocation'])
|
||
|
|
->findOrFail($id);
|
||
|
|
|
||
|
|
return new JobResource($job);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get autocomplete suggestions for job titles
|
||
|
|
*/
|
||
|
|
public function titleSuggestions(Request $request)
|
||
|
|
{
|
||
|
|
$query = $request->input('q', '');
|
||
|
|
|
||
|
|
if (strlen($query) < 2) {
|
||
|
|
return response()->json([]);
|
||
|
|
}
|
||
|
|
|
||
|
|
$suggestions = $this->searchService->getTitleSuggestions($query, 10);
|
||
|
|
|
||
|
|
return response()->json($suggestions);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get autocomplete suggestions for companies
|
||
|
|
*/
|
||
|
|
public function companySuggestions(Request $request)
|
||
|
|
{
|
||
|
|
$query = $request->input('q', '');
|
||
|
|
|
||
|
|
if (strlen($query) < 2) {
|
||
|
|
return response()->json([]);
|
||
|
|
}
|
||
|
|
|
||
|
|
$suggestions = $this->searchService->getCompanySuggestions($query, 10);
|
||
|
|
|
||
|
|
return response()->json($suggestions);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get autocomplete suggestions for locations
|
||
|
|
*/
|
||
|
|
public function locationSuggestions(Request $request)
|
||
|
|
{
|
||
|
|
$query = $request->input('q', '');
|
||
|
|
|
||
|
|
if (strlen($query) < 2) {
|
||
|
|
return response()->json([]);
|
||
|
|
}
|
||
|
|
|
||
|
|
$suggestions = $this->searchService->getLocationSuggestions($query, 10);
|
||
|
|
|
||
|
|
return response()->json($suggestions);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get filter options
|
||
|
|
*/
|
||
|
|
public function filterOptions()
|
||
|
|
{
|
||
|
|
return response()->json($this->searchService->getFilterOptions());
|
||
|
|
}
|
||
|
|
}
|