validateHmacSignature($api_key, $signature, '', $timestamp); if (!$authResult['valid']) { throw new Exception($authResult['error'], 401); } $user_id = $authResult['user_id']; // Fetch workouts $stmt = $db->prepare('SELECT * FROM workouts WHERE user_id = ? ORDER BY created_at DESC LIMIT 50'); $stmt->bind_param('i', $user_id); $stmt->execute(); $result = $stmt->get_result(); $workouts = []; while ($row = $result->fetch_assoc()) { $workouts[] = $row; } echo json_encode([ 'status' => 'success', 'data' => $workouts ]); } catch (Exception $e) { http_response_code($e->getCode() ?: 500); echo json_encode(['status' => 'error', 'error' => $e->getMessage()]); }