Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature backend: adicionando .env.testing para aplicação #16

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions backend-api/.env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
APP_ENV=testing
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION=sqlite
DB_DATABASE=:memory:

CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_CONNECTION=sync
24 changes: 22 additions & 2 deletions backend-api/app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class TaskController extends Controller
public function index(Request $request): JsonResponse
{
$query = Task::with('user');

if ($request->has('search')) {
$search = $request->input('search');
$query->where('title', 'like', "%$search%");
}

$tasks = $query->paginate(10);
return response()->json($tasks, 200);
}
Expand Down Expand Up @@ -110,4 +110,24 @@ public function exportExcel(): BinaryFileResponse
return ExcelExportHelper::exportToExcel($tasks, TaskExport::class, 'tarefas.xlsx');
}

/**
* @param Request $request
* @return JsonResponse
*/
public function deleteMultiple(Request $request): JsonResponse
{
$tasks = $request->all();

if (!is_array($tasks) || empty($tasks)) {
return response()->json(['message' => 'Nenhuma tarefa foi informada'], 400);
}

$taskIds = array_column($tasks, 'id');

foreach ($tasks as $task) {
Task::whereIn('id', $taskIds)->delete();
}

return response()->json(['message' => 'Tarefas excluídas com sucesso'], 200);
}
}
65 changes: 65 additions & 0 deletions backend-api/app/Providers/TelescopeServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeApplicationServiceProvider;

class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
// Telescope::night();

$this->hideSensitiveRequestDetails();

Telescope::filter(function (IncomingEntry $entry) {
if ($this->app->environment('local')) {
return true;
}

return $entry->isReportableException() ||
$entry->isFailedRequest() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});
}

/**
* Prevent sensitive request details from being logged by Telescope.
*/
protected function hideSensitiveRequestDetails(): void
{
if ($this->app->environment('local')) {
return;
}

Telescope::hideRequestParameters(['_token']);

Telescope::hideRequestHeaders([
'cookie',
'x-csrf-token',
'x-xsrf-token',
]);
}

/**
* Register the Telescope gate.
*
* This gate determines who can access Telescope in non-local environments.
*/
protected function gate(): void
{
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
//
]);
});
}
}
1 change: 1 addition & 0 deletions backend-api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"laravel/framework": "^9.19",
"laravel/passport": "^11.10",
"laravel/sanctum": "^3.0",
"laravel/telescope": "*",
"laravel/tinker": "^2.7",
"laravel/ui": "^4.2",
"maatwebsite/excel": "^3.1"
Expand Down
73 changes: 72 additions & 1 deletion backend-api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend-api/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\TelescopeServiceProvider::class,

],

Expand All @@ -210,6 +211,7 @@

'aliases' => Facade::defaultAliases()->merge([
// 'ExampleClass' => App\Example\ExampleClass::class,
'Telescope' => Laravel\Telescope\TelescopeServiceProvider::class,
])->toArray(),

];
Loading
Loading