-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit post: Unable to specifically remove "Add caption" field for image (
#4686) * endpoint for media patch (caption only) * Modified to implement CQRS * cleaning out the lint
- Loading branch information
1 parent
a5dc0e7
commit 0ff0c29
Showing
6 changed files
with
137 additions
and
9 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
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