diff --git a/app/Http/Controllers/HuntsController.php b/app/Http/Controllers/HuntsController.php index 78a5b5a..ee2526f 100644 --- a/app/Http/Controllers/HuntsController.php +++ b/app/Http/Controllers/HuntsController.php @@ -14,36 +14,13 @@ class HuntsController extends Controller public function index(Request $request): JsonResponse { try { - Log::info('HUNTS_INDEX_START', [ - 'full_request' => $request->all(), - 'url' => $request->fullUrl(), - 'method' => $request->method(), - ]); - $searchTerm = $this->resolveSearchTerm($request); - Log::info('HUNTS_SEARCH_TERM_RESOLVED', [ - 'search_term' => $searchTerm, - ]); - $filters = $this->buildMeilisearchFilters($request); - Log::info('HUNTS_FILTERS_BUILT', [ - 'filters' => $filters, - 'filters_length' => strlen($filters), - ]); - - Log::info('HUNTS_CREATING_SEARCH_QUERY', [ - 'search_term' => $searchTerm ?? '', - 'filters' => $filters, - ]); $search = Hunts::search($searchTerm ?? '') ->query(fn ($query) => $query->with('participants:id,avatar_uri')) ->options(['filter' => $filters]); - Log::info('HUNTS_SEARCH_QUERY_CREATED', [ - 'search_class' => get_class($search), - ]); - Log::info('HUNTS_SEARCH', [ 'q' => $searchTerm ?? '', 'filters' => $filters, @@ -52,86 +29,14 @@ class HuntsController extends Controller 'request_params' => $request->all(), ]); - Log::info('HUNTS_EXECUTING_PAGINATE'); $result = $search->paginate(10); Log::info('HUNTS_SEARCH_SUCCESS', [ 'total' => $result->total(), 'count' => count($result->items()), - 'result_class' => get_class($result), ]); - // Log the structure of each item - $items = $result->items(); - Log::info('HUNTS_RESULT_ITEMS_COUNT', [ - 'items_count' => count($items), - ]); - - foreach ($items as $index => $item) { - try { - Log::info('HUNTS_ITEM_STRUCTURE', [ - 'index' => $index, - 'item_class' => get_class($item), - 'item_id' => $item->id ?? null, - 'item_title' => $item->title ?? null, - 'has_participants' => isset($item->participants), - 'participants_type' => isset($item->participants) ? gettype($item->participants) : null, - 'participants_class' => isset($item->participants) && is_object($item->participants) ? get_class($item->participants) : null, - ]); - - // Try to access participants - if (isset($item->participants)) { - try { - $participantsData = $item->participants; - Log::info('HUNTS_ITEM_PARTICIPANTS_DATA', [ - 'index' => $index, - 'item_id' => $item->id, - 'participants_count' => is_countable($participantsData) ? count($participantsData) : 'not_countable', - 'participants_value' => $participantsData, - ]); - } catch (\Throwable $participantsError) { - Log::error('HUNTS_ERROR_ACCESSING_PARTICIPANTS', [ - 'index' => $index, - 'item_id' => $item->id, - 'error' => $participantsError->getMessage(), - 'trace' => $participantsError->getTraceAsString(), - ]); - } - } - - // Try to serialize this specific item - try { - $itemJson = json_encode($item); - Log::info('HUNTS_ITEM_JSON_SUCCESS', [ - 'index' => $index, - 'item_id' => $item->id, - 'json_length' => strlen($itemJson), - ]); - } catch (\Throwable $jsonError) { - Log::error('HUNTS_ERROR_JSON_ENCODING_ITEM', [ - 'index' => $index, - 'item_id' => $item->id ?? null, - 'error' => $jsonError->getMessage(), - 'trace' => $jsonError->getTraceAsString(), - ]); - } - } catch (\Throwable $itemError) { - Log::error('HUNTS_ERROR_PROCESSING_ITEM', [ - 'index' => $index, - 'error' => $itemError->getMessage(), - 'trace' => $itemError->getTraceAsString(), - ]); - } - } - - Log::info('HUNTS_CREATING_JSON_RESPONSE'); - $jsonResponse = response()->json($result); - - Log::info('HUNTS_JSON_RESPONSE_CREATED', [ - 'status' => $jsonResponse->status(), - ]); - - return $jsonResponse; + return response()->json($result); } catch (\Throwable $e) { Log::error('HUNTS_ERROR_CAUGHT', [ 'message' => $e->getMessage(), diff --git a/app/Models/User.php b/app/Models/User.php index f5b2987..719b5ba 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -109,6 +109,13 @@ class User extends Authenticatable implements FilamentUser, HasName public function getNextLevelXpAttribute(): ?int { + // Si l'XP est null, on ne peut pas comparer avec > + // On retourne le premier niveau disponible + if ($this->xp === null) { + return Level::orderBy('xpThreshold', 'asc') + ->value('xpThreshold'); + } + return Level::where('xpThreshold', '>', $this->xp) ->orderBy('xpThreshold', 'asc') ->value('xpThreshold');