fix: trustProxies (assets Filament https) + noms exos localisés (name_i18n) + /api/stats
Build & Deploy / build (push) Successful in 18s
Build & Deploy / build (push) Successful in 18s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Functional\Exercises\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Stats publiques agrégées (widget Homepage). Compteurs seulement, aucune donnée perso.
|
||||
*/
|
||||
class StatsController
|
||||
{
|
||||
public function __invoke(): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'exercises' => DB::table('exercises')->count(),
|
||||
'users' => DB::table('users')->count(),
|
||||
'workouts' => DB::table('workout_sessions')->where('status', 'completed')->count(),
|
||||
'active_streaks' => DB::table('streaks')->where('current_count', '>', 0)->count(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class ExerciseListResource extends JsonResource
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'name' => $this->resource->localizedName($l),
|
||||
'slug' => $this->slug,
|
||||
'body_part' => Exercise::localizeTerm($this->body_part, $l),
|
||||
'equipment' => Exercise::localizeTerm($this->equipment, $l),
|
||||
|
||||
@@ -22,7 +22,7 @@ class ExerciseResource extends JsonResource
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'name' => $model->localizedName($l),
|
||||
'slug' => $this->slug,
|
||||
'body_part' => $model::localizeTerm($this->body_part, $l),
|
||||
'category' => $model::localizeTerm($this->category, $l),
|
||||
|
||||
@@ -22,7 +22,7 @@ class Exercise extends Model
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'external_id', 'name', 'slug', 'category', 'body_part', 'equipment',
|
||||
'external_id', 'name', 'name_i18n', 'slug', 'category', 'body_part', 'equipment',
|
||||
'target', 'muscle_group', 'secondary_muscles', 'instructions',
|
||||
'image_path', 'gif_path', 'attribution',
|
||||
];
|
||||
@@ -30,6 +30,7 @@ class Exercise extends Model
|
||||
protected $casts = [
|
||||
'secondary_muscles' => 'array',
|
||||
'instructions' => 'array',
|
||||
'name_i18n' => 'array',
|
||||
];
|
||||
|
||||
protected $appends = ['image_url', 'gif_url'];
|
||||
@@ -82,6 +83,14 @@ class Exercise extends Model
|
||||
return [];
|
||||
}
|
||||
|
||||
/** Nom localisé (name_i18n) avec repli sur le nom anglais canonique. */
|
||||
public function localizedName(string $locale): string
|
||||
{
|
||||
$map = $this->name_i18n ?? [];
|
||||
|
||||
return $map[$locale] ?? $map[substr($locale, 0, 2)] ?? $this->name;
|
||||
}
|
||||
|
||||
/** Traduit un terme du vocabulaire contrôlé (zone/équipement/muscle) selon la locale. Repli = anglais. */
|
||||
public static function localizeTerm(?string $value, string $locale): ?string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user