Skip to content

Commit

Permalink
Removed the admin tasks from routes and added them as a Command
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Nov 22, 2024
1 parent 4adf222 commit 180ddaf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
52 changes: 52 additions & 0 deletions app/Console/Commands/TestAdminTasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Console\Commands;

use App\Models\User\User;
use App\Notifications\UserRegistered;
use App\Utils\Translator;
use Illuminate\Console\Command;

class TestAdminTasks extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:test-admin-tasks';

/**
* The console command description.
*
* @var string
*/
protected $description = 'This command is used to test the availability of some tasks, like the external translation service and the emailing service.';

/**
* Execute the console command.
*/
public function handle() {
$task = $this->choice('Which task would you like to test?', ['Translate service', 'Test email', 'Test Sentry error']);

if ($task === 'Translate service') {
$this->info('Testing the translation service...');
$texts = ['Hello', 'How are you?', 'Good morning'];
$lang_code = 'fr';
$translations = Translator::translateTexts($texts, $lang_code);
$this->info('Translations:');
foreach ($translations as $translation) {
$this->info($translation);
}
$this->info('API Key: ' . config('app.google_translate_key'));
} elseif ($task === 'Test email') {
$this->info('Testing the email service...');
$email = $this->ask('Enter the email address to send the test email to:');
User::where(['email' => $email])->first()->notify(new UserRegistered);
$this->info('The test email has been sent to ' . $email);
} elseif ($task === 'Test Sentry error') {
$this->info('Testing the Sentry error reporting service...');
$message = $this->ask('Enter the message for the Sentry error:');
throw new \Exception('Test Sentry error: ' . $message);
}
}
}
11 changes: 5 additions & 6 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
use App\Http\Controllers\Solution\SolutionController;
use App\Http\Controllers\User\AdminController;
use App\Http\Controllers\User\UserController;
use App\Models\User\User;
use App\Notifications\UserRegistered;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

Expand Down Expand Up @@ -68,9 +65,11 @@
Route::get('/communication/mailchimp', [CommunicationController::class, 'getMailChimpIntegration'])->name('mailchimp-integration.get');
Route::post('/communication/mailchimp', [CommunicationController::class, 'storeMailChimpListsIds'])->name('mailchimp-integration');
});
Route::get('/test-sentry/{message}', fn (Request $request) => throw new Exception('Test Sentry error: ' . $request->message));
Route::get('/phpinfo', fn () => phpinfo());
Route::get('/test-email/{email}', fn (Request $request) => User::where(['email' => $request->email])->first()->notify(new UserRegistered) && 'Success! Email sent to: ' . $request->email);
Route::middleware(['throttle:api-public'])->group(function () {
Route::group(['prefix' => 'admin'], function () {
Route::get('/phpinfo', fn () => phpinfo());
});
});
});

Route::group(['middleware' => ['auth', 'can:manage-platform-content']], function () use ($localeInfo, $backOfficePrefix) {
Expand Down

0 comments on commit 180ddaf

Please sign in to comment.