fix(goal): bound public calculator inputs
This commit is contained in:
1 parent
041d717439
commit
5d6e5987d1
8 files changed
+58
-8
No files matched your search
+7
-1
@@ -6,6 +6,7 @@ API-слой: парсинг JSON-пейлоадов и диспетчериза
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
from math import isfinite
|
||||
from typing import Any
|
||||
|
||||
from .domain import (
|
||||
@@ -190,10 +191,15 @@ def calculate_payload(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
if mode == "goal":
|
||||
def _number_value(key: str) -> float:
|
||||
value = _required(payload, key)
|
||||
if isinstance(value, bool):
|
||||
raise ApiError(f"Поле {key} должно быть числом")
|
||||
try:
|
||||
return float(value)
|
||||
number = float(value)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise ApiError(f"Поле {key} должно быть числом") from exc
|
||||
if not isfinite(number):
|
||||
raise ApiError(f"Поле {key} должно быть конечным числом")
|
||||
return number
|
||||
|
||||
minutes = _int(payload, "minutes_per_session")
|
||||
result = calculate_goal(
|
||||
|
||||
Reference in new issue
Block a user