[]]], tags: ['Notifications'], parameters: [ new OA\Parameter(name: 'per_page', description: 'Items per page', in: 'query', schema: new OA\Schema(type: 'integer', example: 15)), ], responses: [ new OA\Response( response: 200, description: 'Notifications 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: 'notifications', type: 'array', items: new OA\Items(ref: '#/components/schemas/Notification') ), ], type: 'object' ), ] ) ), new OA\Response(response: 401, description: 'Unauthenticated'), ] )] public function index(Request $request): JsonResponse { $perPage = min(max((int) $request->integer('per_page', 15), 1), 100); $notifications = $request->user()->notifications()->paginate($perPage); return $this->success('نوتیفیکیشن‌ها با موفقیت دریافت شد.', [ 'notifications' => NotificationResource::collection($notifications)->response()->getData(true), ]); } #[OA\Post( path: '/notifications/read-all', description: 'Mark all the authenticated user notifications as read', summary: 'Mark all notifications as read', security: [['sanctum' => []]], tags: ['Notifications'], responses: [ new OA\Response( response: 200, description: 'Notifications marked as read 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 markAllAsRead(Request $request): JsonResponse { $this->notificationService->markAllAsRead($request->user()); return $this->success('همه نوتیفیکیشن‌ها خوانده شد.'); } #[OA\Get( path: '/notifications/preferences', description: 'Get the authenticated user notification preferences', summary: 'Show notification preferences', security: [['sanctum' => []]], tags: ['Notifications'], responses: [ new OA\Response( response: 200, description: 'Notification preferences 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: 'preferences', ref: '#/components/schemas/NotificationPreference'), ], type: 'object' ), ] ) ), new OA\Response(response: 401, description: 'Unauthenticated'), ] )] public function preferences(Request $request): JsonResponse { $preferences = $this->firstOrCreatePreferences($request); return $this->success('تنظیمات اعلان‌ها با موفقیت دریافت شد.', [ 'preferences' => new NotificationPreferenceResource($preferences), ]); } #[OA\Put( path: '/notifications/preferences', description: 'Update the authenticated user notification preferences', summary: 'Update notification preferences', security: [['sanctum' => []]], tags: ['Notifications'], requestBody: new OA\RequestBody( required: true, content: new OA\JsonContent(ref: '#/components/schemas/NotificationPreference') ), responses: [ new OA\Response( response: 200, description: 'Notification preferences 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: 'preferences', ref: '#/components/schemas/NotificationPreference'), ], type: 'object' ), ] ) ), new OA\Response(response: 401, description: 'Unauthenticated'), new OA\Response(response: 422, description: 'Validation error'), ] )] public function updatePreferences(UpdateNotificationPreferencesRequest $request): JsonResponse { $preferences = $this->firstOrCreatePreferences($request); $preferences->update($request->validated()); return $this->success('تنظیمات اعلان‌ها با موفقیت به‌روزرسانی شد.', [ 'preferences' => new NotificationPreferenceResource($preferences->fresh()), ]); } private function firstOrCreatePreferences(Request $request): NotificationPreference { return $request->user()->notificationPreference()->firstOrCreate([], [ 'comment_on_presentation' => true, 'form_reply' => false, 'new_follower' => false, 'news_announcements' => false, 'weekly_product_updates' => true, 'weekly_blog_digest' => false, ]); } }