refactor(api): restructure API routes and improve organization

- Group employee routes under a prefix for better clarity.
- Remove unnecessary blank lines and improve code formatting.
This commit is contained in:
Jérémy Munsch 2026-08-13 09:35:09 +02:00
parent 3208556047
commit b2c11a52ad
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
6 changed files with 19 additions and 15 deletions

View file

@ -3,10 +3,9 @@
declare(strict_types=1);
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Support\Env;
return Application::configure(Env::get('APP_BASE_PATH', dirname(__DIR__)))
$app = Application::configure(Env::get('APP_BASE_PATH', dirname(__DIR__)))
->withRouting(
web: __DIR__ . '/../routes/web.php',
api: __DIR__ . '/../routes/api.php',
@ -16,3 +15,7 @@ return Application::configure(Env::get('APP_BASE_PATH', dirname(__DIR__)))
->withMiddleware(require __DIR__ . '/middlewares.php')
->withExceptions(require __DIR__ . '/exceptions.php')
->create();
$app->useAppPath($app->basePath('src/Presentation'));
return $app;

View file

@ -18,7 +18,6 @@ Route::get(
Route::get('/ping', fn () => response()->json('pong'))->name('api.ping');
// * V1 API
Route::prefix('v1')->name('api.v1.')->group(function () {
require __DIR__ . '/apiv1.php';

View file

@ -7,17 +7,22 @@ use Illuminate\Support\Facades\Route;
use Presentation\Api\V1\Http\Controllers\Employees\EmployeeShowController;
use Presentation\Api\V1\Http\Controllers\Employees\EmployeesIndexController;
// * ROOT
Route::get('/', fn () => response()->json([
'message' => Config::string('app.name') . ' v1',
'spec' => route('api.v1.openapi'),
]))->name('root');
// * OPENAPI
Route::get('/openapi', function () {
return response()->file(
base_path('documentation/OpenApi/openapi.yaml'),
['Content-Type' => 'application/yaml']
);
})->name('openapi');
Route::get('/employees', EmployeesIndexController::class)->name('employees.index');
Route::get('/employees/{employeeId}', EmployeeShowController::class)->name('employees.show');
// * EMPLOYEES
Route::prefix('employees')->group(function () {
Route::get('/', EmployeesIndexController::class)->name('employees.index');
Route::get('/{employeeId}', EmployeeShowController::class)->name('employees.show');
});

View file

@ -5,16 +5,16 @@ declare(strict_types=1);
namespace Infra\Providers;
use Carbon\CarbonInterface;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request as HttpRequest;
use Illuminate\Http\Request as IlluminateRequest;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request as IlluminateRequest;
use League\Uri\Http;
use Shared\Pagination;
@ -90,7 +90,6 @@ class AppServiceProvider extends ServiceProvider
});
}
public function toLocalInput(CarbonInterface | \DateTimeInterface | int | float | string | null $date): ?string
{
if ($date === null) {

View file

@ -5,10 +5,10 @@ declare(strict_types=1);
namespace Presentation\Api\V1\Exceptions;
use Domain\Exceptions\NotFoundException;
use Illuminate\Http\Exceptions\ThrottleRequestsException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Illuminate\Http\Exceptions\ThrottleRequestsException;
use Illuminate\Validation\ValidationException;
use League\Uri\Http;
use Symfony\Component\HttpFoundation\Response;
@ -58,7 +58,6 @@ final readonly class ApiExceptionRenderer
)),
], 400, ['Content-Type' => self::CONTENT_TYPE]),
$e instanceof \DomainException => response()->json([
'type' => (string) $baseUri->withPath('/errors/422'),
'title' => 'Unprocessable Entity',
@ -97,7 +96,7 @@ final readonly class ApiExceptionRenderer
$detail = $e->getMessage() ?: $title;
}
$headers = $e instanceof HttpExceptionInterface ? $e->getHeaders() : [];
$headers = $e instanceof HttpExceptionInterface ? $e->getHeaders() : [];
$headers['Content-Type'] = self::CONTENT_TYPE;
return response()->json([

View file

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Presentation\Web\Http\Controllers;
use Illuminate\Contracts\View\View;
use Symfony\Component\HttpFoundation\Response;
final class ErrorDocumentationController
@ -18,7 +17,7 @@ final class ErrorDocumentationController
$viewName = 'errors.docs.' . $code;
if (!view()->exists($viewName)) {
if (! view()->exists($viewName)) {
abort(404);
}