Last active
November 11, 2022 11:53
-
-
Save maxloncar/7dc5dc60d00380c9e0ca1132713056e3 to your computer and use it in GitHub Desktop.
Creating a user
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
<?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