Initial commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
|
||||
def parse_positive_int_ids(value, field_name: str = "ids") -> list[int]:
|
||||
detail = f"{field_name} must be a list of positive integers"
|
||||
if not isinstance(value, list):
|
||||
raise HTTPException(status_code=400, detail=detail)
|
||||
ids: list[int] = []
|
||||
for item in value:
|
||||
if isinstance(item, bool):
|
||||
raise HTTPException(status_code=400, detail=detail)
|
||||
if isinstance(item, int):
|
||||
item_id = item
|
||||
elif isinstance(item, str) and item.isdecimal():
|
||||
item_id = int(item)
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail=detail)
|
||||
if item_id <= 0:
|
||||
raise HTTPException(status_code=400, detail=detail)
|
||||
ids.append(item_id)
|
||||
return ids
|
||||
Reference in New Issue
Block a user