feat: initial commit
This commit is contained in:
10
app/Actions/BaseAction.php
Normal file
10
app/Actions/BaseAction.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
abstract class BaseAction
|
||||
{
|
||||
abstract public function __invoke(Data $payload, \Closure $next) ;
|
||||
}
|
||||
31
app/Actions/Branch/StoreBranch.php
Normal file
31
app/Actions/Branch/StoreBranch.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Branch;
|
||||
|
||||
use App\Actions\BaseAction;
|
||||
use App\Commands\Branches\CreateBranchCommand;
|
||||
use App\DataObjects\CreateBranchDTO;
|
||||
use Exception;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class StoreBranch extends BaseAction
|
||||
{
|
||||
|
||||
public function __construct(private CreateBranchCommand $createBranchCommand) {}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __invoke(CreateBranchDTO | Data $payload, \Closure $next)
|
||||
{
|
||||
try {
|
||||
|
||||
$payload->branch = $this->createBranchCommand->execute($payload->data);
|
||||
return $next($payload);
|
||||
|
||||
} catch (Exception $exception)
|
||||
{
|
||||
throw new \LogicException('Error Storing Branch: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
30
app/Actions/Branch/StoreBranchSeries.php
Normal file
30
app/Actions/Branch/StoreBranchSeries.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Branch;
|
||||
|
||||
use App\Actions\BaseAction;
|
||||
use App\Commands\Series\CreateSeriesCommand;
|
||||
use App\DataObjects\CreateBranchDTO;
|
||||
use App\DataObjects\CreateSeriesDTO;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class StoreBranchSeries extends BaseAction
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private CreateSeriesCommand $createSeriesCommand
|
||||
) {}
|
||||
|
||||
public function __invoke(CreateBranchDTO|Data $payload, \Closure $next)
|
||||
{
|
||||
try {
|
||||
$seriesPayload = CreateSeriesDTO::from(['branch_id' => $payload->branch->id, 'series' => $payload->data['series'], 'is_start' => true]);
|
||||
|
||||
$payload->series = $this->createSeriesCommand->execute($seriesPayload->toArray());
|
||||
|
||||
return $next($payload);
|
||||
} catch (\Exception $exception) {
|
||||
throw new \LogicException('Failed to create branch series', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
29
app/Actions/Transmittal/CreateTransmittal.php
Normal file
29
app/Actions/Transmittal/CreateTransmittal.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Transmittal;
|
||||
|
||||
use App\Actions\BaseAction;
|
||||
use App\Commands\Transmittal\StoreTransmittalCommand;
|
||||
use App\DataObjects\CreateTransmittalDTO;
|
||||
use Illuminate\Support\Arr;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class CreateTransmittal extends BaseAction
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private readonly StoreTransmittalCommand $storeTransmittalCommand
|
||||
) {}
|
||||
|
||||
public function __invoke(CreateTransmittalDTO | Data $payload, \Closure $next)
|
||||
{
|
||||
try {
|
||||
$payload->transmittal = $this->storeTransmittalCommand->execute(Arr::except($payload->data, ['files']));
|
||||
|
||||
return $next($payload);
|
||||
} catch (\Exception $exception)
|
||||
{
|
||||
throw new \LogicException('Error creating transmittal: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
63
app/Actions/Transmittal/CreateTransmittalFiles.php
Normal file
63
app/Actions/Transmittal/CreateTransmittalFiles.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Transmittal;
|
||||
|
||||
use App\Actions\BaseAction;
|
||||
use App\Commands\Transmittal\StoreCommentCommand;
|
||||
use App\Commands\Transmittal\StoreFileCommand;
|
||||
use App\Commands\Transmittal\StoreRemarkCommand;
|
||||
use App\DataObjects\CreateCommentDTO;
|
||||
use App\DataObjects\CreateFileDTO;
|
||||
use App\DataObjects\CreateRemarkDTO;
|
||||
use App\DataObjects\CreateTransmittalDTO;
|
||||
use Illuminate\Support\Arr;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class CreateTransmittalFiles extends BaseAction
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private readonly StoreFileCommand $storeFileCommand,
|
||||
private readonly StoreCommentCommand $storeCommentCommand,
|
||||
private readonly StoreRemarkCommand $storeRemarkCommand
|
||||
) {}
|
||||
|
||||
public function __invoke(CreateTransmittalDTO | Data $payload, \Closure $next)
|
||||
{
|
||||
try {
|
||||
$files = Arr::only($payload->data, 'files');
|
||||
$filesCreated = [];
|
||||
foreach ($files as $file) {
|
||||
|
||||
//save each file
|
||||
$filePayload = new CreateFileDTO(transmittal_id: $payload->transmittal->id, description: Arr::first($file)['description']);
|
||||
$fileCreated = $this->storeFileCommand->execute($filePayload->except('file')->toArray());
|
||||
|
||||
|
||||
$comments = Arr::first($file)['comments'];
|
||||
$remarks = Arr::first($file)['remarks'];
|
||||
|
||||
//save each comments of each file
|
||||
foreach ($comments as $key => $comment) {
|
||||
$commentPayload = new CreateCommentDTO(file_id: $fileCreated->id, comment: $comment['comment']);
|
||||
$this->storeCommentCommand->execute($commentPayload->except('commentModel')->toArray());
|
||||
}
|
||||
|
||||
//save each remarks of each file
|
||||
foreach ($remarks as $key => $remark) {
|
||||
$remarkPayload = new CreateRemarkDTO(file_id: $fileCreated->id, remark: $remark['remark']);
|
||||
$this->storeRemarkCommand->execute($remarkPayload->except('remarkModel')->toArray());
|
||||
}
|
||||
|
||||
$filesCreated[] = $fileCreated;
|
||||
}
|
||||
|
||||
$payload->files = $filesCreated;
|
||||
|
||||
return $next($payload);
|
||||
} catch (\Exception $exception)
|
||||
{
|
||||
throw new \LogicException('Error creating transmittal files: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user