Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DeleteErrorLogsAction | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |||
| 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\Domain\Exception\BadRequestException; |
| 9 | use App\Renderer\JsonRenderer; |
| 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 BadRequestException('ids array is required'); |
| 35 | } |
| 36 | |
| 37 | $ids = array_filter( |
| 38 | array_map(static fn(mixed $id): int => is_numeric($id) ? (int)$id : 0, $data['ids']), |
| 39 | static fn(int $id): bool => $id > 0, |
| 40 | ); |
| 41 | |
| 42 | if (count($ids) === 0) { |
| 43 | throw new BadRequestException('At least one valid ID is required'); |
| 44 | } |
| 45 | |
| 46 | $deletedCount = $this->errorLogService->delete($ids); |
| 47 | |
| 48 | return $this->renderer->json($response, [ |
| 49 | 'success' => true, |
| 50 | 'message' => "Deleted {$deletedCount} error log(s)", |
| 51 | 'data' => [ |
| 52 | 'deletedCount' => $deletedCount, |
| 53 | 'requestedCount' => count($ids), |
| 54 | ], |
| 55 | ]); |
| 56 | } |
| 57 | } |