Skip to content

Commit

Permalink
🐛 fix(TextToSpeechController.php): fix incorrect parameter name in in…
Browse files Browse the repository at this point in the history
…dex method

✨ feat(TextToSpeechController.php): add support for retrieving ATIS audio file by ID and ICAO code in index method
🔧 chore(TextToSpeechController.php): refactor generate method to use request parameters instead of method parameters
🔧 chore(TextToSpeechController.php): refactor delete method to remove unused parameter
✨ feat(GetTextToSpeechParameters.php): add GetTextToSpeechParameters class to handle query parameters for retrieving ATIS audio file
✨ feat(GetTextToSpeechRequestBody.php): add GetTextToSpeechRequestBody class to handle request body for retrieving ATIS audio file
✨ feat(ErrorGetTextToSpeechResponse.php): add ErrorGetTextToSpeechResponse class to handle error response for retrieving ATIS audio file
✨ feat(SuccessResponse.php): add SuccessResponse class to handle success response for retrieving ATIS audio file

🐛 fix(redbeard.js): add missing semicolons to improve code readability and prevent potential issues
✨ feat(redbeard.js): refactor API routes to use a prefix for better organization and readability
✨ feat(redbeard.js): add support for generating ATIS audio file using Text-to-Speech (TTS) functionality
✨ feat(redbeard.js): add support for deleting ATIS audio file generated using TTS functionality
  • Loading branch information
Vahn Gomes authored and Vahn Gomes committed Jul 21, 2023
1 parent e33b5ce commit d31c99a
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 65 deletions.
69 changes: 59 additions & 10 deletions src/app/Http/Controllers/API/TextToSpeechController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
use App\Http\Controllers\Controller;
use App\Models\ATISAudioFile;
use App\OpenApi\Parameters\GetAirportParameters;
use App\OpenApi\Parameters\GetTextToSpeechParameters;
use App\OpenApi\RequestBodies\TTS\GenerateRequestBody;
use App\OpenApi\RequestBodies\TTS\GetTextToSpeechRequestBody;
use App\OpenApi\Responses\TTS\ErrorGeneratingResponse;
use App\OpenApi\Responses\TTS\ErrorRequestConflictResponse;
use App\OpenApi\Responses\TTS\ErrorValidatingIcaoResponse;
use App\OpenApi\Responses\TTS\ErrorWithVoiceAPIResponse;
use App\OpenApi\Responses\TTS\SuccessResponse;
use App\OpenApi\Responses\TTS\GetTextToSpeech\ErrorGetTextToSpeechResponse;
use App\OpenApi\Responses\TTS\GetTextToSpeech\SuccessResponse as GetTextToSpeechSuccessResponse;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
Expand All @@ -25,15 +29,58 @@ class TextToSpeechController extends Controller
*
* Gets a link to a mp3 text-to-speech file for an airport and returns it in a JSON response.
*
* @param string $icao The ICAO code of the airport to generate the TTS for.
* @param Request $request
* @return void
* @return JsonResponse
*/
#[OpenApi\Operation(tags: ['Text to Speech'])]
#[OpenApi\Parameters(factory: GetAirportParameters::class)]
public function index(string $icao, Request $request): void
#[OpenApi\Parameters(factory: GetTextToSpeechParameters::class)]
#[OpenApi\Response(factory: ErrorValidatingIcaoResponse::class, statusCode: 400)]
#[OpenApi\Response(factory: ErrorGetTextToSpeechResponse::class, statusCode: 404)]
#[OpenApi\Response(factory: GetTextToSpeechSuccessResponse::class, statusCode: 200)]
public function index(Request $request): JsonResponse
{
// TODO: Get mp3 atis file and return link and id.
// Get the request parameters
$id = $request->id;
$icao = $request->icao;

// Validate the request
if (
!isset($icao) ||
!Helpers::validateIcao($icao)
) {
return response()->json([
'status' => 'error',
'message' => 'Invalid ICAO code.',
'code' => 400,
'data' => null
]);
}

// Get the ATIS audio file
$atis_file = ATISAudioFile::where('icao', $icao)->where('id', $id)->first();

// Check if the ATIS audio file exists
if ($atis_file == null || !$atis_file->exists()) {
return response()->json([
'status' => 'error',
'message' => 'ATIS audio file not found.',
'code' => 404,
'data' => null
]);
}

// Return the response
return response()->json([
'status' => 'success',
'message' => 'ATIS audio file found.',
'code' => 200,
'data' => [
'id' => $atis_file->id,
'name' => $atis_file->file_name,
'url' => $atis_file->url,
'expires_at' => $atis_file->expires_at,
]
]);
}

