-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from VMGWARE/2-feature-pdc-pre-departure-clear…
…ance-generator-option Feature: Add PDCController with a generate method to generate Pre-Departure Clearances (PDC)
- Loading branch information
Showing
5 changed files
with
236 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Validator; | ||
use Vyuldashev\LaravelOpenApi\Attributes as OpenApi; | ||
use App\Custom\Helpers; | ||
|
||
#[OpenApi\PathItem] | ||
class PDCController extends Controller | ||
{ | ||
|
||
/** | ||
* Generate a Pre-Departure Clearance (PDC) for a flight. | ||
* | ||
* This endpoint generates a PDC for a flight based on the provided parameters. | ||
* | ||
* @param Request $request An instance of the HTTP request which should contain both 'icao' and 'id' parameters. | ||
* @return JsonResponse A JSON response. It can be: | ||
* 1. A success response with the generated PDC. | ||
* 2. An error response indicating an error with the request. | ||
*/ | ||
#[OpenApi\Operation(tags: ['Miscellaneous'])] | ||
#[OpenApi\RequestBody(factory: \App\OpenApi\RequestBodies\PDC\GenerateRequestBody::class)] | ||
#[OpenApi\Response(factory: \App\OpenApi\Responses\PDC\FailureResponse::class, statusCode: 400)] | ||
#[OpenApi\Response(factory: \App\OpenApi\Responses\PDC\SuccessResponse::class, statusCode: 200)] | ||
public function generate(Request $request) | ||
{ | ||
// Define validation rules for the request data | ||
$rules = [ | ||
'callsign' => 'required|string', | ||
'departure' => 'required|string', | ||
'arrival' => 'required|string', | ||
'route' => 'required|string', | ||
'aircraft' => 'required|string', | ||
'altitude' => 'required|string', | ||
'squawk' => 'required|string', | ||
'departure_time' => 'required|date_format:Y-m-d\TH:i:s\Z', | ||
'remarks' => 'nullable|string', | ||
]; | ||
|
||
// Validate the request data | ||
$validator = Validator::make($request->all(), $rules); | ||
|
||
// Check if validation fails | ||
if ($validator->fails()) { | ||
return Helpers::response('Validation failed', ['error' => $validator->errors()], 400); | ||
} | ||
|
||
// Get request data | ||
$callsign = $request->input('callsign'); | ||
$departure = $request->input('departure'); | ||
$arrival = $request->input('arrival'); | ||
$route = $request->input('route'); | ||
$aircraft = $request->input('aircraft'); | ||
$altitude = $request->input('altitude'); | ||
$squawk = $request->input('squawk'); | ||
$departure_time = $request->input('departure_time'); | ||
$remarks = $request->input('remarks'); | ||
|
||
// Build PDC | ||
$pdc = "PDC FOR $callsign\n"; | ||
$pdc .= "DEPARTING $departure\n"; | ||
$pdc .= "ARRIVING $arrival\n"; | ||
$pdc .= "VIA $route\n"; | ||
$pdc .= "AIRCRAFT $aircraft\n"; | ||
$pdc .= "ALTITUDE $altitude\n"; | ||
$pdc .= "SQUAWK $squawk\n"; | ||
$pdc .= "DEPARTURE TIME $departure_time\n"; | ||
$pdc .= "REMARKS $remarks\n"; | ||
$pdc .= "END PDC"; | ||
|
||
return Helpers::response('PDC generated successfully', ['pdc' => $pdc], 200); | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace App\OpenApi\RequestBodies\PDC; | ||
|
||
use GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType; | ||
use GoldSpecDigital\ObjectOrientedOAS\Objects\RequestBody; | ||
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema; | ||
use Vyuldashev\LaravelOpenApi\Factories\RequestBodyFactory; | ||
|
||
class GenerateRequestBody extends RequestBodyFactory | ||
{ | ||
public function build(): RequestBody | ||
{ | ||
// Define the schema for the request body | ||
$response = Schema::object()->properties( | ||
Schema::string('callsign') | ||
->example('AAL123') | ||
->description('The callsign of the flight.'), | ||
Schema::string('departure') | ||
->example('KJAX') | ||
->description('The departure airport ICAO code.'), | ||
Schema::string('arrival') | ||
->example('KDFW') | ||
->description('The arrival airport ICAO code.'), | ||
Schema::string('route') | ||
->example('JAX5 J14 MEI J17 MEM J6 PLESS J180 CYN') | ||
->description('The route of the flight.'), | ||
Schema::string('aircraft') | ||
->example('B737') | ||
->description('The aircraft type.'), | ||
Schema::string('altitude') | ||
->example('FL350') | ||
->description('The altitude of the flight.'), | ||
Schema::string('squawk') | ||
->example('1234') | ||
->description('The squawk code of the flight.'), | ||
Schema::string('departure_time') | ||
->example('2023-09-15T14:00:00Z') | ||
->description('The departure time of the flight in ISO 8601 format.'), | ||
Schema::string('remarks') | ||
->example('VIP onboard, special meal requests') | ||
->description('Any remarks for the flight.'), | ||
); | ||
|
||
return RequestBody::create('GeneratePDC') | ||
->description('Generate a Pre-Departure Clearance (PDC) for a flight.') | ||
->content( | ||
MediaType::json()->schema($response) | ||
); | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
namespace App\OpenApi\Responses\PDC; | ||
|
||
use GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType; | ||
use GoldSpecDigital\ObjectOrientedOAS\Objects\Response; | ||
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema; | ||
use Vyuldashev\LaravelOpenApi\Factories\ResponseFactory; | ||
use Vyuldashev\LaravelOpenApi\Contracts\Reusable; | ||
|
||
class FailureResponse extends ResponseFactory implements Reusable | ||
{ | ||
public function build(): Response | ||
{ | ||
$response = Schema::object()->properties( | ||
Schema::string('status') | ||
->example('error') | ||
->enum('success', 'error') | ||
->description('The status of the response indicating the success or failure of the operation.'), | ||
Schema::string('message') | ||
->example('Validation failed') | ||
->description('A human-readable message providing additional information about the status.'), | ||
Schema::integer('code') | ||
->example(200) | ||
->description('An optional status code for the response. It typically indicates the HTTP status code.'), | ||
Schema::object('data')->properties( | ||
Schema::object('error')->properties( | ||
Schema::string('callsign') | ||
->example('The callsign field is required.') | ||
->description('The error message for the callsign field.'), | ||
Schema::string('departure') | ||
->example('The departure field is required.') | ||
->description('The error message for the departure field.'), | ||
Schema::string('arrival') | ||
->example('The arrival field is required.') | ||
->description('The error message for the arrival field.'), | ||
Schema::string('route') | ||
->example('The route field is required.') | ||
->description('The error message for the route field.'), | ||
Schema::string('aircraft') | ||
->example('The aircraft field is required.') | ||
->description('The error message for the aircraft field.'), | ||
Schema::string('altitude') | ||
->example('The altitude field is required.') | ||
->description('The error message for the altitude field.'), | ||
Schema::string('squawk') | ||
->example('The squawk field is required.') | ||
->description('The error message for the squawk field.'), | ||
Schema::string('departure_time') | ||
->example('The departure time field is required.') | ||
->description('The error message for the departure time field.'), | ||
) | ||
) | ||
); | ||
|
||
return Response::create('FailedGeneratePDC') | ||
->description('Failed to generate a Pre-Departure Clearance (PDC) for a flight.') | ||
->content( | ||
MediaType::json()->schema($response) | ||
); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace App\OpenApi\Responses\PDC; | ||
|
||
use GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType; | ||
use GoldSpecDigital\ObjectOrientedOAS\Objects\Response; | ||
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema; | ||
use Vyuldashev\LaravelOpenApi\Factories\ResponseFactory; | ||
use Vyuldashev\LaravelOpenApi\Contracts\Reusable; | ||
|
||
class SuccessResponse extends ResponseFactory implements Reusable | ||
{ | ||
public function build(): Response | ||
{ | ||
$response = Schema::object()->properties( | ||
Schema::string('status') | ||
->example('success') | ||
->enum('success', 'error') | ||
->description('The status of the response indicating the success or failure of the operation.'), | ||
Schema::string('message') | ||
->example('PDC generated successfully') | ||
->description('A human-readable message providing additional information about the status.'), | ||
Schema::integer('code') | ||
->example(200) | ||
->description('An optional status code for the response. It typically indicates the HTTP status code.'), | ||
Schema::object('data')->properties( | ||
Schema::string('pdc') | ||
->example('PDC FOR AAL123\nDEPARTING KJAX\nARRIVING KDFW\nVIA JAX5 J14 MEI J17 MEM J6 PLESS J180 CYN\nAIRCRAFT B737\nALTITUDE FL350\nSQUAWK 1234\nDEPARTURE TIME 2023-09-15T14:00:00Z\nREMARKS VIP onboard, special meal requests\nEND PDC') | ||
->description('The generated PDC.'), | ||
) | ||
); | ||
|
||
return Response::create('GeneratePDC') | ||
->description('Generate a Pre-Departure Clearance (PDC) for a flight.') | ||
->content( | ||
MediaType::json()->schema($response) | ||
); | ||
} | ||
} |
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