Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DeleteErrorLogsAction | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\SuperAdmin; |
| 6 | |
| 7 | use App\Domain\ErrorLog\Service\ErrorLogService; |
| 8 | use App\Renderer\JsonRenderer; |
| 9 | use InvalidArgumentException; |
| 10 | use Psr\Http\Message\ResponseInterface; |
| 11 | use Psr\Http\Message\ServerRequestInterface; |
| 12 | |
| 13 | /** |
| 14 | * Delete error logs by IDs (bulk delete). |
| 15 | */ |
| 16 | final readonly class DeleteErrorLogsAction |
| 17 | { |
| 18 | private ErrorLogService $errorLogService; |
| 19 | |
| 20 | private JsonRenderer $renderer; |
| 21 | |
| 22 | public function __construct(ErrorLogService $errorLogService, JsonRenderer $renderer) |
| 23 | { |
| 24 | $this->errorLogService = $errorLogService; |
| 25 | $this->renderer = $renderer; |
| 26 | } |
| 27 | |
| 28 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 29 | { |
| 30 | $data = (array)$request->getParsedBody(); |
| 31 | |
| 32 | // Validate IDs |
| 33 | if (!isset($data['ids']) || !is_array($data['ids'])) { |
| 34 | throw new InvalidArgumentException('ids array is required'); |
| 35 | } |
| 36 | |
| 37 | $ids = array_filter(array_map('intval', $data['ids']), static fn($id) => $id > 0); |
| 38 | |
| 39 | if (count($ids) === 0) { |
| 40 | throw new InvalidArgumentException('At least one valid ID is required'); |
| 41 | } |
| 42 | |
| 43 | $deletedCount = $this->errorLogService->delete($ids); |
| 44 | |
| 45 | return $this->renderer->json($response, [ |
| 46 | 'success' => true, |
| 47 | 'message' => "Deleted {$deletedCount} error log(s)", |
| 48 | 'data' => [ |
| 49 | 'deletedCount' => $deletedCount, |
| 50 | 'requestedCount' => count($ids), |
| 51 | ], |
| 52 | ]); |
| 53 | } |
| 54 | } |