[]]], 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('حساب کاربری با موفقیت حذف شد.'); } }