Merge branch '149-api-companies' into 'develop'

feat: ✨ add companies endpoint

See merge request ldc-web/projets/ldc!166
This commit is contained in:
Noix 2026-05-12 14:20:15 +00:00
commit 1895a9411a
3 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,35 @@
<?php
namespace App\Http\Controllers\Api;
use App\Models\Company;
class CompanyController
{
/**
* Retrieve all published companies with their associated activity and sector.
*
* @return \Illuminate\Http\JsonResponse
*/
public function getCompanies(): \Illuminate\Http\JsonResponse
{
$companies = Company::query()->where('published', true)->with('companyActivity', 'companySector')->get();
$data = $companies->map(function ($company) {
return array_filter([
'name' => $company->name,
'logo' => $company->logo,
'informations' => $company->informations,
'responsable' => $company->responsable,
'employees' => $company->employees,
'url' => $company->url,
'latitude' => $company->latitude,
'longitude' => $company->longitude,
'type_activite' => $company->companyActivity->name,
'filiere' => $company->companySector?->name,
], fn($value) => !is_null($value));
});
return response()->json($data);
}
}

View file

@ -14,6 +14,7 @@ return Application::configure(basePath: dirname(__DIR__))
__DIR__ . '/../routes/web-front.php',
__DIR__ . '/../routes/web-back.php',
],
api: __DIR__.'/../routes/api.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {

6
routes/api.php Normal file
View file

@ -0,0 +1,6 @@
<?php
use App\Http\Controllers\Api\CompanyController;
use Illuminate\Support\Facades\Route;
Route::get('/companies', [CompanyController::class, 'getCompanies']);