feat(pets): adds validator for pet id
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
from app.models.pet import Pet
|
||||||
from app.models.pet_kind import PetKind
|
from app.models.pet_kind import PetKind
|
||||||
from app.utils.errors.pets.pet_register_errors import PetRegisterError
|
from app.utils.errors.pets.pet_register_errors import PetRegisterError
|
||||||
from app.utils.helpers import pet_sex_id_to_str
|
from app.utils.helpers import pet_sex_id_to_str
|
||||||
@@ -63,4 +64,14 @@ class PetValidators:
|
|||||||
if location is not None:
|
if location is not None:
|
||||||
if Validators.is_valid_str_and_pattern(location,'^[A-Za-z ]{2,255}$'):
|
if Validators.is_valid_str_and_pattern(location,'^[A-Za-z ]{2,255}$'):
|
||||||
return location
|
return location
|
||||||
raise PetRegisterError("Invalid location")
|
raise PetRegisterError("Invalid location")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_valid_pet_id(id: str | None):
|
||||||
|
if id is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
int(id)
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
return db.session.execute(db.select(Pet).filter_by(id=id)).one_or_none()
|
||||||
Reference in New Issue
Block a user