* command and user actions added
* language model added
This commit is contained in:
37
src/App/Action/User/PostAction.php
Normal file
37
src/App/Action/User/PostAction.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Action\User;
|
||||
|
||||
use App\Action\AbstractFormAction;
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Zend\Diactoros\Response\JsonResponse;
|
||||
|
||||
class PostAction extends AbstractFormAction
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityServiceInterface
|
||||
*/
|
||||
private $entityService;
|
||||
|
||||
public function __construct(EntityServiceInterface $entityService)
|
||||
{
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
|
||||
{
|
||||
$data = $this->getRequestData($request);
|
||||
|
||||
$result = $this->entityService->create($data);
|
||||
|
||||
if (false === $result) {
|
||||
$result = new JsonResponse(false);
|
||||
return $result->withStatus(500, 'Failed to insert record.');
|
||||
}
|
||||
|
||||
return new JsonResponse($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user