Skip to content

Commit

Permalink
#23 refactoring for ranks
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Jun 21, 2017
1 parent 4f295ce commit cb63129
Show file tree
Hide file tree
Showing 22 changed files with 228 additions and 195 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<?php

namespace App\Http\Controllers;
namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use App\Http\Requests\CreateRankingRequest;
use App\Http\Requests\UpdateRankingRequest;
use App\Repositories\RankingRepository;
use App\Repositories\RankRepository;
use App\Http\Controllers\AppBaseController as InfyOmBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class RankingController extends InfyOmBaseController
class RankController extends BaseController
{
/** @var RankingRepository */
private $rankingRepository;
/** @var RankRepository */
private $rankRepository;

public function __construct(RankingRepository $rankingRepo)
public function __construct(RankRepository $rankingRepo)
{
$this->rankingRepository = $rankingRepo;
$this->rankRepository = $rankingRepo;
}

/**
Expand All @@ -30,11 +29,11 @@ public function __construct(RankingRepository $rankingRepo)
*/
public function index(Request $request)
{
$this->rankingRepository->pushCriteria(new RequestCriteria($request));
$rankings = $this->rankingRepository->all();
$this->rankRepository->pushCriteria(new RequestCriteria($request));
$ranks = $this->rankRepository->all();

return view('admin.rankings.index')
->with('rankings', $rankings);
return view('admin.ranks.index')
->with('ranks', $ranks);
}

/**
Expand All @@ -44,7 +43,7 @@ public function index(Request $request)
*/
public function create()
{
return view('admin.rankings.create');
return view('admin.ranks.create');
}

/**
Expand All @@ -57,12 +56,11 @@ public function create()
public function store(CreateRankingRequest $request)
{
$input = $request->all();

$ranking = $this->rankingRepository->create($input);
$rank = $this->rankRepository->create($input);

Flash::success('Ranking saved successfully.');

return redirect(route('admin.rankings.index'));
return redirect(route('admin.ranks.index'));
}

/**
Expand All @@ -74,15 +72,14 @@ public function store(CreateRankingRequest $request)
*/
public function show($id)
{
$ranking = $this->rankingRepository->findWithoutFail($id);
$rank = $this->rankRepository->findWithoutFail($id);

if (empty($ranking)) {
if (empty($rank)) {
Flash::error('Ranking not found');

return redirect(route('admin.rankings.index'));
return redirect(route('admin.ranks.index'));
}

return view('admin.rankings.show')->with('ranking', $ranking);
return view('admin.ranks.show')->with('rank', $rank);
}

/**
Expand All @@ -94,15 +91,14 @@ public function show($id)
*/
public function edit($id)
{
$ranking = $this->rankingRepository->findWithoutFail($id);
$rank = $this->rankRepository->findWithoutFail($id);

if (empty($ranking)) {
if (empty($rank)) {
Flash::error('Ranking not found');

return redirect(route('admin.rankings.index'));
return redirect(route('admin.ranks.index'));
}

return view('admin.rankings.edit')->with('ranking', $ranking);
return view('admin.ranks.edit')->with('rank', $rank);
}

/**
Expand All @@ -115,19 +111,18 @@ public function edit($id)
*/
public function update($id, UpdateRankingRequest $request)
{
$ranking = $this->rankingRepository->findWithoutFail($id);
$rank = $this->rankRepository->findWithoutFail($id);

if (empty($ranking)) {
if (empty($rank)) {
Flash::error('Ranking not found');

return redirect(route('admin.rankings.index'));
return redirect(route('admin.ranks.index'));
}

$ranking = $this->rankingRepository->update($request->all(), $id);
$rank = $this->rankRepository->update($request->all(), $id);

Flash::success('Ranking updated successfully.');

return redirect(route('admin.rankings.index'));
return redirect(route('admin.ranks.index'));
}

/**
Expand All @@ -139,18 +134,17 @@ public function update($id, UpdateRankingRequest $request)
*/
public function destroy($id)
{
$ranking = $this->rankingRepository->findWithoutFail($id);
$rank = $this->rankRepository->findWithoutFail($id);

if (empty($ranking)) {
if (empty($rank)) {
Flash::error('Ranking not found');

return redirect(route('admin.rankings.index'));
return redirect(route('admin.ranks.index'));
}

$this->rankingRepository->delete($id);
$this->rankRepository->delete($id);

Flash::success('Ranking deleted successfully.');

return redirect(route('admin.rankings.index'));
return redirect(route('admin.ranks.index'));
}
}
4 changes: 2 additions & 2 deletions app/Http/Requests/CreateRankingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Requests;

use App\Http\Requests\Request;
use App\Models\Ranking;
use App\Models\Rank;

class CreateRankingRequest extends Request
{
Expand All @@ -25,6 +25,6 @@ public function authorize()
*/
public function rules()
{
return Ranking::$rules;
return Rank::$rules;
}
}
4 changes: 2 additions & 2 deletions app/Http/Requests/UpdateRankingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Requests;

use App\Http\Requests\Request;
use App\Models\Ranking;
use App\Models\Rank;

class UpdateRankingRequest extends Request
{
Expand All @@ -25,6 +25,6 @@ public function authorize()
*/
public function rules()
{
return Ranking::$rules;
return Rank::$rules;
}
}
4 changes: 2 additions & 2 deletions app/Models/Ranking.php → app/Models/Rank.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
* Class Ranking
* @package App\Models
*/
class Ranking extends Model
class Rank extends Model
{

public $table = 'rankings';
public $table = 'ranks';

public $fillable = [
'name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

namespace App\Repositories;

use App\Models\Ranking;
use App\Models\Rank;
use InfyOm\Generator\Common\BaseRepository;

class RankingRepository extends BaseRepository
class RankRepository extends BaseRepository
{
/**
* @var array
*/
protected $fieldSearchable = [

];

/**
* Configure the Model
**/
public function model()
{
return Ranking::class;
return Rank::class;
}
}
1 change: 1 addition & 0 deletions database/migrations/2017_06_08_0000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function up()
$table->string('email')->unique();
$table->string('password');
$table->integer('airline_id')->nullable()->unsigned();
$table->integer('rank_id')->nullable()->unsigned();
$table->integer('home_airport_id')->nullable()->unsigned();
$table->integer('curr_airport_id')->nullable()->unsigned();
$table->bigInteger('last_pirep_id')->nullable()->unsigned();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateRankingsTable extends Migration
class CreateRanksTable extends Migration
{

/**
Expand All @@ -13,7 +13,7 @@ class CreateRankingsTable extends Migration
*/
public function up()
{
Schema::create('rankings', function (Blueprint $table) {
Schema::create('ranks', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('hours')->default(0);
Expand All @@ -22,6 +22,14 @@ public function up()
$table->boolean('auto_promote')->default(true);
$table->timestamps();
});

Schema::create('flight_rank', function(Blueprint $table) {
$table->increments('id');
$table->integer('flight_id')->unsigned();
$table->integer('rank_id')->unsigned();
$table->double('manual_pay', 19, 2)->default(0.0)->unsigned();
$table->double('acars_pay', 19, 2)->default(0.0)->unsigned();
});
}

/**
Expand All @@ -31,6 +39,7 @@ public function up()
*/
public function down()
{
Schema::drop('rankings');
Schema::drop('ranks');
Schema::drop('flight_rank');
}
}
2 changes: 1 addition & 1 deletion database/seeds/DevelopmentSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function time(): string
return Carbon::now('UTC')->format('Y-m-d H:i:s');
}

protected function seed_from_yaml(): void
protected function seed_from_yaml():
{
$time_fields = ['created_at', 'updated_at'];

Expand Down
1 change: 1 addition & 0 deletions resources/views/admin/menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
<li><a href="{!! url('/admin/airports') !!}"><i class="fa fa-globe"></i>&nbsp;airports</a></li>
{{--<li><a href="{!! url('/admin/aircraftclasses') !!}"><i class="fa fa-tag"></i>&nbsp;aircraft classes</a></li>--}}
<li><a href="#"><i class="fa fa-user-circle-o" aria-hidden="true"></i>&nbsp;users</a></li>
<li><a href="{!! url('/admin/ranks') !!}"><i class="fa fa-user-circle-o" aria-hidden="true"></i>&nbsp;ranks</a></li>
24 changes: 0 additions & 24 deletions resources/views/admin/rankings/create.blade.php

This file was deleted.

35 changes: 0 additions & 35 deletions resources/views/admin/rankings/fields.blade.php

This file was deleted.

23 changes: 0 additions & 23 deletions resources/views/admin/rankings/index.blade.php

This file was deleted.

Loading

0 comments on commit cb63129

Please sign in to comment.