| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Http\Controllers;
- use App\Http\Requests\NotificationRequest;
- use App\Http\Resources\NotificationResource;
- use App\Http\Resources\NotificationSendResource;
- use App\Services\NotificationService;
- use Illuminate\Http\JsonResponse;
- use Illuminate\Support\Facades\Auth;
- class NotificationController extends Controller
- {
- public function __construct(protected NotificationService $service) {}
- public function index(): JsonResponse
- {
- $items = $this->service->getAll();
- return $this->successResponse(payload: NotificationResource::collection($items));
- }
- public function store(NotificationRequest $request): JsonResponse
- {
- $item = $this->service->create($request->validated());
- return $this->successResponse(
- payload: new NotificationResource($item),
- message: __('messages.created'),
- code: 201,
- );
- }
- public function show(int $id): JsonResponse
- {
- $item = $this->service->findById($id);
- return $this->successResponse(payload: new NotificationResource($item));
- }
- public function destroy(int $id): JsonResponse
- {
- $this->service->delete($id);
- return $this->successResponse(message: __('messages.deleted'), code: 204);
- }
- public function myUnread(): JsonResponse
- {
- $items = $this->service->getUnreadByUser(Auth::id());
- return $this->successResponse(payload: NotificationSendResource::collection($items));
- }
- public function markAsRead(int $sendId): JsonResponse
- {
- $this->service->markAsRead($sendId, Auth::id());
- return $this->successResponse(message: __('messages.updated'));
- }
- }
|