Add backend validation for note length using constant
- Updated BookingRequest validator to use NOTE_MAX_LENGTH constant - Replaced hardcoded 144 with constant for consistency - Error message now includes the actual max length value
This commit is contained in:
parent
3c13270bc0
commit
1497a81cd5
1 changed files with 4 additions and 2 deletions
|
|
@ -4,6 +4,8 @@ from typing import Generic, TypeVar
|
|||
|
||||
from pydantic import BaseModel, EmailStr, field_validator
|
||||
|
||||
from shared_constants import NOTE_MAX_LENGTH
|
||||
|
||||
|
||||
class UserCredentials(BaseModel):
|
||||
"""Base model for user email/password."""
|
||||
|
|
@ -207,8 +209,8 @@ class BookingRequest(BaseModel):
|
|||
@field_validator("note")
|
||||
@classmethod
|
||||
def validate_note_length(cls, v: str | None) -> str | None:
|
||||
if v is not None and len(v) > 144:
|
||||
raise ValueError("Note must be at most 144 characters")
|
||||
if v is not None and len(v) > NOTE_MAX_LENGTH:
|
||||
raise ValueError(f"Note must be at most {NOTE_MAX_LENGTH} characters")
|
||||
return v
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue