From eb6c95c8625ca3af4d52a9edb3b49f065e542412 Mon Sep 17 00:00:00 2001 From: Vahn Gomes Date: Fri, 15 Sep 2023 18:23:08 -0400 Subject: [PATCH] Add PDCController with a generate method to generate a Pre-Departure Clearance (PDC) for a flight. --- .../Http/Controllers/API/PDCController.php | 77 +++++++++++++++++++ .../RequestBodies/PDC/GenerateRequestBody.php | 51 ++++++++++++ .../OpenApi/Responses/PDC/FailureResponse.php | 62 +++++++++++++++ .../OpenApi/Responses/PDC/SuccessResponse.php | 39 ++++++++++ src/routes/api.php | 7 ++ 5 files changed, 236 insertions(+) create mode 100644 src/app/Http/Controllers/API/PDCController.php create mode 100644 src/app/OpenApi/RequestBodies/PDC/GenerateRequestBody.php create mode 100644 src/app/OpenApi/Responses/PDC/FailureResponse.php create mode 100644 src/app/OpenApi/Responses/PDC/SuccessResponse.php diff --git a/src/app/Http/Controllers/API/PDCController.php b/src/app/Http/Controllers/API/PDCController.php new file mode 100644 index 0000000..325746b --- /dev/null +++ b/src/app/Http/Controllers/API/PDCController.php @@ -0,0 +1,77 @@ + '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); + } +} diff --git a/src/app/OpenApi/RequestBodies/PDC/GenerateRequestBody.php b/src/app/OpenApi/RequestBodies/PDC/GenerateRequestBody.php new file mode 100644 index 0000000..df23dd0 --- /dev/null +++ b/src/app/OpenApi/RequestBodies/PDC/GenerateRequestBody.php @@ -0,0 +1,51 @@ +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) + ); + } +} diff --git a/src/app/OpenApi/Responses/PDC/FailureResponse.php b/src/app/OpenApi/Responses/PDC/FailureResponse.php new file mode 100644 index 0000000..45f932b --- /dev/null +++ b/src/app/OpenApi/Responses/PDC/FailureResponse.php @@ -0,0 +1,62 @@ +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) + ); + } +} diff --git a/src/app/OpenApi/Responses/PDC/SuccessResponse.php b/src/app/OpenApi/Responses/PDC/SuccessResponse.php new file mode 100644 index 0000000..0fce2cd --- /dev/null +++ b/src/app/OpenApi/Responses/PDC/SuccessResponse.php @@ -0,0 +1,39 @@ +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) + ); + } +} diff --git a/src/routes/api.php b/src/routes/api.php index 446590c..4a30fc4 100644 --- a/src/routes/api.php +++ b/src/routes/api.php @@ -3,6 +3,7 @@ use App\Http\Controllers\API\HealthCheckController; use App\Http\Controllers\API\AirportController; use App\Http\Controllers\API\TextToSpeechController; +use App\Http\Controllers\API\PDCController; use Illuminate\Support\Facades\Route; /* @@ -50,4 +51,10 @@ // Delete atis audio file Route::delete('/', [TextToSpeechController::class, 'delete']); }); + + // PDC Generator + Route::prefix('pdc')->group(function () { + // Generate PDC + Route::post('/', [PDCController::class, 'generate'])->name('api.pdc.generate'); + }); });