You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
944 B
28 lines
944 B
from typing import Optional, List
|
|
from pydantic import BaseModel, Field, field_validator
|
|
from datetime import datetime
|
|
|
|
class Pin(BaseModel):
|
|
id: Optional[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
|
|
is_poi: bool = False
|
|
user_id: Optional[str] = None
|
|
date: Optional[datetime] = None
|
|
|
|
@field_validator('location')
|
|
@classmethod
|
|
def validate_location(cls, v):
|
|
if not v or len(v) == 0:
|
|
raise ValueError('La location ne peut pas être vide')
|
|
return v
|
|
|
|
@field_validator('user_id')
|
|
@classmethod
|
|
def validate_user_id(cls, v, info):
|
|
if not info.data.get('is_poi') and not v:
|
|
raise ValueError('user_id est requis lorsque is_poi est False')
|
|
return v |