Files
Php-Template/src/Controllers/IndexController.php
Ron Rise 99493d4264
All checks were successful
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 4m0s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 4m11s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 4m22s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 4m42s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 4m27s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 2m55s
feat: add Swagger integration with OpenAPI annotations and endpoints
2025-12-01 10:21:04 -05:00

63 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Siteworxpro\App\Controllers;
use Nyholm\Psr7\ServerRequest;
use Psr\Http\Message\ResponseInterface;
use Siteworxpro\App\Attributes\Guards;
use Siteworxpro\App\Http\JsonResponseFactory;
use OpenApi\Attributes as OA;
/**
* Class IndexController
*
* This class handles the index route of the application.
*/
class IndexController extends Controller
{
/**
* Handles the GET request for the index route.
*
* @throws \JsonException
*/
#[Guards\Jwt]
#[Guards\Scope(['get.index', 'status.check'])]
#[Guards\RequireAllScopes]
#[OA\Get(path: '/')]
#[OA\Response(
response: '200',
description: 'An Example Response',
content: new OA\JsonContent(properties: [
new OA\Property('status_code', type: 'integer'),
new OA\Property('message', type: 'string'),
])
)]
public function get(ServerRequest $request): ResponseInterface
{
return JsonResponseFactory::createJsonResponse(['status_code' => 200, 'message' => 'Server is running']);
}
/**
* @throws \JsonException
*/
#[Guards\Jwt]
#[Guards\Scope(['post.index'])]
#[OA\Post(path: '/')]
#[OA\Response(
response: '200',
description: 'An Example Response',
content: new OA\JsonContent(
properties: [
new OA\Property('status_code', type: 'integer'),
new OA\Property('message', type: 'string'),
]
)
)]
public function post(ServerRequest $request): ResponseInterface
{
return JsonResponseFactory::createJsonResponse(['status_code' => 200, 'message' => 'Server is running']);
}
}