Перевод на доменную архитектуру
This commit is contained in:
56
app/Application/Reports/ReportSavePathService.php
Normal file
56
app/Application/Reports/ReportSavePathService.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Application\Reports;
|
||||
|
||||
use App\Application\Reports\DTO\GenerateReportResult;
|
||||
use App\Models\Department;
|
||||
use App\Models\Report;
|
||||
use App\Models\User;
|
||||
use App\Services\DateRange;
|
||||
use App\Services\ReportService;
|
||||
|
||||
final readonly class ReportSavePathService
|
||||
{
|
||||
public function __construct(
|
||||
private ReportFlowDecider $reportFlowDecider,
|
||||
private ReportInputFactory $reportInputFactory,
|
||||
private GenerateReportUseCase $generateReportUseCase,
|
||||
private ReportService $reportService,
|
||||
) {}
|
||||
|
||||
public function usesNewArchitecture(string $reportType = 'daily'): bool
|
||||
{
|
||||
return $this->reportFlowDecider->shouldUseNewArchitecture($reportType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $validated
|
||||
*/
|
||||
public function saveManual(User $actor, array $validated, string $reportType = 'daily'): GenerateReportResult|Report
|
||||
{
|
||||
if (! $this->usesNewArchitecture($reportType)) {
|
||||
return $this->reportService->storeReport($validated, $actor, false);
|
||||
}
|
||||
|
||||
return $this->generateReportUseCase->handle(
|
||||
$this->reportInputFactory->forManualSave($actor, $validated, $reportType)
|
||||
);
|
||||
}
|
||||
|
||||
public function saveAutoFill(
|
||||
User $scopedUser,
|
||||
Department $department,
|
||||
DateRange $dateRange,
|
||||
string $reportType = 'daily',
|
||||
): GenerateReportResult|Report {
|
||||
if (! $this->usesNewArchitecture($reportType)) {
|
||||
$payload = $this->reportService->buildAutoFillReportPayload($scopedUser, $department, $dateRange);
|
||||
|
||||
return $this->reportService->storeReport($payload, $scopedUser, true);
|
||||
}
|
||||
|
||||
return $this->generateReportUseCase->handle(
|
||||
$this->reportInputFactory->forAutoFill($scopedUser, $department, $dateRange, $reportType)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user