From 868b09f7efa84da59867ffb02370c370d8243b01 Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Thu, 29 May 2025 01:40:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=BA=20Validate=20fields=20in=20pin=20t?= =?UTF-8?q?o=20avoid=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/pin.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/models/pin.py b/app/models/pin.py index 12c4591..ce81c71 100644 --- a/app/models/pin.py +++ b/app/models/pin.py @@ -1,13 +1,19 @@ from typing import Optional, List -from pydantic import BaseModel +from pydantic import BaseModel, Field, validator from datetime import datetime class Pin(BaseModel): id: Optional[str] - title: str - description: str - location: list - complete_address: str + title: str = Field(..., min_length=3) + description: str = Field(..., min_length=3) + location: list = Field(..., min_items=2) + complete_address: str = Field(..., min_length=3) files: Optional[List[str]] = [] # Liste des IDs d'images user_id: str - date: Optional[datetime] = None \ No newline at end of file + date: Optional[datetime] = None + + @validator('location') + def validate_location(cls, v): + if not v or len(v) == 0: + raise ValueError('La location ne peut pas ĂȘtre vide') + return v \ No newline at end of file