61 lines
2.3 KiB
PHP
61 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Opportunity;
|
|
use App\Models\Sector;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
public function show(Request $request): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'locale' => ['nullable', 'string', Rule::in(['pt', 'en'])],
|
|
]);
|
|
|
|
$locale = $validated['locale'] ?? 'pt';
|
|
|
|
$data = Cache::remember("portal_home_sector_organization_v1_{$locale}", now()->addMinutes(10), function () {
|
|
$sectors = \App\Services\SectorOrganization::catalog();
|
|
|
|
$featured = Opportunity::with('sector:id,name,slug')
|
|
->published()->where('is_featured', true)
|
|
->latest('published_at')->limit(6)->get();
|
|
|
|
return [
|
|
'sectors' => $sectors->map(fn ($s) => [
|
|
'id' => $s->id, 'specializations' => $s->specializations, 'name' => $s->name,
|
|
'slug' => $s->slug,
|
|
'shortDescription' => $s->short_description,
|
|
'opportunitiesCount' => $s->opportunities_count,
|
|
'url' => "/sectores/{$s->slug}",
|
|
])->values()->all(),
|
|
'featuredOpportunities' => $featured->map(fn ($o) => [
|
|
'id' => $o->id, 'reference' => $o->reference,
|
|
'title' => $o->title,
|
|
'sector' => $o->sector?->name,
|
|
'province' => $o->province,
|
|
'maturity' => $o->maturity_label,
|
|
'estimatedInvestment' => [
|
|
'amount' => $o->estimated_investment_amount,
|
|
'currency' => $o->estimated_investment_currency,
|
|
],
|
|
'url' => "/oportunidades/{$o->slug}",
|
|
])->values()->all(),
|
|
'stats' => [
|
|
'opportunities' => Opportunity::published()->count(),
|
|
'sectors' => $sectors->count(),
|
|
'provinces' => Opportunity::published()->distinct('province')->count('province'),
|
|
],
|
|
];
|
|
});
|
|
|
|
return response()->json(['success' => true, 'locale' => $locale, 'data' => $data]);
|
|
}
|
|
}
|