feat : indentation
This commit is contained in:
parent
4a29522f49
commit
da3068f95e
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
enum HuntStatus : string
|
||||
enum HuntStatus: string
|
||||
{
|
||||
case DRAFT = 'draft';
|
||||
case PUBLISHED = 'published';
|
||||
|
|
|
|||
|
|
@ -2,28 +2,27 @@
|
|||
|
||||
namespace App\Filament\Resources\Hunts;
|
||||
|
||||
use App\Enums\HuntDifficulty;
|
||||
use App\Enums\HuntStatus;
|
||||
use App\Enums\UserRole;
|
||||
use App\Filament\Resources\Hunts\Pages\CreateHunts;
|
||||
use App\Filament\Resources\Hunts\Pages\EditHunts;
|
||||
use App\Filament\Resources\Hunts\Pages\ListHunts;
|
||||
use App\Models\Hunts;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use App\Enums\HuntStatus;
|
||||
use Filament\Schemas\Schema;
|
||||
use BackedEnum;
|
||||
use App\Enums\HuntDifficulty;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Enums\UserRole;
|
||||
|
||||
class HuntsResource extends Resource
|
||||
{
|
||||
|
|
@ -37,6 +36,7 @@ class HuntsResource extends Resource
|
|||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected static ?string $model = Hunts::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-map';
|
||||
|
|
@ -56,20 +56,20 @@ class HuntsResource extends Resource
|
|||
Select::make('difficulty')
|
||||
->options(HuntDifficulty::class)
|
||||
->required(),
|
||||
TextInput::make('slug')
|
||||
->required(),
|
||||
Forms\Components\FileUpload::make('image')
|
||||
->image()
|
||||
->disk('public')
|
||||
->directory('hunts'),
|
||||
TextInput::make('city')
|
||||
TextInput::make('slug')
|
||||
->required(),
|
||||
Forms\Components\FileUpload::make('image')
|
||||
->image()
|
||||
->disk('public')
|
||||
->directory('hunts'),
|
||||
TextInput::make('city')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
DateTimePicker::make('start_at'),
|
||||
DateTimePicker::make('end_at'),
|
||||
TextInput::make('latitude')
|
||||
TextInput::make('latitude')
|
||||
->numeric(),
|
||||
TextInput::make('longitude')
|
||||
TextInput::make('longitude')
|
||||
->numeric(),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
namespace App\Filament\Resources\Hunts\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,18 +2,17 @@
|
|||
|
||||
namespace App\Filament\Resources\Hunts\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class StepsRelationManager extends RelationManager
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,6 @@ class CreateUser extends CreateRecord
|
|||
protected function afterCreate(): void
|
||||
{
|
||||
$record = $this->getRecord();
|
||||
\Illuminate\Support\Facades\Log::info('Filament CreateUser: User ' . $record->id . ' created. avatar_uri: ' . $record->avatar_uri);
|
||||
\Illuminate\Support\Facades\Log::info('Filament CreateUser: User '.$record->id.' created. avatar_uri: '.$record->avatar_uri);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,6 @@ class EditUser extends EditRecord
|
|||
protected function afterSave(): void
|
||||
{
|
||||
$record = $this->getRecord();
|
||||
\Illuminate\Support\Facades\Log::info('Filament EditUser: User ' . $record->id . ' updated. avatar_uri: ' . $record->avatar_uri);
|
||||
\Illuminate\Support\Facades\Log::info('Filament EditUser: User '.$record->id.' updated. avatar_uri: '.$record->avatar_uri);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
namespace App\Filament\Resources\Users\Schemas;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserForm
|
||||
{
|
||||
|
|
@ -48,7 +48,7 @@ class UserForm
|
|||
->image()
|
||||
->avatar()
|
||||
->disk('public')
|
||||
->directory('avatars')
|
||||
->directory('avatars'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ use Filament\Actions\DeleteBulkAction;
|
|||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\ImageColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ class AuthController extends Controller
|
|||
$avatar_uri = null;
|
||||
|
||||
if ($request->hasFile('avatar')) {
|
||||
$filename = \Illuminate\Support\Str::uuid() . '.jpg';
|
||||
$path = $request->file('avatar')->storeAs('avatars', $filename, 'public');
|
||||
$avatar_uri = $path;
|
||||
$filename = \Illuminate\Support\Str::uuid().'.jpg';
|
||||
$path = $request->file('avatar')->storeAs('avatars', $filename, 'public');
|
||||
$avatar_uri = $path;
|
||||
}
|
||||
|
||||
$user = User::create([
|
||||
|
|
@ -87,7 +87,8 @@ class AuthController extends Controller
|
|||
'message' => __('auth.logout_success'),
|
||||
]);
|
||||
}
|
||||
/**
|
||||
|
||||
/**
|
||||
* Determine the token name to use for the access token.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
|
|
@ -103,7 +104,7 @@ class AuthController extends Controller
|
|||
{
|
||||
$user = $request->user(); // ou $request->user('sanctum')
|
||||
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return response()->json(['message' => 'Unauthenticated.'], 401);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\HuntSteps;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HuntStepsController extends Controller
|
||||
{
|
||||
/**
|
||||
|
|
@ -54,17 +51,17 @@ class HuntStepsController extends Controller
|
|||
// 1. Check participation
|
||||
$participation = $user->participations()->where('hunt_id', $hunt->id)->first();
|
||||
|
||||
if (!$participation) {
|
||||
if (! $participation) {
|
||||
return response()->json(['message' => 'Not participating in this hunt'], 403);
|
||||
}
|
||||
|
||||
// 2. Check if this is the current step
|
||||
if ($participation->pivot->current_step_number !== $step->step_number) {
|
||||
return response()->json(['message' => 'This is not your current step'], 400);
|
||||
return response()->json(['message' => 'This is not your current step'], 400);
|
||||
}
|
||||
|
||||
// 3. Check proximity
|
||||
// Haversine formula
|
||||
// 3. Check proximity
|
||||
// Haversine formula
|
||||
$earthRadius = 6371000; // meters
|
||||
|
||||
$latFrom = deg2rad($request->latitude);
|
||||
|
|
@ -81,11 +78,11 @@ class HuntStepsController extends Controller
|
|||
$distance = $angle * $earthRadius;
|
||||
|
||||
if ($distance > $step->radius_m) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'You are too far from the target.',
|
||||
'distance' => round($distance) . 'm'
|
||||
], 400);
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'You are too far from the target.',
|
||||
'distance' => round($distance).'m',
|
||||
], 400);
|
||||
}
|
||||
|
||||
// 4. Update progress
|
||||
|
|
@ -98,15 +95,15 @@ class HuntStepsController extends Controller
|
|||
if ($nextStep) {
|
||||
$updateData['current_step_number'] = $nextStepNumber;
|
||||
} else {
|
||||
$updateData['status'] = 'completed';
|
||||
// Keep current_step_number as is (last step) or increment it to indicate "done"?
|
||||
// Usually keeping it at last step or marking status completed is enough.
|
||||
// Let's verify existing logic in HuntsController::show which filters based on step number.
|
||||
// If we increment, show() might need adjustment to show everything if completed.
|
||||
// For now, let's just mark completed and maybe keep same step number or increment.
|
||||
// If we increment, $nextStep is null, so user matches nothing in filter?
|
||||
// Let's increment current_step_number so that in show(), $step->step_number < $currentStepNumber becomes true for all steps.
|
||||
$updateData['current_step_number'] = $nextStepNumber;
|
||||
$updateData['status'] = 'completed';
|
||||
// Keep current_step_number as is (last step) or increment it to indicate "done"?
|
||||
// Usually keeping it at last step or marking status completed is enough.
|
||||
// Let's verify existing logic in HuntsController::show which filters based on step number.
|
||||
// If we increment, show() might need adjustment to show everything if completed.
|
||||
// For now, let's just mark completed and maybe keep same step number or increment.
|
||||
// If we increment, $nextStep is null, so user matches nothing in filter?
|
||||
// Let's increment current_step_number so that in show(), $step->step_number < $currentStepNumber becomes true for all steps.
|
||||
$updateData['current_step_number'] = $nextStepNumber;
|
||||
}
|
||||
|
||||
$hunt->participants()->updateExistingPivot($user->id, $updateData);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ namespace App\Http\Controllers;
|
|||
use App\Models\Hunts;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class HuntsController extends Controller
|
||||
{
|
||||
|
|
@ -17,41 +16,39 @@ class HuntsController extends Controller
|
|||
try {
|
||||
$query = Hunts::with('participants:id,avatar_uri');
|
||||
|
||||
if ($request->has('participating')) {
|
||||
$participating = filter_var(
|
||||
$request->query('participating'),
|
||||
FILTER_VALIDATE_BOOLEAN,
|
||||
FILTER_NULL_ON_FAILURE
|
||||
);
|
||||
if ($request->has('participating')) {
|
||||
$participating = filter_var(
|
||||
$request->query('participating'),
|
||||
FILTER_VALIDATE_BOOLEAN,
|
||||
FILTER_NULL_ON_FAILURE
|
||||
);
|
||||
|
||||
$userId = auth('sanctum')->id();
|
||||
$userId = auth('sanctum')->id();
|
||||
|
||||
Log::info('Participating filter resolved', [
|
||||
'participating' => $participating,
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
Log::info('Participating filter resolved', [
|
||||
'participating' => $participating,
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
|
||||
if (!$userId) {
|
||||
// Non connecté → aucune hunt "participating"
|
||||
if ($participating === true) {
|
||||
$query->whereRaw('1 = 0');
|
||||
}
|
||||
} else {
|
||||
if ($participating === true) {
|
||||
// Hunts où l'utilisateur participe
|
||||
$query->whereHas('participants', function ($q) use ($userId) {
|
||||
$q->where('user_id', $userId);
|
||||
});
|
||||
if (! $userId) {
|
||||
// Non connecté → aucune hunt "participating"
|
||||
if ($participating === true) {
|
||||
$query->whereRaw('1 = 0');
|
||||
}
|
||||
} else {
|
||||
// Hunts où l'utilisateur NE participe PAS
|
||||
$query->whereDoesntHave('participants', function ($q) use ($userId) {
|
||||
$q->where('user_id', $userId);
|
||||
});
|
||||
if ($participating === true) {
|
||||
// Hunts où l'utilisateur participe
|
||||
$query->whereHas('participants', function ($q) use ($userId) {
|
||||
$q->where('user_id', $userId);
|
||||
});
|
||||
} else {
|
||||
// Hunts où l'utilisateur NE participe PAS
|
||||
$query->whereDoesntHave('participants', function ($q) use ($userId) {
|
||||
$q->where('user_id', $userId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Filtre active/inactive uniquement si le param est présent
|
||||
if ($request->has('active')) {
|
||||
|
|
@ -69,20 +66,21 @@ class HuntsController extends Controller
|
|||
// Inactives: NOT(active)
|
||||
$query->where(function ($q) use ($now) {
|
||||
$q->whereNull('start_at')
|
||||
->orWhere('start_at', '>', $now)
|
||||
->orWhere(function ($q2) use ($now) {
|
||||
$q2->whereNotNull('end_at')
|
||||
->where('end_at', '<', $now);
|
||||
});
|
||||
->orWhere('start_at', '>', $now)
|
||||
->orWhere(function ($q2) use ($now) {
|
||||
$q2->whereNotNull('end_at')
|
||||
->where('end_at', '<', $now);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$hunts = $query->paginate(10);
|
||||
|
||||
return response()->json($hunts);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Error fetching hunts: ' . $e->getMessage());
|
||||
Log::error('Error fetching hunts: '.$e->getMessage());
|
||||
|
||||
return response()->json([
|
||||
'error' => 'Server Error',
|
||||
|
|
@ -91,7 +89,6 @@ class HuntsController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
|
|
@ -116,7 +113,7 @@ class HuntsController extends Controller
|
|||
{
|
||||
$hunt = Hunts::with(['steps', 'participants:id,avatar_uri'])->find($id);
|
||||
|
||||
if (!$hunt) {
|
||||
if (! $hunt) {
|
||||
return response()->json(['message' => 'Hunt not found'], 404);
|
||||
}
|
||||
|
||||
|
|
@ -135,27 +132,29 @@ class HuntsController extends Controller
|
|||
return true; // Show past steps fully
|
||||
}
|
||||
if ($step->step_number == $currentStepNumber) {
|
||||
// Show hints but hide location for current step
|
||||
// Show hints but hide location for current step
|
||||
$step->makeHidden(['latitude', 'longitude', 'radius_m']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // Hide future steps
|
||||
})->values());
|
||||
|
||||
$hunt->participation_status = $participation->pivot;
|
||||
} elseif ($hunt->creator_id !== $user->id) {
|
||||
// User is logged in but not participant and not creator
|
||||
// Show only first step or nothing specific (keep as is for now, maybe hide all steps or just show basic info)
|
||||
// For now, let's just hide hints of all steps if not participating?
|
||||
// Or maybe just show nothing of steps if not participating?
|
||||
// Requirement: "fetch the hunt in question it retrieves me the hunt steps already passed and the next one" implying context of participation.
|
||||
// If not participating, maybe just return basic hunt info without steps?
|
||||
$hunt->unsetRelation('steps');
|
||||
// User is logged in but not participant and not creator
|
||||
// Show only first step or nothing specific (keep as is for now, maybe hide all steps or just show basic info)
|
||||
// For now, let's just hide hints of all steps if not participating?
|
||||
// Or maybe just show nothing of steps if not participating?
|
||||
// Requirement: "fetch the hunt in question it retrieves me the hunt steps already passed and the next one" implying context of participation.
|
||||
// If not participating, maybe just return basic hunt info without steps?
|
||||
$hunt->unsetRelation('steps');
|
||||
}
|
||||
// If creator, show everything (default)
|
||||
// If creator, show everything (default)
|
||||
} else {
|
||||
// Guest
|
||||
$hunt->unsetRelation('steps');
|
||||
// Guest
|
||||
$hunt->unsetRelation('steps');
|
||||
}
|
||||
|
||||
return response()->json($hunt);
|
||||
|
|
@ -163,16 +162,16 @@ class HuntsController extends Controller
|
|||
|
||||
public function participate(Request $request, $id)
|
||||
{
|
||||
$hunt = Hunts::findOrFail($id);
|
||||
$user = $request->user();
|
||||
$hunt = Hunts::findOrFail($id);
|
||||
$user = $request->user();
|
||||
|
||||
if ($user->participations()->where('hunt_id', $hunt->id)->exists()) {
|
||||
return response()->json(['message' => 'Already participating'], 409);
|
||||
}
|
||||
if ($user->participations()->where('hunt_id', $hunt->id)->exists()) {
|
||||
return response()->json(['message' => 'Already participating'], 409);
|
||||
}
|
||||
|
||||
$hunt->participants()->attach($user->id, ['current_step_number' => 1, 'status' => 'started']);
|
||||
$hunt->participants()->attach($user->id, ['current_step_number' => 1, 'status' => 'started']);
|
||||
|
||||
return response()->json(['message' => 'Participation started'], 201);
|
||||
return response()->json(['message' => 'Participation started'], 201);
|
||||
}
|
||||
|
||||
public function unparticipate(Request $request, $id)
|
||||
|
|
@ -180,7 +179,7 @@ class HuntsController extends Controller
|
|||
$hunt = Hunts::findOrFail($id);
|
||||
$user = $request->user();
|
||||
|
||||
if (!$user->participations()->where('hunt_id', $hunt->id)->exists()) {
|
||||
if (! $user->participations()->where('hunt_id', $hunt->id)->exists()) {
|
||||
return response()->json(['message' => 'Not participating'], 404);
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +195,7 @@ class HuntsController extends Controller
|
|||
{
|
||||
$hunt = Hunts::find($id);
|
||||
|
||||
if (!$hunt) {
|
||||
if (! $hunt) {
|
||||
return response()->json(['message' => 'Hunt not found'], 404);
|
||||
}
|
||||
|
||||
|
|
@ -214,7 +213,7 @@ class HuntsController extends Controller
|
|||
{
|
||||
$hunt = Hunts::find($id);
|
||||
|
||||
if (!$hunt) {
|
||||
if (! $hunt) {
|
||||
return response()->json(['message' => 'Hunt not found'], 404);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\Auth\UpdatePasswordRequest;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use App\Http\Requests\Auth\UpdatePasswordRequest;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class UsersController extends Controller
|
||||
{
|
||||
|
|
@ -39,7 +39,7 @@ class UsersController extends Controller
|
|||
'avatar' => ['required', 'image', 'max:2048'], // 2MB max
|
||||
]);
|
||||
|
||||
$filename = \Illuminate\Support\Str::uuid() . '.jpg';
|
||||
$filename = \Illuminate\Support\Str::uuid().'.jpg';
|
||||
$path = $request->file('avatar')->storeAs('avatars', $filename, 'public');
|
||||
|
||||
$user->update([
|
||||
|
|
@ -55,7 +55,6 @@ class UsersController extends Controller
|
|||
/**
|
||||
* @requestMediaType multipart/form-data
|
||||
*/
|
||||
|
||||
public function updateUsername(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
|
|
@ -77,13 +76,12 @@ class UsersController extends Controller
|
|||
/**
|
||||
* @requestMediaType multipart/form-data
|
||||
*/
|
||||
|
||||
public function updatePassword(UpdatePasswordRequest $request)
|
||||
{
|
||||
$data = $request->validated();
|
||||
$user = $request->user();
|
||||
|
||||
if (!Hash::check($data['old_password'], $user->password)) {
|
||||
if (! Hash::check($data['old_password'], $user->password)) {
|
||||
return response()->json([
|
||||
'message' => 'The provided password does not match your current password.',
|
||||
], 422);
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class EnsureUserIsAdmin
|
|||
$user = $request->user();
|
||||
|
||||
if (
|
||||
!$user ||
|
||||
! $user ||
|
||||
($user->role !== \App\Enums\UserRole::ADMIN)
|
||||
) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class EnsureUserIsOrga
|
|||
$user = $request->user();
|
||||
|
||||
if (
|
||||
!$user ||
|
||||
! $user ||
|
||||
($user->role !== \App\Enums\UserRole::ORGA && $user->role !== \App\Enums\UserRole::ADMIN)
|
||||
) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
|
||||
class StoreHuntRequest extends FormRequest
|
||||
|
|
@ -44,7 +44,6 @@ class StoreHuntRequest extends FormRequest
|
|||
/**
|
||||
* Handle a failed validation attempt.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Http\Exceptions\HttpResponseException
|
||||
|
|
@ -53,7 +52,7 @@ class StoreHuntRequest extends FormRequest
|
|||
{
|
||||
throw new HttpResponseException(response()->json([
|
||||
'message' => 'Validation errors',
|
||||
'errors' => $validator->errors()
|
||||
'errors' => $validator->errors(),
|
||||
], 422));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
|
||||
class StoreHuntStepRequest extends FormRequest
|
||||
|
|
@ -39,7 +39,6 @@ class StoreHuntStepRequest extends FormRequest
|
|||
/**
|
||||
* Handle a failed validation attempt.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Http\Exceptions\HttpResponseException
|
||||
|
|
@ -48,7 +47,7 @@ class StoreHuntStepRequest extends FormRequest
|
|||
{
|
||||
throw new HttpResponseException(response()->json([
|
||||
'message' => 'Validation errors',
|
||||
'errors' => $validator->errors()
|
||||
'errors' => $validator->errors(),
|
||||
], 422));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
|
|
@ -50,7 +50,6 @@ class UpdateHuntRequest extends FormRequest
|
|||
/**
|
||||
* Handle a failed validation attempt.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Http\Exceptions\HttpResponseException
|
||||
|
|
@ -59,7 +58,7 @@ class UpdateHuntRequest extends FormRequest
|
|||
{
|
||||
throw new HttpResponseException(response()->json([
|
||||
'message' => 'Validation errors',
|
||||
'errors' => $validator->errors()
|
||||
'errors' => $validator->errors(),
|
||||
], 422));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
class HuntSteps extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'hunt_id',
|
||||
'step_number',
|
||||
|
|
@ -20,6 +21,7 @@ class HuntSteps extends Model
|
|||
'radius_m',
|
||||
'xp',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'latitude' => 'float',
|
||||
'longitude' => 'float',
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\HuntDifficulty;
|
||||
use App\Enums\HuntStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Enums\HuntStatus;
|
||||
use App\Enums\HuntDifficulty;
|
||||
|
||||
class Hunts extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
|
@ -40,6 +41,7 @@ class Hunts extends Model
|
|||
'status' => HuntStatus::class,
|
||||
'difficulty' => HuntDifficulty::class,
|
||||
];
|
||||
|
||||
public function steps()
|
||||
{
|
||||
return $this->hasMany(HuntSteps::class, 'hunt_id');
|
||||
|
|
@ -51,5 +53,4 @@ class Hunts extends Model
|
|||
->withPivot(['current_step_number', 'status'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\User;
|
||||
|
||||
class Level extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'level_position',
|
||||
'xpThreshold',
|
||||
|
|
|
|||
|
|
@ -4,22 +4,21 @@ namespace App\Models;
|
|||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Enums\UserRole;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Models\Contracts\HasName;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
|
||||
class User extends Authenticatable implements HasName, FilamentUser
|
||||
class User extends Authenticatable implements FilamentUser, HasName
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasApiTokens, HasFactory, Notifiable, SoftDeletes, HasUuids;
|
||||
use HasApiTokens, HasFactory, HasUuids, Notifiable, SoftDeletes;
|
||||
|
||||
/**
|
||||
* The primary key type.
|
||||
|
|
@ -49,7 +48,7 @@ class User extends Authenticatable implements HasName, FilamentUser
|
|||
'avatar_uri',
|
||||
'participations',
|
||||
'victories',
|
||||
'level_id'
|
||||
'level_id',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -81,7 +80,7 @@ class User extends Authenticatable implements HasName, FilamentUser
|
|||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'role'=> UserRole::class
|
||||
'role' => UserRole::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -114,6 +113,7 @@ class User extends Authenticatable implements HasName, FilamentUser
|
|||
->orderBy('xpThreshold', 'asc')
|
||||
->value('xpThreshold');
|
||||
}
|
||||
|
||||
public function getFilamentName(): string
|
||||
{
|
||||
return $this->username;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\Hunts;
|
||||
use App\Models\User;
|
||||
use App\Enums\UserRole;
|
||||
|
||||
class HuntsPolicy
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Enums\UserRole;
|
||||
use App\Models\User;
|
||||
|
||||
class UserPolicy
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ namespace App\Providers;
|
|||
use Dedoc\Scramble\Scramble;
|
||||
use Dedoc\Scramble\Support\Generator\OpenApi;
|
||||
use Dedoc\Scramble\Support\Generator\SecurityScheme;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
if($this->app->environment('production')) {
|
||||
if ($this->app->environment('production')) {
|
||||
\Illuminate\Support\Facades\URL::forceScheme('https');
|
||||
}
|
||||
|
||||
|
|
@ -33,14 +33,14 @@ class AppServiceProvider extends ServiceProvider
|
|||
return true;
|
||||
});
|
||||
|
||||
Scramble::configure()
|
||||
Scramble::configure()
|
||||
->routes(function (Route $route) {
|
||||
return Str::startsWith($route->uri, 'api/');
|
||||
})
|
||||
->withDocumentTransformers(function (OpenApi $openApi) {
|
||||
$openApi->secure(
|
||||
SecurityScheme::http('bearer')
|
||||
);
|
||||
});
|
||||
->withDocumentTransformers(function (OpenApi $openApi) {
|
||||
$openApi->secure(
|
||||
SecurityScheme::http('bearer')
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
"require-dev": {
|
||||
"laravel/boost": "^1.8",
|
||||
"laravel/pail": "^1.2.2",
|
||||
"laravel/pint": "^1.24",
|
||||
"laravel/pint": "*",
|
||||
"laravel/sail": "^1.41",
|
||||
"mockery/mockery": "^1.6",
|
||||
"nunomaduro/collision": "^8.6",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "47bd34a5c0059d745d768652ac0ee581",
|
||||
"content-hash": "047de0487d6a961282c968d1142d9844",
|
||||
"packages": [
|
||||
{
|
||||
"name": "anourvalar/eloquent-serialize",
|
||||
|
|
@ -9107,16 +9107,16 @@
|
|||
},
|
||||
{
|
||||
"name": "laravel/pint",
|
||||
"version": "v1.26.0",
|
||||
"version": "v1.27.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/pint.git",
|
||||
"reference": "69dcca060ecb15e4b564af63d1f642c81a241d6f"
|
||||
"reference": "c67b4195b75491e4dfc6b00b1c78b68d86f54c90"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/69dcca060ecb15e4b564af63d1f642c81a241d6f",
|
||||
"reference": "69dcca060ecb15e4b564af63d1f642c81a241d6f",
|
||||
"url": "https://api.github.com/repos/laravel/pint/zipball/c67b4195b75491e4dfc6b00b1c78b68d86f54c90",
|
||||
"reference": "c67b4195b75491e4dfc6b00b1c78b68d86f54c90",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -9127,9 +9127,9 @@
|
|||
"php": "^8.2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3.90.0",
|
||||
"illuminate/view": "^12.40.1",
|
||||
"larastan/larastan": "^3.8.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.92.4",
|
||||
"illuminate/view": "^12.44.0",
|
||||
"larastan/larastan": "^3.8.1",
|
||||
"laravel-zero/framework": "^12.0.4",
|
||||
"mockery/mockery": "^1.6.12",
|
||||
"nunomaduro/termwind": "^2.3.3",
|
||||
|
|
@ -9170,7 +9170,7 @@
|
|||
"issues": "https://github.com/laravel/pint/issues",
|
||||
"source": "https://github.com/laravel/pint"
|
||||
},
|
||||
"time": "2025-11-25T21:15:52+00:00"
|
||||
"time": "2026-01-05T16:49:17+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/roster",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class BordeauxHuntsSeeder extends Seeder
|
||||
|
|
@ -55,7 +54,7 @@ class BordeauxHuntsSeeder extends Seeder
|
|||
'radius_m' => 50,
|
||||
]);
|
||||
|
||||
// Step 3: Cathédrale Saint-André
|
||||
// Step 3: Cathédrale Saint-André
|
||||
\App\Models\HuntSteps::factory()->create([
|
||||
'hunt_id' => $hunt->id,
|
||||
'step_number' => 3,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Level;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class LevelSeeder extends Seeder
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,6 +16,6 @@ return [
|
|||
'failed' => 'These credentials do not match our records.',
|
||||
'password' => 'The provided password is incorrect.',
|
||||
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
|
||||
'logout_success' => "You have been deconnecte"
|
||||
'logout_success' => 'You have been deconnecte',
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -16,6 +16,6 @@ return [
|
|||
'failed' => 'Impossible de vous connecter',
|
||||
'password' => 'Email ou mot de passe incorrect',
|
||||
'throttle' => 'Trop de tentatives veuillez reessayer dans :seconds seconds.',
|
||||
'logout_success' => 'Vous êtes bien déconnecté'
|
||||
'logout_success' => 'Vous êtes bien déconnecté',
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@ return [
|
|||
'sent' => 'Nous avons envoyé par e-mail le lien de réinitialisation de votre mot de passe.',
|
||||
'throttled' => 'Veuillez patienter avant de réessayer.',
|
||||
'token' => 'Ce jeton de réinitialisation du mot de passe est invalide.',
|
||||
'user' => "Nous ne trouvons pas d’utilisateur avec cette adresse e-mail.",
|
||||
'user' => 'Nous ne trouvons pas d’utilisateur avec cette adresse e-mail.',
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,16 +1,12 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\AuthController;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
||||
|
||||
use App\Http\Controllers\HuntsController;
|
||||
use App\Http\Controllers\HuntStepsController;
|
||||
use App\Http\Controllers\UsersController;
|
||||
use App\Http\Middleware\EnsureUserIsAdmin;
|
||||
use App\Http\Middleware\EnsureUserIsOrga;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('auth')->group(function (): void {
|
||||
Route::post('register', [AuthController::class, 'register']);
|
||||
|
|
@ -21,7 +17,7 @@ Route::prefix('auth')->group(function (): void {
|
|||
|
||||
// List hunts
|
||||
|
||||
//Ensure is Admin
|
||||
// Ensure is Admin
|
||||
Route::middleware(['auth:sanctum', EnsureUserIsAdmin::class])->group(function () {
|
||||
Route::post('users/{user}/delete', [UsersController::class, 'softDeleteById'])->withTrashed();
|
||||
});
|
||||
|
|
@ -38,7 +34,7 @@ Route::middleware(['auth:sanctum', EnsureUserIsOrga::class])->group(function ()
|
|||
Route::middleware('auth:sanctum')->group(function (): void {
|
||||
Route::get('hunts', [HuntsController::class, 'index']);
|
||||
Route::get('hunts/{hunt}', [HuntsController::class, 'show']);
|
||||
//Auth
|
||||
// Auth
|
||||
Route::post('auth/delete', [AuthController::class, 'softDelete']);
|
||||
// User
|
||||
Route::get('users/leaderboard', [UsersController::class, 'leaderboard']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue