From 36cf4a816fdaef0e8d2229747a0487f26ba2636e Mon Sep 17 00:00:00 2001 From: Bozhidar Slaveykov Date: Wed, 3 Apr 2024 12:56:10 +0300 Subject: [PATCH] update --- .../Controllers/Api/CustomersController.php | 1 - .../Http/Controllers/Api/HealthController.php | 2 + .../Api/Request/AuthLoginRequest.php | 20 +++++++ .../Api/Request/AuthorizedApiRequest.php | 2 +- web/db-migrate.sh | 2 + web/routes/api.php | 19 ++++--- web/storage/api-docs/api-docs.json | 54 ++++++++++++++++++- 7 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 web/app/Http/Controllers/Api/Request/AuthLoginRequest.php diff --git a/web/app/Http/Controllers/Api/CustomersController.php b/web/app/Http/Controllers/Api/CustomersController.php index f91d744..911de19 100644 --- a/web/app/Http/Controllers/Api/CustomersController.php +++ b/web/app/Http/Controllers/Api/CustomersController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers\Api; - use App\Http\Controllers\Api\Request\CustomerCreateRequest; use App\Http\Controllers\ApiController; use App\Models\Customer; diff --git a/web/app/Http/Controllers/Api/HealthController.php b/web/app/Http/Controllers/Api/HealthController.php index e7bf9a5..d12d4f8 100644 --- a/web/app/Http/Controllers/Api/HealthController.php +++ b/web/app/Http/Controllers/Api/HealthController.php @@ -20,6 +20,8 @@ class HealthController extends ApiController */ public function index() { + file_put_contents('test.txt', 'test'); + return response()->json(['status' => 'ok']); } } diff --git a/web/app/Http/Controllers/Api/Request/AuthLoginRequest.php b/web/app/Http/Controllers/Api/Request/AuthLoginRequest.php new file mode 100644 index 0000000..bd319c0 --- /dev/null +++ b/web/app/Http/Controllers/Api/Request/AuthLoginRequest.php @@ -0,0 +1,20 @@ + 'required|string|email', + 'password' => 'required|string', + // 'browserAgent' => 'required|string', + ]; + } +} diff --git a/web/app/Http/Controllers/Api/Request/AuthorizedApiRequest.php b/web/app/Http/Controllers/Api/Request/AuthorizedApiRequest.php index 606699e..230d22a 100644 --- a/web/app/Http/Controllers/Api/Request/AuthorizedApiRequest.php +++ b/web/app/Http/Controllers/Api/Request/AuthorizedApiRequest.php @@ -12,7 +12,7 @@ class AuthorizedApiRequest extends ApiRequest public function authorize() { $user = auth()->user(); - + if ($user) { return true; } diff --git a/web/db-migrate.sh b/web/db-migrate.sh index a7a8310..b6a49b8 100644 --- a/web/db-migrate.sh +++ b/web/db-migrate.sh @@ -2,6 +2,8 @@ PHYRE_PHP=/usr/local/phyre/php/bin/php #rm -rf composer.lock #$PHYRE_PHP composer.phar i +#$PHYRE_PHP composer.phar dump-autoload + $PHYRE_PHP artisan migrate $PHYRE_PHP artisan l5-swagger:generate diff --git a/web/routes/api.php b/web/routes/api.php index da8f78f..530ac9d 100644 --- a/web/routes/api.php +++ b/web/routes/api.php @@ -16,13 +16,18 @@ use Illuminate\Support\Facades\Route; Route::get('health', [\App\Http\Controllers\Api\HealthController::class, 'index']); -Route::get('customers', [\App\Http\Controllers\Api\CustomersController::class, 'index']); -Route::post('customers', [\App\Http\Controllers\Api\CustomersController::class, 'store']); -Route::get('customers/{id}', [\App\Http\Controllers\Api\CustomersController::class, 'show']); -Route::put('customers/{id}', [\App\Http\Controllers\Api\CustomersController::class, 'update']); -Route::delete('customers/{id}', [\App\Http\Controllers\Api\CustomersController::class, 'destroy']); +Route::middleware('auth:sanctum')->group(function () { + + Route::get('/user', function (Request $request) { + return $request->user(); + }); + + Route::get('customers', [\App\Http\Controllers\Api\CustomersController::class, 'index']); + Route::post('customers', [\App\Http\Controllers\Api\CustomersController::class, 'store']); + Route::get('customers/{id}', [\App\Http\Controllers\Api\CustomersController::class, 'show']); + Route::put('customers/{id}', [\App\Http\Controllers\Api\CustomersController::class, 'update']); + Route::delete('customers/{id}', [\App\Http\Controllers\Api\CustomersController::class, 'destroy']); + -Route::middleware('auth:sanctum')->get('/user', function (Request $request) { - return $request->user(); }); diff --git a/web/storage/api-docs/api-docs.json b/web/storage/api-docs/api-docs.json index 6ee8828..08ca8e9 100644 --- a/web/storage/api-docs/api-docs.json +++ b/web/storage/api-docs/api-docs.json @@ -8,9 +8,59 @@ "version": "0.1" }, "paths": { - "/health": { + "/api/customers": { "get": { - "operationId": "14039960f5c35aafcd0adcc381fc5f34", + "operationId": "6f01ddd63e2a72fee24eb31157a1c799", + "responses": { + "200": { + "description": "Successful operation" + } + } + }, + "post": { + "operationId": "cef1c1e98a7505ddd8d797aba6787da4", + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "required": [ + "name", + "email", + "phone" + ], + "properties": { + "name": { + "description": "Name of the customer", + "type": "string", + "example": "John Doe" + }, + "email": { + "description": "Email of the customer", + "type": "string", + "example": "jhon@gmail.com" + }, + "phone": { + "description": "Phone of the customer", + "type": "string", + "example": "1234567890" + } + }, + "type": "object" + } + } + } + }, + "responses": { + "200": { + "description": "Successful operation" + } + } + } + }, + "/api/health": { + "get": { + "operationId": "c873d7f3d9f52c19cd7a1b4bebfe02df", "responses": { "200": { "description": "Successful operation"