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
This commit is contained in:
89
app/Http/Controllers/Api/NotificationController.php
Normal file
89
app/Http/Controllers/Api/NotificationController.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?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('همه نوتیفیکیشنها خوانده شد.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user