-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* StyleCI (#9) * Add CI Status To Readme (#12) * Arrival holds (#31) * Fix #14 Essex Frequency (#15) Fix ESSEX_APP frequency in controller positions * Fix #13 EGSS NUGBO Initial Altitudes (#16) They were the wrong way round * Add Migration For Hold Table * Add Hold Model * Start Migration For Adding Holds * Add Seeder For Holds * Hide Timestamps From Model JSON * Add Service For Processing Hold Data * Add Controller For Hold Retrieval * Spacing * Create Hold Restrictions Table * Model For Hold Restrictions * Add Relation For Hold Restrictions * Add Seeder For New Table * Return Restrictions With Holds * Require JSON Extension In Composer * Add Additional Holds * Start Adding Hold Restrictions * Fix Seed * HoldRestriction Casts Its Restriction To Array So that it is usable and nice JSON * Frequency updates (#23) * Add Missing CCAMS Ranges (#25) * Tweak Tests * Add Hold Profile Table * Add User Hold Profile Table * Add HoldProfile Model * Add HoldProfileUser Model * Add Database Seeder * Update Schema * Add Tables Linking Holds To Hold Profiles * Combine Tables * Add Holds Relation * Add Table Comments * Hold Profile Add HasManyThrough Relation * Add Service Methods For Getting Hold Profiles * Add Cascade Foreign Keys On Migrations * Add Methods To Manipulate Hold Profiles Creating, deleting and updating * Hold Controller Can Return Generic Hold Profiles * HoldController Can Return User Hold Profiles * Controller Can Delete User Profiles * HoldController Can Create Profiles * HoldController Can Update Hold Profiles * Fix #23: Solent Doesnt Exist (#28) Add SOLENT_APP to controller positions and airfield ownership. * Merge Develop Changes To Master (#29) * StyleCI (#9) * Add CI Status To Readme (#12) * Fix #32: Add Redhill Squawks (#33) * HoldProfile Appends Whether User Profile So we can easily tell profiles apart, it uses its user_id property to determine whether or not the profile is generic or user specific. * Remove Notion Of Generic Profiles It's probably easier to let people just create their own. * Style * AIRAC 2019/03 (#35) * Tweak ROSUN level * Hold Profile Names No Longer Need To Be Unique * Return Hold Profile Holds Properly * PSR * Add More Holds * Add More Holds * Fix Hold Description For SABER * Add Three Basic Hold Profiles For All Users
- Loading branch information
1 parent
04366b8
commit 62523e6
Showing
23 changed files
with
2,073 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Services\HoldService; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class HoldController extends BaseController | ||
{ | ||
/** | ||
* @var HoldService | ||
*/ | ||
private $holdService; | ||
|
||
/** | ||
* @param HoldService $holdService | ||
*/ | ||
public function __construct(HoldService $holdService) | ||
{ | ||
$this->holdService = $holdService; | ||
} | ||
|
||
/** | ||
* Return the hold data as JSON | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function getAllHolds() : JsonResponse | ||
{ | ||
return response()->json($this->holdService->getHolds())->setStatusCode(200); | ||
} | ||
|
||
/** | ||
* Get all the hold profiles pertaining to a user | ||
* | ||
* @return JsonResponse | ||
*/ | ||
public function getUserHoldProfiles() : JsonResponse | ||
{ | ||
return response()->json($this->holdService->getUserHoldProfiles())->setStatusCode(200); | ||
} | ||
|
||
/** | ||
* Delete the given user hold profile | ||
* | ||
* @param int $holdProfileId Profile to delete | ||
* @return Response|\Laravel\Lumen\Http\ResponseFactory | ||
*/ | ||
public function deleteUserHoldProfile(int $holdProfileId) : Response | ||
{ | ||
$this->holdService->deleteUserHoldProfile($holdProfileId); | ||
return response('', 204); | ||
} | ||
|
||
/** | ||
* Creates the given user hold profile | ||
* | ||
* @param Request $request | ||
* @return JsonResponse | ||
*/ | ||
public function createUserHoldProfile(Request $request) : JsonResponse | ||
{ | ||
$invalidRequest = $this->checkForSuppliedData( | ||
$request, | ||
[ | ||
'name' => 'string|required', | ||
'holds' => 'array|required', | ||
] | ||
); | ||
|
||
if ($invalidRequest) { | ||
return $invalidRequest; | ||
} | ||
|
||
$holdsValid = array_reduce( | ||
$request->json('holds'), | ||
function ($carry, $hold) { | ||
return $carry && is_integer($hold); | ||
}, | ||
true | ||
); | ||
|
||
if (!$holdsValid) { | ||
Log::error('Invalid holds submitted'); | ||
return response()->json(null)->setStatusCode(400); | ||
} | ||
|
||
$createdProfile = $this->holdService->createUserHoldProfile($request->json('name'), $request->json('holds')); | ||
return response()->json(['id' => $createdProfile->id])->setStatusCode(201); | ||
} | ||
|
||
/** | ||
* Creates the given user hold profile | ||
* | ||
* @param Request $request | ||
* @param int $profileId | ||
* @return JsonResponse | ||
*/ | ||
public function updateUserHoldProfile(Request $request, int $profileId) : JsonResponse | ||
{ | ||
$invalidRequest = $this->checkForSuppliedData( | ||
$request, | ||
[ | ||
'name' => 'string|required', | ||
'holds' => 'array|required', | ||
] | ||
); | ||
|
||
if ($invalidRequest) { | ||
return $invalidRequest; | ||
} | ||
|
||
$holdsValid = array_reduce( | ||
$request->json('holds'), | ||
function ($carry, $hold) { | ||
return $carry && is_integer($hold); | ||
}, | ||
true | ||
); | ||
|
||
if (!$holdsValid) { | ||
Log::error('Invalid holds submitted'); | ||
return response()->json(null)->setStatusCode(400); | ||
} | ||
|
||
$this->holdService->updateUserHoldProfile($profileId, $request->json('name'), $request->json('holds')); | ||
return response()->json(null)->setStatusCode(204); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
namespace App\Models\Hold; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* Model for a hold | ||
* | ||
* Class Hold | ||
* @package App\Models\Squawks | ||
*/ | ||
class Hold extends Model | ||
{ | ||
protected $table = 'hold'; | ||
|
||
public $timestamps = true; | ||
|
||
protected $hidden = [ | ||
'created_at', | ||
'updated_at', | ||
]; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'fix', | ||
'inbound_heading', | ||
'minimum_altitude', | ||
'maximum_altitude', | ||
'turn_direction', | ||
'description', | ||
]; | ||
|
||
/** | ||
* Relationship between a hold and its restrictions | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\HasMany | ||
*/ | ||
public function restrictions() | ||
{ | ||
return $this->hasMany(HoldRestriction::class, 'hold_id', 'id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Models\Hold; | ||
|
||
use App\Models\User\User; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
/** | ||
* Model for a hold profile | ||
* | ||
* Class HoldProfile | ||
* @package App\Models\Squawks | ||
*/ | ||
class HoldProfile extends Model | ||
{ | ||
protected $table = 'hold_profile'; | ||
|
||
public $timestamps = true; | ||
|
||
protected $hidden = [ | ||
'created_at', | ||
'updated_at', | ||
'user_id', | ||
'hold_profile_hold', | ||
]; | ||
|
||
protected $appends = [ | ||
'holds' | ||
]; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'name', | ||
'user_id', | ||
]; | ||
|
||
/** | ||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough | ||
*/ | ||
public function getHoldsAttribute() | ||
{ | ||
return $this->holdProfileHold->pluck('hold_id')->toArray(); | ||
} | ||
|
||
/** | ||
* @return HasMany | ||
*/ | ||
public function holdProfileHold() : HasMany | ||
{ | ||
return $this->hasMany(HoldProfileHold::class); | ||
} | ||
|
||
/** | ||
* @return BelongsTo | ||
*/ | ||
public function user() : BelongsTo | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
namespace App\Models\Hold; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\HasOne; | ||
|
||
/** | ||
* Model for a hold profile | ||
* | ||
* Class HoldProfile | ||
* @package App\Models\Squawks | ||
*/ | ||
class HoldProfileHold extends Model | ||
{ | ||
protected $table = 'hold_profile_hold'; | ||
|
||
public $timestamps = false; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'hold_profile_id', | ||
'hold_id', | ||
]; | ||
|
||
/** | ||
* @return HasOne | ||
*/ | ||
public function hold() : HasOne | ||
{ | ||
return $this->hasOne(Hold::class); | ||
} | ||
|
||
/** | ||
* @return BelongsTo | ||
*/ | ||
public function profile() : BelongsTo | ||
{ | ||
return $this->belongsTo(HoldProfile::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace App\Models\Hold; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* Model for a restriction on a hold | ||
* | ||
* Class HoldRestriction | ||
* @package App\Models\Hold | ||
*/ | ||
class HoldRestriction extends Model | ||
{ | ||
protected $table = 'hold_restriction'; | ||
|
||
public $timestamps = true; | ||
|
||
protected $hidden = [ | ||
'created_at', | ||
'updated_at', | ||
]; | ||
|
||
protected $casts = [ | ||
'restriction' => 'array', | ||
]; | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'hold_id', | ||
'restriction', | ||
]; | ||
} |
Oops, something went wrong.