From 9706114289ebe734ff02f41577e88ac74ba06085 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 1 Dec 2017 10:53:33 -0600 Subject: [PATCH] Caching & search configuration in repository classes --- .../Controllers/Admin/PirepController.php | 24 +++++++------------ app/Repositories/AircraftRepository.php | 17 ++++--------- app/Repositories/AirlineRepository.php | 8 +------ app/Repositories/AirportRepository.php | 15 ++---------- app/Repositories/BaseRepository.php | 9 +++++++ app/Repositories/FareRepository.php | 21 +++++++--------- app/Repositories/FlightRepository.php | 6 ----- app/Repositories/PirepFieldRepository.php | 8 +------ app/Repositories/PirepRepository.php | 12 ++++------ app/Repositories/RankRepository.php | 8 +------ app/Repositories/SubfleetRepository.php | 15 ++++++------ app/Repositories/UserRepository.php | 17 ++++++------- 12 files changed, 56 insertions(+), 104 deletions(-) diff --git a/app/Http/Controllers/Admin/PirepController.php b/app/Http/Controllers/Admin/PirepController.php index ea7ac4ac..c8aa493b 100644 --- a/app/Http/Controllers/Admin/PirepController.php +++ b/app/Http/Controllers/Admin/PirepController.php @@ -34,18 +34,16 @@ class PirepController extends BaseController } /** - * Display a listing of the Pirep. - * * @param Request $request - * @return Response + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + * @throws \Prettus\Repository\Exceptions\RepositoryException */ public function index(Request $request) { $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', [ @@ -64,11 +62,9 @@ class PirepController extends BaseController } /** - * Store a newly created Pirep in storage. - * * @param CreatePirepRequest $request - * - * @return Response + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function store(CreatePirepRequest $request) { @@ -83,7 +79,6 @@ class PirepController extends BaseController * Display the specified Pirep. * * @param int $id - * * @return Response */ public function show($id) @@ -104,7 +99,6 @@ class PirepController extends BaseController * Show the form for editing the specified Pirep. * * @param int $id - * * @return Response */ public function edit($id) @@ -123,12 +117,10 @@ class PirepController extends BaseController } /** - * Update the specified Pirep in storage. - * - * @param int $id + * @param $id * @param UpdatePirepRequest $request - * - * @return Response + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function update($id, UpdatePirepRequest $request) { diff --git a/app/Repositories/AircraftRepository.php b/app/Repositories/AircraftRepository.php index cc45122b..4ef3cc87 100644 --- a/app/Repositories/AircraftRepository.php +++ b/app/Repositories/AircraftRepository.php @@ -10,19 +10,12 @@ class AircraftRepository extends BaseRepository implements CacheableInterface { use CacheableRepository; - /** - * @var array - */ - protected $fieldSearchable - = [ - 'name', - 'registration', - 'active', - ]; + protected $fieldSearchable = [ + 'name' => 'like', + 'registration' => 'like', + 'active', + ]; - /** - * Configure the Model - **/ public function model() { return Aircraft::class; diff --git a/app/Repositories/AirlineRepository.php b/app/Repositories/AirlineRepository.php index 423ddaf7..8a526ba1 100644 --- a/app/Repositories/AirlineRepository.php +++ b/app/Repositories/AirlineRepository.php @@ -11,17 +11,11 @@ class AirlineRepository extends BaseRepository implements CacheableInterface { use CacheableRepository; - /** - * @var array - */ protected $fieldSearchable = [ 'code', - 'name' + 'name' => 'like', ]; - /** - * Configure the Model - **/ public function model() { return Airline::class; diff --git a/app/Repositories/AirportRepository.php b/app/Repositories/AirportRepository.php index d1d23002..fa14ba4d 100644 --- a/app/Repositories/AirportRepository.php +++ b/app/Repositories/AirportRepository.php @@ -11,24 +11,13 @@ class AirportRepository extends BaseRepository implements CacheableInterface { use CacheableRepository; - /** - * @var array - */ protected $fieldSearchable = [ - 'icao' + 'icao', + 'name' => 'like', ]; - /** - * Configure the Model - **/ public function model() { return Airport::class; } - - public function create(array $attributes) - { - //$attributes['id'] = $attributes['icao']; - return parent::create($attributes); - } } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 9af49388..9febf83c 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -7,6 +7,11 @@ use Illuminate\Validation\Validator; abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepository { + /** + * @param $id + * @param array $columns + * @return mixed|void + */ public function findWithoutFail($id, $columns = ['*']) { try { @@ -16,6 +21,10 @@ abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepositor } } + /** + * @param $values + * @return bool + */ public function validate($values) { $validator = Validator::make( diff --git a/app/Repositories/FareRepository.php b/app/Repositories/FareRepository.php index 88a96a43..71c0b56a 100644 --- a/app/Repositories/FareRepository.php +++ b/app/Repositories/FareRepository.php @@ -3,24 +3,19 @@ namespace App\Repositories; use App\Models\Fare; +use Prettus\Repository\Contracts\CacheableInterface; +use Prettus\Repository\Traits\CacheableRepository; -class FareRepository extends BaseRepository +class FareRepository extends BaseRepository implements CacheableInterface { - /** - * @var array - */ + use CacheableRepository; + protected $fieldSearchable = [ - 'code', - 'name', - 'price', - 'cost', - 'notes', - 'active' + 'code' => 'like', + 'name' => 'like', + 'notes' => 'like', ]; - /** - * Configure the Model - **/ public function model() { return Fare::class; diff --git a/app/Repositories/FlightRepository.php b/app/Repositories/FlightRepository.php index 4840bdce..0b36caf3 100644 --- a/app/Repositories/FlightRepository.php +++ b/app/Repositories/FlightRepository.php @@ -10,9 +10,6 @@ class FlightRepository extends BaseRepository implements CacheableInterface { use CacheableRepository; - /** - * @var array - */ protected $fieldSearchable = [ 'arr_airport_id', 'dpt_airport_id', @@ -21,9 +18,6 @@ class FlightRepository extends BaseRepository implements CacheableInterface 'notes' => 'like', ]; - /** - * Configure the Model - **/ public function model() { return Flight::class; diff --git a/app/Repositories/PirepFieldRepository.php b/app/Repositories/PirepFieldRepository.php index 7f8710e6..546f0bb5 100644 --- a/app/Repositories/PirepFieldRepository.php +++ b/app/Repositories/PirepFieldRepository.php @@ -6,16 +6,10 @@ use App\Models\PirepField; class PirepFieldRepository extends BaseRepository { - /** - * @var array - */ protected $fieldSearchable = [ - 'name' + 'name' => 'like', ]; - /** - * Configure the Model - **/ public function model() { return PirepField::class; diff --git a/app/Repositories/PirepRepository.php b/app/Repositories/PirepRepository.php index a67514df..88e4ee5a 100644 --- a/app/Repositories/PirepRepository.php +++ b/app/Repositories/PirepRepository.php @@ -4,19 +4,17 @@ namespace App\Repositories; use App\Models\Pirep; use App\Models\User; +use Prettus\Repository\Contracts\CacheableInterface; +use Prettus\Repository\Traits\CacheableRepository; -class PirepRepository extends BaseRepository +class PirepRepository extends BaseRepository implements CacheableInterface { - /** - * @var array - */ + use CacheableRepository; + protected $fieldSearchable = [ 'user_id' ]; - /** - * Configure the Model - **/ public function model() { return Pirep::class; diff --git a/app/Repositories/RankRepository.php b/app/Repositories/RankRepository.php index 961f43ec..bfbac8a0 100644 --- a/app/Repositories/RankRepository.php +++ b/app/Repositories/RankRepository.php @@ -10,16 +10,10 @@ class RankRepository extends BaseRepository implements CacheableInterface { use CacheableRepository; - /** - * @var array - */ protected $fieldSearchable = [ - + 'name' => 'like', ]; - /** - * Configure the Model - **/ public function model() { return Rank::class; diff --git a/app/Repositories/SubfleetRepository.php b/app/Repositories/SubfleetRepository.php index 943be299..178268a4 100644 --- a/app/Repositories/SubfleetRepository.php +++ b/app/Repositories/SubfleetRepository.php @@ -3,19 +3,18 @@ namespace App\Repositories; use App\Models\Subfleet; +use Prettus\Repository\Contracts\CacheableInterface; +use Prettus\Repository\Traits\CacheableRepository; -class SubfleetRepository extends BaseRepository +class SubfleetRepository extends BaseRepository implements CacheableInterface { - /** - * @var array - */ - protected $fieldSearchable = [ + use CacheableRepository; + protected $fieldSearchable = [ + 'name' => 'like', + 'type' => 'like', ]; - /** - * Configure the Model - **/ public function model() { return Subfleet::class; diff --git a/app/Repositories/UserRepository.php b/app/Repositories/UserRepository.php index 86a7712f..f2ffd41c 100644 --- a/app/Repositories/UserRepository.php +++ b/app/Repositories/UserRepository.php @@ -2,19 +2,20 @@ namespace App\Repositories; use App\Models\User; +use Prettus\Repository\Contracts\CacheableInterface; +use Prettus\Repository\Traits\CacheableRepository; -class UserRepository extends BaseRepository +class UserRepository extends BaseRepository implements CacheableInterface { - /** - * @var array - */ + use CacheableRepository; + protected $fieldSearchable = [ - 'email' + 'name' => 'like', + 'email' => 'like', + 'home_airport_id', + 'curr_airport_id', ]; - /** - * Configure the Model - **/ public function model() { return User::class;