Closed pdt256 closed 7 years ago
Commands are much less complex:
$tagId = $request->input('tagId');
$productId = $request->input('productId');
try {
$this->dispatch(new AddTagToProductCommand(
$productId,
$tagId
));
$this->flashSuccess('Successfully added product');
} catch (KommerceException $e) {
$this->flashError('Unable to add product');
}
Classes required:
Before:
public function index(Request $httpRequest)
{
$queryString = $httpRequest->query('q');
$request = new ListWarehousesRequest(
$queryString,
$this->getPaginationDTO(20)
);
$response = new ListWarehousesResponse();
$this->dispatchQuery(new ListWarehousesQuery($request, $response));
$warehouses = $response->getWarehouseDTOs();
$pagination = $response->getPaginationDTO();
return $this->renderTemplate(
'@admin/inventory/warehouse/index.twig',
[
'warehouses' => $warehouses,
'pagination' => $pagination,
'queryString' => $queryString,
]
);
}
After:
public function index(Request $httpRequest)
{
$queryString = $httpRequest->query('q');
/** @var ListWarehousesResponse $response */
$response = $this->dispatchQuery(new ListWarehousesQuery(
$queryString,
$this->getPaginationDTO(20)
));
$warehouses = $response->getWarehouseDTOs();
$pagination = $response->getPaginationDTO();
return $this->renderTemplate(
'@admin/inventory/warehouse/index.twig',
[
'warehouses' => $warehouses,
'pagination' => $pagination,
'queryString' => $queryString,
]
);
}
37 to refactor:
$ find . -name *Query.php
Refactoring is really easy. Around 3 minutes per Query:
Code from the video: https://github.com/inklabs/kommerce-core/commit/66ddaf1f5876d713e21765f55e52e8ea4fa9ec7a
Merged to master via #110
Do you have any ideas how to reduce the complexity?
The current way to get a ProductDTO:
The classes required to satisfy the request:
GetProductQuery GetProductRequest GetProductResponseInterface GetProductResponse GetProductHandler
The GetProductHandler defers to the ProductService:
The ProductService defers to the ProductRepository:
The ProductRepository defers to the Doctrine EntityRepository: