add use cases to Carrier Controller
get all and create carrier
This commit is contained in:
parent
6776dc6291
commit
13c2464f95
1 changed files with 22 additions and 1 deletions
|
|
@ -2,20 +2,41 @@
|
|||
|
||||
namespace FreightQuote\Carrier;
|
||||
|
||||
use FreightQuote\Carrier\UseCases\CreateCarrier;
|
||||
use FreightQuote\Carrier\UseCases\CreateCarrierRequest;
|
||||
use FreightQuote\Carrier\UseCases\GetAllCarriers;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Slim\Views\Twig;
|
||||
|
||||
class CarrierController
|
||||
{
|
||||
public function __construct(
|
||||
private CarrierRepository $carrierRepo,
|
||||
) {}
|
||||
|
||||
public function page(Request $request, Response $response): Response
|
||||
{
|
||||
$twig = Twig::fromRequest($request);
|
||||
|
||||
return $twig->render($response, 'carriers.html.twig');
|
||||
$useCase = new GetAllCarriers($this->carrierRepo);
|
||||
$result = $useCase->execute();
|
||||
|
||||
return $twig->render($response, 'carriers.html.twig', [
|
||||
'carriers' => $result,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request, Response $response): Response
|
||||
{
|
||||
$body = $request->getParsedBody();
|
||||
$dto = new CreateCarrierRequest(
|
||||
$body['email'],
|
||||
$body['companyName'],
|
||||
);
|
||||
$useCase = new CreateCarrier($dto, $this->carrierRepo);
|
||||
$useCase->execute();
|
||||
|
||||
return $response->withHeader('Location', '/freight_carriers')->withStatus(303);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue