Skip to content

Commit

Permalink
Get the authenticated admin
Browse files Browse the repository at this point in the history
  • Loading branch information
arifszn committed Sep 19, 2022
1 parent b38f470 commit 9548c69
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
51 changes: 51 additions & 0 deletions app/Http/Controllers/Admin/ProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Resources\AdminResource;
use App\Services\AdminService;
use OpenApi\Attributes as OAT;
use Illuminate\Http\Response as HttpResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Response;
use Illuminate\Http\Request;

class ProfileController extends Controller
{
/**
* Create a new controller instance.
*
* @param AdminService $adminService
* @return void
*/
public function __construct(private AdminService $adminService)
{
//
}

/**
* Get the authenticated admin.
*
* @param Request $request
* @return JsonResponse
*/
#[OAT\Get(
tags: ['adminProfile'],
path: '/api/admin/profile',
summary: 'me',
operationId: 'Admin.ProfileController.me',
security: [['BearerToken' => []]],
responses: [
new OAT\Response(
response: HttpResponse::HTTP_OK,
description: 'Ok',
content: new OAT\JsonContent(ref: '#/components/schemas/AdminResource')
),
]
)]
public function me(Request $request): JsonResponse
{
return Response::json(new AdminResource($request->user()));
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
OAT\Tag(name: 'auth', description: 'User authentication'),
OAT\Tag(name: 'adminAuth', description: 'Admin authentication'),
OAT\Tag(name: 'profile', description: 'User profile'),
OAT\Tag(name: 'adminProfile', description: 'Admin profile'),
OAT\Schema(
schema: 'ValidationError',
properties: [
Expand Down
7 changes: 7 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public function boot()
], function () {
require base_path('routes/api/profile.php');
});

Route::group([
'middleware' => ['auth:admin'],
'prefix' => 'admin'
], function () {
require base_path('routes/api/admin/profile.php');
});
});

Route::middleware('web')
Expand Down
20 changes: 20 additions & 0 deletions public/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ servers:
url: 'http://localhost'
description: 'Local API server'
paths:
/api/admin/profile:
get:
tags:
- adminProfile
summary: me
description: 'Get the authenticated admin.'
operationId: Admin.ProfileController.me
responses:
'200':
description: Ok
content:
application/json:
schema:
$ref: '#/components/schemas/AdminResource'
security:
-
BearerToken: []
/api/signup:
post:
tags:
Expand Down Expand Up @@ -291,3 +308,6 @@ tags:
-
name: profile
description: 'User profile'
-
name: adminProfile
description: 'Admin profile'
8 changes: 8 additions & 0 deletions routes/api/admin/profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

use App\Http\Controllers\Admin\ProfileController;
use Illuminate\Support\Facades\Route;

Route::group(['prefix' => 'profile'], function () {
Route::get('/', [ProfileController::class, 'me']);
});

0 comments on commit 9548c69

Please sign in to comment.