feat: try fix xp treshold
This commit is contained in:
parent
c61b887ca8
commit
23163c9c4c
|
|
@ -14,36 +14,13 @@ class HuntsController extends Controller
|
||||||
public function index(Request $request): JsonResponse
|
public function index(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Log::info('HUNTS_INDEX_START', [
|
|
||||||
'full_request' => $request->all(),
|
|
||||||
'url' => $request->fullUrl(),
|
|
||||||
'method' => $request->method(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$searchTerm = $this->resolveSearchTerm($request);
|
$searchTerm = $this->resolveSearchTerm($request);
|
||||||
Log::info('HUNTS_SEARCH_TERM_RESOLVED', [
|
|
||||||
'search_term' => $searchTerm,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$filters = $this->buildMeilisearchFilters($request);
|
$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 ?? '')
|
$search = Hunts::search($searchTerm ?? '')
|
||||||
->query(fn ($query) => $query->with('participants:id,avatar_uri'))
|
->query(fn ($query) => $query->with('participants:id,avatar_uri'))
|
||||||
->options(['filter' => $filters]);
|
->options(['filter' => $filters]);
|
||||||
|
|
||||||
Log::info('HUNTS_SEARCH_QUERY_CREATED', [
|
|
||||||
'search_class' => get_class($search),
|
|
||||||
]);
|
|
||||||
|
|
||||||
Log::info('HUNTS_SEARCH', [
|
Log::info('HUNTS_SEARCH', [
|
||||||
'q' => $searchTerm ?? '',
|
'q' => $searchTerm ?? '',
|
||||||
'filters' => $filters,
|
'filters' => $filters,
|
||||||
|
|
@ -52,86 +29,14 @@ class HuntsController extends Controller
|
||||||
'request_params' => $request->all(),
|
'request_params' => $request->all(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Log::info('HUNTS_EXECUTING_PAGINATE');
|
|
||||||
$result = $search->paginate(10);
|
$result = $search->paginate(10);
|
||||||
|
|
||||||
Log::info('HUNTS_SEARCH_SUCCESS', [
|
Log::info('HUNTS_SEARCH_SUCCESS', [
|
||||||
'total' => $result->total(),
|
'total' => $result->total(),
|
||||||
'count' => count($result->items()),
|
'count' => count($result->items()),
|
||||||
'result_class' => get_class($result),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Log the structure of each item
|
return response()->json($result);
|
||||||
$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;
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
Log::error('HUNTS_ERROR_CAUGHT', [
|
Log::error('HUNTS_ERROR_CAUGHT', [
|
||||||
'message' => $e->getMessage(),
|
'message' => $e->getMessage(),
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,13 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||||
|
|
||||||
public function getNextLevelXpAttribute(): ?int
|
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)
|
return Level::where('xpThreshold', '>', $this->xp)
|
||||||
->orderBy('xpThreshold', 'asc')
|
->orderBy('xpThreshold', 'asc')
|
||||||
->value('xpThreshold');
|
->value('xpThreshold');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue