Skip to content

Instantly share code, notes, and snippets.

@maxloncar
Last active November 11, 2022 11:53
Show Gist options
  • Save maxloncar/7dc5dc60d00380c9e0ca1132713056e3 to your computer and use it in GitHub Desktop.
Save maxloncar/7dc5dc60d00380c9e0ca1132713056e3 to your computer and use it in GitHub Desktop.
Creating a user
<?php
// src/User/Action/CreateUser.php
namespace App\User\Action;
use App\Core\REST\Action\AbstractApiAction;
use App\Core\REST\ValueObject\ApiResponse;
use App\Domain\User\Representation\UserRepresentation;
use App\User\Message\CreateUserMessage;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class CreateUser
*
* @package App\User\Action
* @author DEVŌT <devot.team>
*/
class CreateUser extends AbstractApiAction
{
/**
* Create new User
*
* @param Request $request
* @return ApiResponse
*/
#[Route('/user', name: 'api_v1_user', methods: ['POST'])]
public function __invoke(Request $request): ApiResponse
{
/** @var UserRepresentation $representation */
$representation = $this->handle(
CreateUserMessage::fromRequest($request)
);
return ApiResponse::created($representation);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment