accept/reject pireps in admin; cleanup and refactoring
This commit is contained in:
@@ -6,19 +6,25 @@ use App\Http\Requests\CreatePirepRequest;
|
||||
use App\Http\Requests\UpdatePirepRequest;
|
||||
use App\Repositories\AircraftRepository;
|
||||
use App\Repositories\PirepRepository;
|
||||
use App\Services\PIREPService;
|
||||
use Illuminate\Http\Request;
|
||||
use Flash;
|
||||
use Log;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
use Response;
|
||||
|
||||
class PirepController extends BaseController
|
||||
{
|
||||
private $pirepRepo, $aircraftRepo;
|
||||
private $pirepRepo, $aircraftRepo, $pirepSvc;
|
||||
|
||||
public function __construct(PirepRepository $pirepRepo, AircraftRepository $aircraftRepo)
|
||||
{
|
||||
public function __construct(
|
||||
AircraftRepository $aircraftRepo,
|
||||
PirepRepository $pirepRepo,
|
||||
PIREPService $pirepSvc
|
||||
) {
|
||||
$this->aircraftRepo = $aircraftRepo;
|
||||
$this->pirepRepo = $pirepRepo;
|
||||
$this->pirepSvc = $pirepSvc;
|
||||
}
|
||||
|
||||
public function aircraftList()
|
||||
@@ -43,7 +49,8 @@ class PirepController extends BaseController
|
||||
$criterea = new RequestCriteria($request);
|
||||
$this->pirepRepo->pushCriteria($criterea);
|
||||
|
||||
$pireps = $this->pirepRepo->orderBy('created_at', 'desc')
|
||||
$pireps = $this->pirepRepo
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate();
|
||||
|
||||
return view('admin.pireps.index', [
|
||||
@@ -53,7 +60,6 @@ class PirepController extends BaseController
|
||||
|
||||
/**
|
||||
* Show the form for creating a new Pirep.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create()
|
||||
@@ -77,7 +83,6 @@ class PirepController extends BaseController
|
||||
|
||||
/**
|
||||
* Display the specified Pirep.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
@@ -97,7 +102,6 @@ class PirepController extends BaseController
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified Pirep.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
@@ -139,9 +143,7 @@ class PirepController extends BaseController
|
||||
|
||||
/**
|
||||
* Remove the specified Pirep from storage.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
@@ -158,4 +160,23 @@ class PirepController extends BaseController
|
||||
Flash::success('Pirep deleted successfully.');
|
||||
return redirect(route('admin.pireps.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Change or update the PIREP status
|
||||
* @param Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function status(Request $request)
|
||||
{
|
||||
Log::info('PIREP status update call', [$request->toArray()]);
|
||||
|
||||
$pirep = $this->pirepRepo->findWithoutFail($request->id);
|
||||
if($request->isMethod('post')) {
|
||||
$new_status = (int) $request->new_status;
|
||||
$pirep = $this->pirepSvc->changeStatus($pirep, $new_status);
|
||||
}
|
||||
|
||||
$pirep->refresh();
|
||||
return view('admin.pireps.pirep_card', ['pirep' => $pirep]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user