feat: add ApiResponse trait for standardized API responses
chore: update composer dependencies to include phppresentation chore: update composer.lock after adding phppresentation feat: create categories migration for category management feat: create templates migration for template storage feat: create template generations migration for tracking template usage feat: create template keys migration for template customization feat: create notifications migration for user notifications feat: update API routes for categories, templates, and user profile management docs: update API documentation to include new endpoints for profile and wallet
This commit is contained in:
98
app/Http/Controllers/Api/ProfileController.php
Normal file
98
app/Http/Controllers/Api/ProfileController.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Profile\UpdateProfileRequest;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Traits\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
#[OA\Get(
|
||||
path: '/profile',
|
||||
description: 'Get the authenticated user profile',
|
||||
summary: 'Show profile',
|
||||
security: [['sanctum' => []]],
|
||||
tags: ['Profile'],
|
||||
responses: [
|
||||
new OA\Response(
|
||||
response: 200,
|
||||
description: 'Profile fetched successfully',
|
||||
content: new OA\JsonContent(
|
||||
properties: [
|
||||
new OA\Property(property: 'message', type: 'string', example: 'اطلاعات پروفایل با موفقیت دریافت شد.'),
|
||||
new OA\Property(
|
||||
property: 'data',
|
||||
properties: [
|
||||
new OA\Property(property: 'user', ref: '#/components/schemas/User'),
|
||||
],
|
||||
type: 'object'
|
||||
),
|
||||
]
|
||||
)
|
||||
),
|
||||
new OA\Response(response: 401, description: 'Unauthenticated'),
|
||||
]
|
||||
)]
|
||||
public function show(): JsonResponse
|
||||
{
|
||||
return $this->success('اطلاعات پروفایل با موفقیت دریافت شد.', [
|
||||
'user' => new UserResource(request()->user()),
|
||||
]);
|
||||
}
|
||||
|
||||
#[OA\Put(
|
||||
path: '/profile',
|
||||
description: 'Update the authenticated user profile',
|
||||
summary: 'Update profile',
|
||||
security: [['sanctum' => []]],
|
||||
tags: ['Profile'],
|
||||
requestBody: new OA\RequestBody(
|
||||
required: true,
|
||||
content: new OA\JsonContent(
|
||||
properties: [
|
||||
new OA\Property(property: 'name', type: 'string', example: 'علی رضایی'),
|
||||
new OA\Property(property: 'username', type: 'string', example: 'ali'),
|
||||
new OA\Property(property: 'email', type: 'string', format: 'email', example: 'ali@example.com'),
|
||||
new OA\Property(property: 'mobile', type: 'string', example: '09123456789'),
|
||||
new OA\Property(property: 'password', type: 'string', format: 'password', example: 'password123'),
|
||||
]
|
||||
)
|
||||
),
|
||||
responses: [
|
||||
new OA\Response(
|
||||
response: 200,
|
||||
description: 'Profile updated successfully',
|
||||
content: new OA\JsonContent(
|
||||
properties: [
|
||||
new OA\Property(property: 'message', type: 'string', example: 'پروفایل با موفقیت بهروزرسانی شد.'),
|
||||
new OA\Property(
|
||||
property: 'data',
|
||||
properties: [
|
||||
new OA\Property(property: 'user', ref: '#/components/schemas/User'),
|
||||
],
|
||||
type: 'object'
|
||||
),
|
||||
]
|
||||
)
|
||||
),
|
||||
new OA\Response(response: 401, description: 'Unauthenticated'),
|
||||
new OA\Response(response: 422, description: 'Validation error'),
|
||||
]
|
||||
)]
|
||||
public function update(UpdateProfileRequest $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$user->update($request->validated());
|
||||
|
||||
return $this->success('پروفایل با موفقیت بهروزرسانی شد.', [
|
||||
'user' => new UserResource($user->fresh()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user