Everyone who may comment on a task sends images to it, e.g. photos taken with a phone. The server stores an upright, at most 2560 px JPEG without EXIF data (no location) and a 400 px thumbnail on the private disk, served only to those who see the job. Uploaders change captions (also the alt text) and remove their own images; admin and management may remove anyone's (jobs.remove-any-task-image). Removing a task also removes its image files. Livewire's temporary upload limit is raised to PHP's 40 MB so that the page's own 12 MB limit gives a translated message. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Jobs\Application\Services;
|
|
|
|
use App\Modules\Jobs\Domain\Contracts\TaskImageRepository;
|
|
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
|
use App\Modules\Jobs\Domain\Entities\TaskImage;
|
|
use App\Modules\Jobs\Domain\Exceptions\TaskImageNotFound;
|
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
|
|
|
/**
|
|
* Finds an image only through its task and the task's job, so a page of
|
|
* one job never changes another job's images.
|
|
*/
|
|
final readonly class TaskImageFinder
|
|
{
|
|
public function __construct(
|
|
private TaskRepository $tasks,
|
|
private TaskImageRepository $images,
|
|
) {}
|
|
|
|
/**
|
|
* @throws TaskNotFound
|
|
* @throws TaskImageNotFound
|
|
*/
|
|
public function find(int $jobId, int $taskId, int $imageId): TaskImage
|
|
{
|
|
$this->ensureTask($jobId, $taskId);
|
|
|
|
return $this->images->findForTask($taskId, $imageId) ?? throw new TaskImageNotFound($taskId, $imageId);
|
|
}
|
|
|
|
/**
|
|
* @throws TaskNotFound
|
|
*/
|
|
public function ensureTask(int $jobId, int $taskId): void
|
|
{
|
|
if ($this->tasks->findForJob($jobId, $taskId) === null) {
|
|
throw new TaskNotFound($jobId, $taskId);
|
|
}
|
|
}
|
|
}
|