tries to add api requests

This commit is contained in:
unurled 2025-07-05 10:22:33 +02:00
parent e841c38573
commit 73c32b4fb6
26 changed files with 962 additions and 39 deletions

View file

@ -10,6 +10,7 @@ use App\Models\User;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
@ -201,19 +202,23 @@ class TournamentController extends Controller
->with('success', 'Tournament deleted successfully!');
}
public function addTeam(Competition $tournament, Request $request)
public function addTeam(Request $request, Competition $tournament)
{
Log::info($request);
// Check if user is tournament owner
if ($tournament->owner != Auth::id()) {
Log::error('User is not authorized to add a team to this tournament.');
Log::error('userId: ' . Auth::id() . ' tournamentOwnerId: ' . $tournament->owner);
return redirect()->back()->with('error', 'You are not authorized to add a team to this tournament.');
}
// Validate the request data
$validator = Validator::make($request->all(), [
'team_id' => 'required|exists:teams,id',
'teamName' => 'required|exists:teams,string',
]);
if ($validator->fails()) {
Log::error('Validation failed for addTeam', $validator->errors());
return redirect()->back()->withErrors($validator)->withInput();
}
@ -228,9 +233,8 @@ class TournamentController extends Controller
}
$tournament->teams()->attach($team->id);
return redirect()->route('tournaments.show', $tournament->id)
->with('success', 'Team added successfully!');
return response()->json([
'tournament' => $tournament,
]);
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ApiCreateUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$rules = [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'unique:users', 'max:255'],
'password' => ['required', 'string', 'min:8', 'max:255', 'confirmed'],
];
return $rules;
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ApiLoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$rules = [
'email' => ['required', 'email', 'max:255'],
'password' => ['required', 'min:8'],
];
return $rules;
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'email_verified_at' => $this->email_verified_at,
];
}
}

View file

@ -6,11 +6,12 @@ use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable, HasUuids;
use HasApiTokens, HasFactory, Notifiable, HasUuids;
/**
* The attributes that are mass assignable.

View file

@ -0,0 +1,64 @@
<?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();
$isLocal = $this->app->environment('local');
Telescope::filter(function (IncomingEntry $entry) use ($isLocal) {
return $isLocal ||
$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, [
'unurled@unurled.me'
]);
});
}
}