Files
hoshpoint-backend/app/Http/Controllers/Api/NotificationController.php
soheil khaledabadi ae974c2afa 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
2026-07-07 01:03:12 +03:30

90 lines
3.4 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Resources\NotificationResource;
use App\Services\NotificationService;
use App\Traits\ApiResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use OpenApi\Attributes as OA;
class NotificationController extends Controller
{
use ApiResponse;
public function __construct(private readonly NotificationService $notificationService) {}
#[OA\Get(
path: '/notifications',
description: 'Get the authenticated user notifications',
summary: 'List notifications',
security: [['sanctum' => []]],
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('همه نوتیفیکیشن‌ها خوانده شد.');
}
}