-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69b364e
commit ec384f5
Showing
5 changed files
with
123 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Ushahidi/Modules/V5/Actions/Media/Commands/UpdateMediaCaptionCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Ushahidi\Modules\V5\Actions\Media\Commands; | ||
|
||
use App\Bus\Command\Command; | ||
use Ushahidi\Modules\V5\Models\Media; | ||
use Ushahidi\Modules\V5\Requests\MediaRequest; | ||
use Ushahidi\Core\Entity\Media as MediaEntity; | ||
use Illuminate\Support\Facades\Auth; | ||
use Ushahidi\Modules\V5\Helpers\ParameterUtilities; | ||
|
||
class UpdateMediaCaptionCommand implements Command | ||
{ | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $caption; | ||
|
||
/** | ||
* @var MediaEntity | ||
*/ | ||
private $media_entity; | ||
|
||
public function __construct( | ||
string $caption, | ||
Media $media | ||
) { | ||
// $this->id = $id; | ||
$input['id'] = $media->id; | ||
$input['user_id'] = $media->user_id; | ||
$input['caption'] = $caption; | ||
$input['mime'] = $media->mime; | ||
$input['o_filename'] = $media->o_filename; | ||
$input['o_size'] = $media->o_size; | ||
$input['o_width'] = $media->o_width; | ||
$input['o_height'] = $media->o_height; | ||
$input['created'] = strtotime($media->created); | ||
$input['updated'] = time(); | ||
|
||
$this->media_entity = new MediaEntity($input); | ||
} | ||
|
||
// public function getId(): int | ||
// { | ||
// return $this->id; | ||
// } | ||
public function getCaption(): string | ||
{ | ||
return $this->caption; | ||
} | ||
|
||
public function getMediaEntity(): MediaEntity | ||
{ | ||
return $this->media_entity; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Ushahidi/Modules/V5/Actions/Media/Handlers/UpdateMediaCaptionCommandHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Ushahidi\Modules\V5\Actions\Media\Handlers; | ||
|
||
use App\Bus\Action; | ||
use App\Bus\Command\AbstractCommandHandler; | ||
use App\Bus\Command\Command; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Ushahidi\Core\Exception\NotFoundException; | ||
use Ushahidi\Modules\V5\Models\Media; | ||
use Ushahidi\Modules\V5\Repository\Media\MediaRepository; | ||
use Ushahidi\Modules\V5\Actions\Media\Commands\UpdateMediaCaptionCommand; | ||
use Illuminate\Support\Facades\DB; | ||
use Ushahidi\Modules\V5\Models\MediaLock as Lock; | ||
|
||
class UpdateMediaCaptionCommandHandler extends AbstractCommandHandler | ||
{ | ||
private $media_repository; | ||
|
||
public function __construct(MediaRepository $media_repository) | ||
{ | ||
$this->media_repository = $media_repository; | ||
} | ||
|
||
protected function isSupported(Command $command): void | ||
{ | ||
if (!$command instanceof UpdateMediaCaptionCommand) { | ||
throw new \Exception('Provided $command is not instance of UpdateMediaCommand'); | ||
} | ||
} | ||
|
||
public function __invoke(Action $action) | ||
{ | ||
/** | ||
* @var UpdateMediaCaptionCommand $action | ||
*/ | ||
$this->isSupported($action); | ||
|
||
return $this->media_repository->update($action->getMediaEntity()->getId(), $action->getMediaEntity()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters