feat(api): add AI text-to-deck generation, wallet deposit structure, and profile/notification endpoints
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>
This commit is contained in:
@@ -3,10 +3,13 @@
|
||||
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
|
||||
@@ -89,10 +92,97 @@ class ProfileController extends Controller
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$user->update($request->validated());
|
||||
$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('حساب کاربری با موفقیت حذف شد.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user