Files
parsaaghayi-backend/routes/api.php
T
Parsa Aghayi d4f41b9c2e
Deploy Backend / deploy (push) Successful in 2m40s
Store contact messages in DB and seed real bilingual blog content
Contact form messages were sent via mailto and the site has no mail
service, so visitors saw a placeholder caveat instead of a working
channel. Add a contact_messages table, a public throttled POST endpoint,
and admin list/mark/delete endpoints, then wire them into the panel.

Replace the faker-generated blog demonstration content with real
English and Persian SEO-oriented articles via RealBlogContentSeeder
(deterministic, bilingual posts with per-language categories and tags,
and cross-linked related posts).
2026-10-02 05:41:05 -04:00

118 lines
5.1 KiB
PHP

<?php
use App\Http\Controllers\Api\Admin\AdminResourceController;
use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\Blog\CategoryController;
use App\Http\Controllers\Api\Blog\HomeController;
use App\Http\Controllers\Api\Blog\PostController;
use App\Http\Controllers\Api\Blog\TagController;
use App\Http\Controllers\Api\ContactMessageController;
use App\Http\Controllers\Api\Website\AboutMeController;
use App\Http\Controllers\Api\Website\ProjectCategoryController;
use App\Http\Controllers\Api\Website\ProjectController;
use App\Http\Controllers\Api\Website\ServiceController;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Authentication
|--------------------------------------------------------------------------
| Used by the admin panel. Login is throttled hard because it is the one
| endpoint that accepts attacker-controlled credentials.
*/
Route::post('auth/login', [AuthController::class, 'login'])
->middleware('throttle:5,1')
->name('auth.login');
Route::middleware(['auth:sanctum', 'throttle:60,1'])->group(function () {
Route::get('auth/me', [AuthController::class, 'me'])->name('auth.me');
Route::post('auth/logout', [AuthController::class, 'logout'])->name('auth.logout');
});
/*
|--------------------------------------------------------------------------
| Public read API
|--------------------------------------------------------------------------
| Anonymous, cacheable, GET-only. Nothing here can change state.
*/
Route::middleware('throttle:60,1')->group(function () {
Route::prefix('website')->group(function () {
Route::get('about-me', [AboutMeController::class, 'index']);
Route::get('about-me/{id}', [AboutMeController::class, 'show']);
Route::get('about-me/{id}/translation/{locale}', [AboutMeController::class, 'getTranslation']);
Route::get('project-categories', [ProjectCategoryController::class, 'index']);
Route::get('services/{locale}', [ServiceController::class, 'index']);
Route::get('services/{id}/translation/{locale}', [ServiceController::class, 'showTranslation']);
Route::get('projects/translation/{locale}', [ProjectController::class, 'index']);
Route::get('projects/{id}/translation/{locale}', [ProjectController::class, 'show']);
});
Route::prefix('blog')->group(function () {
Route::get('homepage', [HomeController::class, 'index']);
Route::get('posts', [PostController::class, 'index']);
Route::get('posts/{slug}', [PostController::class, 'show']);
Route::get('categories', [CategoryController::class, 'index']);
Route::get('categories/{id}', [CategoryController::class, 'show']);
Route::get('categories/{slug}/posts', [CategoryController::class, 'getCategoryWithPosts']);
Route::get('tags', [TagController::class, 'index']);
Route::get('tags/{id}', [TagController::class, 'show']);
});
});
/*
|--------------------------------------------------------------------------
| Public contact form
|--------------------------------------------------------------------------
| The site has no mail service; messages are stored and read from the admin
| panel, so the write endpoint is public (no auth) but throttled to keep
| spam from flooding the inbox.
*/
Route::post('contact', [ContactMessageController::class, 'store'])
->middleware('throttle:5,1');
/*
|--------------------------------------------------------------------------
| Admin write API
|--------------------------------------------------------------------------
| Every mutating endpoint requires an authenticated admin. These routes were
| previously anonymous, which allowed anyone to create, edit or delete every
| post, category, tag, project and about-me record on the live site.
*/
Route::middleware(['auth:sanctum', 'admin', 'throttle:30,1'])->group(function () {
Route::prefix('website')->group(function () {
Route::post('about-me', [AboutMeController::class, 'store']);
Route::put('about-me/{id}', [AboutMeController::class, 'update']);
Route::delete('about-me/{id}', [AboutMeController::class, 'destroy']);
Route::post('projects', [ProjectController::class, 'store']);
Route::put('projects/{id}', [ProjectController::class, 'update']);
Route::delete('projects/{id}', [ProjectController::class, 'destroy']);
});
Route::prefix('blog')->group(function () {
Route::post('posts', [PostController::class, 'store']);
Route::put('posts/{id}', [PostController::class, 'update']);
Route::delete('posts/{id}', [PostController::class, 'destroy']);
Route::post('categories', [CategoryController::class, 'store']);
Route::put('categories/{id}', [CategoryController::class, 'update']);
Route::delete('categories/{id}', [CategoryController::class, 'destroy']);
Route::post('tags', [TagController::class, 'store']);
Route::put('tags/{id}', [TagController::class, 'update']);
Route::delete('tags/{id}', [TagController::class, 'destroy']);
});
Route::get('admin/resources/{resource}', [AdminResourceController::class, 'index']);
});