Files
parsaaghayi-backend/routes/api.php
T
DevOps 7ee8440a65
Deploy Backend / deploy (push) Waiting to run
Expose About Me translations and project categories for the admin panel
About-me writes could only set the image: title and description live in the
JSON translations column and were unreachable from the API, so the homepage
bio could never be edited. Accept title_fa/title_en/description_fa/
description_en on both About Me form requests and write them through
setTranslation() for each locale.

Adds a read-only GET /api/website/project-categories endpoint backed by the
existing (previously unreachable) ProjectCategory model, so project forms can
offer a category picker.
2026-10-01 19:24:00 +00:00

102 lines
4.5 KiB
PHP

<?php
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\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']);
});
});
/*
|--------------------------------------------------------------------------
| 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']);
});
});