Initial commit: Laravel Blog API
This commit is contained in:
73
routes/api.php
Normal file
73
routes/api.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\Api\CategoryController;
|
||||
use App\Http\Controllers\Api\PostController;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('v1')->group(function (): void {
|
||||
/**
|
||||
* Health check endpoint.
|
||||
*
|
||||
* @group Health
|
||||
*/
|
||||
Route::get('/health', function () {
|
||||
return response()->json([
|
||||
'service' => config('app.name', 'blog-api'),
|
||||
'status' => 'ok',
|
||||
'timestamp' => now()->toISOString(),
|
||||
]);
|
||||
})->name('api.v1.health');
|
||||
|
||||
/**
|
||||
* Database health check endpoint.
|
||||
*
|
||||
* @group Health
|
||||
*/
|
||||
Route::get('/health-check-db', function () {
|
||||
try {
|
||||
DB::select('select 1');
|
||||
|
||||
return response()->json([
|
||||
'service' => config('app.name', 'blog-api'),
|
||||
'database' => 'connected',
|
||||
'timestamp' => now()->toISOString(),
|
||||
]);
|
||||
} catch (Throwable $throwable) {
|
||||
report($throwable);
|
||||
|
||||
return response()->json([
|
||||
'service' => config('app.name', 'blog-api'),
|
||||
'database' => 'disconnected',
|
||||
'message' => 'Não foi possível conectar ao banco de dados.',
|
||||
'timestamp' => now()->toISOString(),
|
||||
], 500);
|
||||
}
|
||||
})->name('api.v1.health.db');
|
||||
|
||||
Route::prefix('public')->name('api.v1.public.')->group(function (): void {
|
||||
Route::get('/posts', [PostController::class, 'index'])->name('posts.index');
|
||||
Route::get('/posts/{post:slug}', [PostController::class, 'show'])->name('posts.show');
|
||||
Route::get('/categories', [CategoryController::class, 'index'])->name('categories.index');
|
||||
Route::get('/categories/{category:slug}', [CategoryController::class, 'show'])->name('categories.show');
|
||||
});
|
||||
|
||||
/**
|
||||
* Protected routes placeholder.
|
||||
*
|
||||
* These routes are intentionally grouped to make future JWT integration straightforward:
|
||||
* Route::middleware(['auth:api'])->group(...)
|
||||
*/
|
||||
Route::prefix('admin')
|
||||
->name('api.v1.admin.')
|
||||
// ->middleware('auth:api')
|
||||
->group(function (): void {
|
||||
Route::apiResource('posts', PostController::class)->parameters([
|
||||
'posts' => 'post',
|
||||
]);
|
||||
|
||||
Route::apiResource('categories', CategoryController::class)->parameters([
|
||||
'categories' => 'category',
|
||||
]);
|
||||
});
|
||||
});
|
||||
8
routes/console.php
Normal file
8
routes/console.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
Artisan::command('inspire', function () {
|
||||
$this->comment(Inspiring::quote());
|
||||
})->purpose('Display an inspiring quote');
|
||||
61
routes/web.php
Normal file
61
routes/web.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/', function () {
|
||||
$routes = [
|
||||
[
|
||||
'method' => 'GET',
|
||||
'uri' => '/api/v1/health',
|
||||
'description' => 'Verifica se o serviço está respondendo.',
|
||||
'visibility' => 'Pública',
|
||||
],
|
||||
[
|
||||
'method' => 'GET',
|
||||
'uri' => '/api/v1/health-check-db',
|
||||
'description' => 'Verifica a conexão com o banco de dados.',
|
||||
'visibility' => 'Pública',
|
||||
],
|
||||
[
|
||||
'method' => 'GET',
|
||||
'uri' => '/api/v1/public/posts',
|
||||
'description' => 'Lista posts com paginação, busca e filtros.',
|
||||
'visibility' => 'Pública',
|
||||
],
|
||||
[
|
||||
'method' => 'GET',
|
||||
'uri' => '/api/v1/public/posts/{slug}',
|
||||
'description' => 'Exibe um post pelo slug.',
|
||||
'visibility' => 'Pública',
|
||||
],
|
||||
[
|
||||
'method' => 'GET',
|
||||
'uri' => '/api/v1/public/categories',
|
||||
'description' => 'Lista categorias com contagem de posts.',
|
||||
'visibility' => 'Pública',
|
||||
],
|
||||
[
|
||||
'method' => 'GET',
|
||||
'uri' => '/api/v1/public/categories/{slug}',
|
||||
'description' => 'Exibe uma categoria pelo slug.',
|
||||
'visibility' => 'Pública',
|
||||
],
|
||||
[
|
||||
'method' => 'API RESOURCE',
|
||||
'uri' => '/api/v1/admin/posts',
|
||||
'description' => 'CRUD administrativo de posts. Grupo preparado para JWT.',
|
||||
'visibility' => 'Protegida em breve',
|
||||
],
|
||||
[
|
||||
'method' => 'API RESOURCE',
|
||||
'uri' => '/api/v1/admin/categories',
|
||||
'description' => 'CRUD administrativo de categorias. Grupo preparado para JWT.',
|
||||
'visibility' => 'Protegida em breve',
|
||||
],
|
||||
];
|
||||
|
||||
return view('api-dashboard', [
|
||||
'serviceName' => config('app.name', 'Blog API'),
|
||||
'routes' => $routes,
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user