/**
Expand All @@ -53,8 +100,13 @@ public function index(string $icao, Request $request): void
#[OpenApi\Response(factory: ErrorWithVoiceAPIResponse::class, statusCode: 500)]
#[OpenApi\Response(factory: ErrorGeneratingResponse::class, statusCode: 422)]
#[OpenApi\Response(factory: SuccessResponse::class, statusCode: 200)]
public function generate(string $icao, Request $request): JsonResponse
public function generate(Request $request): JsonResponse
{
// Get the request parameters
$icao = $request->icao;
$atis = $request->atis;
$ident = $request->ident;

// Validate the request
if (!Helpers::validateIcao($icao)) {
return response()->json([
Expand All @@ -65,9 +117,6 @@ public function generate(string $icao, Request $request): JsonResponse
]);
}

$atis = $request->atis;
$ident = $request->ident;

// Check if the request has the required parameters, not using request()->validate() for now.
if (!isset($atis) || !isset($ident) || !isset($icao)) {
return response()->json([
Expand Down Expand Up @@ -201,7 +250,7 @@ public function generate(string $icao, Request $request): JsonResponse
*/
#[OpenApi\Operation(tags: ['Text to Speech'])]
#[OpenApi\Parameters(factory: GetAirportParameters::class)]
public function delete(string $icao, Request $request): void
public function delete(Request $request): void
{
// TODO: Delete mp3 atis file.
}
Expand Down
33 changes: 33 additions & 0 deletions src/app/OpenApi/Parameters/GetTextToSpeechParameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\OpenApi\Parameters;

use GoldSpecDigital\ObjectOrientedOAS\Objects\Parameter;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema;
use Vyuldashev\LaravelOpenApi\Factories\ParametersFactory;

class GetTextToSpeechParameters extends ParametersFactory
{
/**
* @return Parameter[]
*/
public function build(): array
{
return [

Parameter::query()
->name('icao')
->description('ICAO code of the airport')
->required(true)
->schema(Schema::string())
->example('KJAX'),
Parameter::query()
->name('id')
->description('ID of the ATIS audio file')
->required(true)
->schema(Schema::string())
->example('1'),

];
}
}
31 changes: 31 additions & 0 deletions src/app/OpenApi/RequestBodies/TTS/GetTextToSpeechRequestBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\OpenApi\RequestBodies\TTS;

use GoldSpecDigital\ObjectOrientedOAS\Objects\MediaType;
use GoldSpecDigital\ObjectOrientedOAS\Objects\RequestBody;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema;
use Vyuldashev\LaravelOpenApi\Factories\RequestBodyFactory;

class GetTextToSpeechRequestBody extends RequestBodyFactory
{
public function build(): RequestBody
{
$response = Schema::object()->properties(
Schema::string('id')
->example('1')
->description('The ID of the ATIS audio file.')
->required(),
Schema::string('icao')
->example('KJAX')
->description('The ICAO code of the airport.')
->required(),
);

return RequestBody::create('GetTextToSpeech')
->description('Get TTS file for an airport.')
->content(
MediaType::json()->schema($response)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\OpenApi\Responses\TTS\GetTextToSpeech;

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 ErrorGetTextToSpeechResponse extends ResponseFactory implements Reusable
{
public function build(): Response
{
$response = Schema::object()->properties(
Schema::string('status')->example('error'),
Schema::string('message')->example('ATIS audio file not found.'),
Schema::integer('code')->example(404),
Schema::object('data')->nullable()
);

return Response::create('TTSError', 'Error getting TTS file.')
->description('Error getting TTS file.')
->content(MediaType::json()->schema($response));
}
}
33 changes: 33 additions & 0 deletions src/app/OpenApi/Responses/TTS/GetTextToSpeech/SuccessResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\OpenApi\Responses\TTS\GetTextToSpeech;

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'),
Schema::string('message')->example('ATIS audio file found.'),
Schema::integer('code')->example(200),
Schema::object('data')->properties(
Schema::string('id')->example('1'),
Schema::string('name')->example('KJAX_ATIS_A_261700Z.mp3'),
Schema::string('url')->example('/storage/atis/1/KJAX_ATIS_A_261700Z.mp3'),
Schema::string('expires_at')->example('2021-01-01 00:00:00'),
)
);

return Response::create('GetTextToSpeechSuccess')
->description('Get TTS file for an airport.')
->content(
MediaType::json()->schema($response)
);
}
}
Loading

0 comments on commit d31c99a

Please sign in to comment.