fix: validate earned inspection resources
This commit is contained in:
1 parent
aa49634d93
commit
d025f51733
5 files changed
+23
-3
No files matched your search
+11
-1
@@ -177,7 +177,17 @@ def calculate_payload(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
raw_resources = payload.get("resources", [])
|
||||
if not isinstance(raw_resources, list):
|
||||
raise ApiError("Поле resources должно быть списком")
|
||||
resources = tuple((str(item[0]), _int_value(item[1], "Количество ресурса")) for item in raw_resources)
|
||||
if len(raw_resources) > MAX_INSPECTION_RESOURCES:
|
||||
raise ApiError(f"В одном расчёте может быть не более {MAX_INSPECTION_RESOURCES} ресурсов")
|
||||
resources_list = []
|
||||
for item in raw_resources:
|
||||
if not isinstance(item, (list, tuple)) or len(item) != 2:
|
||||
raise ApiError("Каждый ресурс должен содержать название и количество")
|
||||
name, amount = item
|
||||
if not isinstance(name, str) or not name.strip():
|
||||
raise ApiError("Укажите название ресурса")
|
||||
resources_list.append((name, _int_value(amount, "Количество ресурса")))
|
||||
resources = tuple(resources_list)
|
||||
result = calculate_inspection(InspectionReport("Персонаж", 1, str(_required(payload, "place")), _int(payload, "inspections"), resources))
|
||||
return {"mode": mode, "activity": activity, "result": {"points": result.points}}
|
||||
raise ApiError("Неизвестный вид занятия")
|
||||
|
||||
Reference in new issue
Block a user