Add different PIREP and User events
This commit is contained in:
23
app/Events/PirepAccepted.php
Normal file
23
app/Events/PirepAccepted.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Pirep;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
|
||||
class PirepAccepted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $pirep;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(Pirep $pirep)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
20
app/Events/PirepFiled.php
Normal file
20
app/Events/PirepFiled.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Pirep;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
|
||||
class PirepFiled
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $pirep;
|
||||
|
||||
public function __construct(Pirep $pirep)
|
||||
{
|
||||
$this->pirep = $pirep;
|
||||
}
|
||||
}
|
||||
20
app/Events/PirepRejected.php
Normal file
20
app/Events/PirepRejected.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Pirep;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
|
||||
class PirepRejected
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $pirep;
|
||||
|
||||
public function __construct(Pirep $pirep)
|
||||
{
|
||||
$this->pirep = $pirep;
|
||||
}
|
||||
}
|
||||
20
app/Events/UserAccepted.php
Normal file
20
app/Events/UserAccepted.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
|
||||
class UserAccepted
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $user;
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
20
app/Events/UserRegistered.php
Normal file
20
app/Events/UserRegistered.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
|
||||
class UserRegistered
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $user;
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
20
app/Events/UserStateChanged.php
Normal file
20
app/Events/UserStateChanged.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
|
||||
class UserStateChanged
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $user;
|
||||
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\AircraftClass;
|
||||
use Dompdf\Exception;
|
||||
|
||||
class AircraftService extends BaseService
|
||||
{
|
||||
|
||||
public function create(
|
||||
array $attributes
|
||||
) {
|
||||
|
||||
$repo = app('App\Repositories\SubfleetRepository');
|
||||
try {
|
||||
$model = $repo->create($attributes);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*if ($class != null) {
|
||||
$model->class()->associate($class);
|
||||
$model->save();
|
||||
}*/
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,10 @@ namespace App\Services;
|
||||
use App\Models\Pirep;
|
||||
use App\Models\PirepFieldValues;
|
||||
|
||||
use App\Events\PirepAccepted;
|
||||
use App\Events\PirepFiled;
|
||||
use App\Events\PirepRejected;
|
||||
use App\Events\UserStateChanged;
|
||||
|
||||
class PIREPService extends BaseService
|
||||
{
|
||||
@@ -40,10 +44,6 @@ class PIREPService extends BaseService
|
||||
$default_status = $pirep->pilot->rank->auto_approve_manual;
|
||||
}
|
||||
|
||||
if ($default_status == config('enums.pirep_status.ACCEPTED')) {
|
||||
$pirep = $this->accept($pirep);
|
||||
}
|
||||
|
||||
$pirep->save();
|
||||
$pirep->refresh();
|
||||
|
||||
@@ -56,6 +56,12 @@ class PIREPService extends BaseService
|
||||
$v->save();
|
||||
}
|
||||
|
||||
event(new PirepFiled($pirep));
|
||||
|
||||
if ($default_status == config('enums.pirep_status.ACCEPTED')) {
|
||||
$pirep = $this->accept($pirep);
|
||||
}
|
||||
|
||||
# only update the pilot last state if they are accepted
|
||||
if ($default_status == config('enums.pirep_status.ACCEPTED')) {
|
||||
$this->setPilotState($pirep);
|
||||
@@ -128,6 +134,8 @@ class PIREPService extends BaseService
|
||||
|
||||
$this->setPilotState($pirep);
|
||||
|
||||
event(new PirepAccepted($pirep));
|
||||
|
||||
return $pirep;
|
||||
}
|
||||
|
||||
@@ -154,6 +162,8 @@ class PIREPService extends BaseService
|
||||
$pirep->save();
|
||||
$pirep->refresh();
|
||||
|
||||
event(new PirepRejected($pirep));
|
||||
|
||||
return $pirep;
|
||||
}
|
||||
|
||||
@@ -163,14 +173,7 @@ class PIREPService extends BaseService
|
||||
$pilot->curr_airport_id = $pirep->arr_airport_id;
|
||||
$pilot->last_pirep_id = $pirep->id;
|
||||
$pilot->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate all of the finances for a PIREP
|
||||
* @param Pirep $pirep
|
||||
*/
|
||||
public function calculateFinances(Pirep &$pirep)
|
||||
{
|
||||
|
||||
event(new UserStateChanged($pilot));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Events\UserRegistered;
|
||||
use App\Models\User;
|
||||
use App\Models\Rank;
|
||||
use App\Models\Role;
|
||||
|
||||
use App\Events\UserStateChanged;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
@@ -17,6 +21,8 @@ class PilotService extends BaseService
|
||||
$pilot->flights = $pilot->flights + $count;
|
||||
$pilot->save();
|
||||
|
||||
event(new UserStateChanged($pilot));
|
||||
|
||||
return $pilot;
|
||||
}
|
||||
|
||||
@@ -26,6 +32,8 @@ class PilotService extends BaseService
|
||||
$pilot->flight_time = $pilot->flight_time + $hours;
|
||||
$pilot->save();
|
||||
|
||||
event(new UserStateChanged($pilot));
|
||||
|
||||
return $pilot;
|
||||
}
|
||||
|
||||
@@ -52,6 +60,8 @@ class PilotService extends BaseService
|
||||
|
||||
$pilot->save();
|
||||
|
||||
event(new UserStateChanged($pilot));
|
||||
|
||||
return $pilot;
|
||||
}
|
||||
|
||||
@@ -68,6 +78,8 @@ class PilotService extends BaseService
|
||||
$user->attachRole($role);
|
||||
# Let's check their rank
|
||||
$this->calculatePilotRank($user);
|
||||
|
||||
event(new UserRegistered($user));
|
||||
# TODO: Send out an email
|
||||
|
||||
# Looking good, let's return their information
|
||||
|
||||
@@ -130,9 +130,5 @@ class AircraftTest extends TestCase
|
||||
$this->markTestSkipped(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
return true;
|
||||
# missing the name field
|
||||
$svc = app('App\Services\AircraftService');
|
||||
$svc->create(['icao' => $this->ICAO]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user