Skip to content

Commit e0b73b5

Browse files
committed
Job Simplification
1 parent 4c1e404 commit e0b73b5

File tree

6 files changed

+19
-66
lines changed

6 files changed

+19
-66
lines changed

app/Events/StatisticRequestedEvent.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

app/Http/Controllers/StatisticController.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace App\Http\Controllers;
44

55
use App\Services\StatisticService;
6-
use Illuminate\Support\Collection;
7-
use Illuminate\Support\Facades\App;
86
use App\Jobs\ProcessStatisticReport;
97
use App\Http\Resources\PaginatorResource;
108
use App\Http\Resources\StatisticResource;
@@ -14,17 +12,11 @@ class StatisticController extends Controller
1412
public function __construct(private StatisticService $statisticService)
1513
{}
1614

17-
private function makeReport(Collection $statistic)
18-
{
19-
return App::make('\Barryvdh\DomPDF\PDF')->loadView('statistic.report', ['stats' => $statistic]);
20-
}
21-
2215
public function index()
2316
{
24-
ProcessStatisticReport::dispatchAfterResponse(
25-
$statistic = $this->statisticService->index(request()->type),
26-
$this->makeReport($statistic->getCollection())->download()
27-
);
17+
$statistic = $this->statisticService->index(request()->type);
18+
19+
ProcessStatisticReport::dispatchAfterResponse($statistic);
2820

2921
return response()->success(new PaginatorResource(StatisticResource::class, $statistic));
3022
}

app/Jobs/ProcessStatisticReport.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,35 @@
22

33
namespace App\Jobs;
44

5+
use App\Models\User;
56
use Illuminate\Bus\Queueable;
7+
use Illuminate\Support\Facades\App;
68
use Illuminate\Queue\SerializesModels;
7-
use App\Events\StatisticRequestedEvent;
89
use Illuminate\Queue\InteractsWithQueue;
910
use Illuminate\Contracts\Queue\ShouldQueue;
1011
use Illuminate\Foundation\Bus\Dispatchable;
12+
use Illuminate\Database\Eloquent\Collection;
1113
use Illuminate\Pagination\LengthAwarePaginator;
14+
use App\Notifications\Statistic\StatisticReported;
1215

1316
class ProcessStatisticReport implements ShouldQueue
1417
{
1518
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
1619

17-
/**
18-
* Create a new job instance.
19-
*
20-
* @return void
21-
*/
22-
public function __construct(protected LengthAwarePaginator $statistic, protected mixed $report)
20+
public function __construct(protected LengthAwarePaginator $statistic)
2321
{}
2422

25-
/**
26-
* Execute the job.
27-
*
28-
* @return void
29-
*/
23+
private function makeReport(Collection $statistic)
24+
{
25+
return App::make('\Barryvdh\DomPDF\PDF')->loadView('statistic.report', ['stats' => $statistic]);
26+
}
27+
3028
public function handle()
3129
{
32-
event(new StatisticRequestedEvent($this->statistic, $this->report));
30+
User::auth()->notify(new StatisticReported(
31+
$this->statistic,
32+
$this->makeReport($this->statistic->getCollection())->download()
33+
));
3334
}
35+
3436
}

app/Listeners/SendStatisticReportListener.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

app/Providers/EventServiceProvider.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use App\Observers\CourseObserver;
1212
use App\Observers\CategoryObserver;
1313
use Illuminate\Auth\Events\Registered;
14-
use App\Events\StatisticRequestedEvent;
15-
use App\Listeners\SendStatisticReportListener;
1614
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
1715
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
1816

@@ -27,9 +25,6 @@ class EventServiceProvider extends ServiceProvider
2725
Registered::class => [
2826
SendEmailVerificationNotification::class,
2927
],
30-
StatisticRequestedEvent::class => [
31-
SendStatisticReportListener::class,
32-
],
3328
];
3429

3530
/**

resources/views/statistic/report.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<table class="pure-table pure-table-bordered">
55
<thead>
66
<tr>
7-
<th>#</th>
7+
<th>ID</th>
88
<th>Type</th>
99
<th>Record</th>
1010
<th>Statisticable</th>

0 commit comments

Comments
 (0)