refactor(sales): replace service with command and action pattern
- Replace SaleService with CreateSaleCommand and CreateSaleAction for better separation of concerns - Move sale creation logic into dedicated command class following command pattern - Update CreateSale.php to use new action instead of direct service call - Wrap sale creation in database transaction for data consistency
This commit is contained in:
22
app/Actions/Sales/CreateSaleAction.php
Normal file
22
app/Actions/Sales/CreateSaleAction.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Sales;
|
||||
|
||||
use App\Commands\Sales\CreateSaleCommand;
|
||||
use App\Models\Sale;
|
||||
|
||||
class CreateSaleAction
|
||||
{
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct(private CreateSaleCommand $createSaleCommand)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function __invoke(array $data): Sale
|
||||
{
|
||||
return $this->createSaleCommand->execute($data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user