mirror of
https://github.com/flarum/core.git
synced 2025-10-23 04:36:08 +02:00
Add delete avatar action
This commit is contained in:
47
src/Api/Actions/Users/DeleteAvatarAction.php
Normal file
47
src/Api/Actions/Users/DeleteAvatarAction.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php namespace Flarum\Api\Actions\Users;
|
||||
|
||||
use Flarum\Core\Commands\DeleteAvatarCommand;
|
||||
use Flarum\Api\Actions\SerializeResourceAction;
|
||||
use Flarum\Api\JsonApiRequest;
|
||||
use Flarum\Api\JsonApiResponse;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
|
||||
class DeleteAvatarAction extends SerializeResourceAction
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Bus\Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
/**
|
||||
* The name of the serializer class to output results with.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $serializer = 'Flarum\Api\Serializers\UserSerializer';
|
||||
|
||||
/**
|
||||
* Instantiate the action.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Bus\Dispatcher $bus
|
||||
*/
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user's avatar, and return the user ready to be serialized and
|
||||
* assigned to the JsonApi response.
|
||||
*
|
||||
* @param \Flarum\Api\JsonApiRequest $request
|
||||
* @param \Flarum\Api\JsonApiResponse $response
|
||||
* @return \Flarum\Core\Models\User
|
||||
*/
|
||||
protected function data(JsonApiRequest $request, JsonApiResponse $response)
|
||||
{
|
||||
return $this->bus->dispatch(
|
||||
new DeleteAvatarCommand($request->get('id'), $this->actor->getUser())
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user