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:
Jp
2026-02-16 01:22:00 +08:00
parent 3cf5f6db6a
commit e04689acca
4 changed files with 51 additions and 32 deletions

View 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);
}
}