Fills the gaps between the admin panel screens and the backend: a full free-text + slide-count + language -> AI-generated presentation flow with new slide-cloning logic in TemplateFillService, a "my presentations" list endpoint, a swappable payment-gateway structure for wallet top-ups (fake driver for now), and avatar upload / public-profile toggle / account deletion / password change / notification preference endpoints. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
189 lines
7.0 KiB
PHP
189 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Profile\ChangePasswordRequest;
|
|
use App\Http\Requests\Profile\UpdateProfileRequest;
|
|
use App\Http\Resources\UserResource;
|
|
use App\Traits\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Storage;
|
|
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();
|
|
|
|
$data = $request->safe()->except('avatar');
|
|
|
|
if ($request->hasFile('avatar')) {
|
|
if ($user->avatar_path) {
|
|
Storage::disk('public')->delete($user->avatar_path);
|
|
}
|
|
|
|
$data['avatar_path'] = $request->file('avatar')->store('avatars', 'public');
|
|
}
|
|
|
|
$user->update($data);
|
|
|
|
return $this->success('پروفایل با موفقیت بهروزرسانی شد.', [
|
|
'user' => new UserResource($user->fresh()),
|
|
]);
|
|
}
|
|
|
|
#[OA\Put(
|
|
path: '/profile/password',
|
|
description: 'Change the authenticated user password',
|
|
summary: 'Change password',
|
|
security: [['sanctum' => []]],
|
|
tags: ['Profile'],
|
|
requestBody: new OA\RequestBody(
|
|
required: true,
|
|
content: new OA\JsonContent(
|
|
required: ['current_password', 'password', 'password_confirmation'],
|
|
properties: [
|
|
new OA\Property(property: 'current_password', type: 'string', format: 'password'),
|
|
new OA\Property(property: 'password', type: 'string', format: 'password'),
|
|
new OA\Property(property: 'password_confirmation', type: 'string', format: 'password'),
|
|
]
|
|
)
|
|
),
|
|
responses: [
|
|
new OA\Response(
|
|
response: 200,
|
|
description: 'Password changed successfully',
|
|
content: new OA\JsonContent(
|
|
properties: [
|
|
new OA\Property(property: 'message', type: 'string', example: 'رمز عبور با موفقیت تغییر کرد.'),
|
|
new OA\Property(property: 'data', type: 'object'),
|
|
]
|
|
)
|
|
),
|
|
new OA\Response(response: 401, description: 'Unauthenticated'),
|
|
new OA\Response(response: 422, description: 'Validation error'),
|
|
]
|
|
)]
|
|
public function changePassword(ChangePasswordRequest $request): JsonResponse
|
|
{
|
|
$user = $request->user();
|
|
|
|
$user->update(['password' => $request->validated('password')]);
|
|
|
|
$currentTokenId = $user->currentAccessToken()?->id;
|
|
|
|
if ($currentTokenId) {
|
|
$user->tokens()->where('id', '!=', $currentTokenId)->delete();
|
|
}
|
|
|
|
return $this->success('رمز عبور با موفقیت تغییر کرد.');
|
|
}
|
|
|
|
#[OA\Delete(
|
|
path: '/profile',
|
|
description: 'Delete the authenticated user account',
|
|
summary: 'Delete account',
|
|
security: [['sanctum' => []]],
|
|
tags: ['Profile'],
|
|
responses: [
|
|
new OA\Response(
|
|
response: 200,
|
|
description: 'Account deleted successfully',
|
|
content: new OA\JsonContent(
|
|
properties: [
|
|
new OA\Property(property: 'message', type: 'string', example: 'حساب کاربری با موفقیت حذف شد.'),
|
|
new OA\Property(property: 'data', type: 'object'),
|
|
]
|
|
)
|
|
),
|
|
new OA\Response(response: 401, description: 'Unauthenticated'),
|
|
]
|
|
)]
|
|
public function destroy(Request $request): JsonResponse
|
|
{
|
|
$user = $request->user();
|
|
|
|
$user->tokens()->delete();
|
|
$user->delete();
|
|
|
|
return $this->success('حساب کاربری با موفقیت حذف شد.');
|
|
}
|
|
}
|