admin frontend elkezdése, járművek tisztázása, frontend fejleszts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# /opt/docker/dev/service_finder/backend/app/schemas/asset.py
|
||||
from pydantic import BaseModel, ConfigDict, Field, validator
|
||||
from pydantic import BaseModel, ConfigDict, Field, validator, root_validator, model_validator
|
||||
from typing import Optional, Dict, Any, List
|
||||
from uuid import UUID
|
||||
from datetime import datetime
|
||||
@@ -113,8 +113,30 @@ class AssetResponse(BaseModel):
|
||||
class AssetCreate(BaseModel):
|
||||
""" Jármű létrehozásához szükséges adatok - Thick Digital Twin támogatással. """
|
||||
# === CORE IDENTIFICATION (Required for status determination) ===
|
||||
license_plate: str = Field(..., min_length=2, max_length=20, description="Rendszám")
|
||||
license_plate: Optional[str] = Field(None, min_length=2, max_length=20, description="Rendszám")
|
||||
vin: Optional[str] = Field(None, min_length=1, max_length=50, description="VIN szám (opcionális)")
|
||||
|
||||
# ── Pre-validator: convert empty strings to None for optional string fields ──
|
||||
@validator('license_plate', 'vin', 'trim_level',
|
||||
'cylinder_layout', 'transmission_type', 'drive_type',
|
||||
'euro_classification', 'roof_type', 'audio_system_type',
|
||||
'data_status',
|
||||
pre=True, always=True)
|
||||
def empty_str_to_none(cls, v):
|
||||
"""Convert empty strings to None so Pydantic doesn't reject them with min_length."""
|
||||
if v is not None and isinstance(v, str) and v.strip() == '':
|
||||
return None
|
||||
return v
|
||||
|
||||
# ── Root validator: ensure at least one of vin or license_plate is provided ──
|
||||
@root_validator(skip_on_failure=True)
|
||||
def validate_vin_or_plate(cls, values):
|
||||
"""Legalább egy azonosítót meg kell adni: rendszám VAGY VIN szám."""
|
||||
license_plate = values.get('license_plate')
|
||||
vin = values.get('vin')
|
||||
if not license_plate and not vin:
|
||||
raise ValueError('Legalább egy azonosítót meg kell adni: rendszám VAGY VIN szám.')
|
||||
return values
|
||||
|
||||
# === CLASSIFICATION (Optional, but affects status) ===
|
||||
brand: Optional[str] = Field(None, max_length=100, description="Márka (ha nincs catalog_id)")
|
||||
@@ -190,6 +212,35 @@ class AssetUpdate(BaseModel):
|
||||
# === CORE IDENTIFICATION ===
|
||||
license_plate: Optional[str] = Field(None, min_length=2, max_length=20, description="Rendszám")
|
||||
vin: Optional[str] = Field(None, min_length=1, max_length=50, description="VIN szám")
|
||||
|
||||
# ── Pre-validator: convert empty strings to None for optional string fields ──
|
||||
@validator('license_plate', 'vin', 'trim_level',
|
||||
'cylinder_layout', 'transmission_type', 'drive_type',
|
||||
'euro_classification', 'roof_type', 'audio_system_type',
|
||||
pre=True, always=True)
|
||||
def empty_str_to_none(cls, v):
|
||||
"""Convert empty strings to None so Pydantic doesn't reject them with min_length."""
|
||||
if v is not None and isinstance(v, str) and v.strip() == '':
|
||||
return None
|
||||
return v
|
||||
|
||||
# ── Model validator: ensure at least one of vin or license_plate is provided ──
|
||||
@model_validator(mode='after')
|
||||
def validate_vin_or_plate(self):
|
||||
"""Update esetén: ha mindkét mezőt None-ra állítják explicit, az nem engedélyezett.
|
||||
|
||||
Működés:
|
||||
- Ha egyik mező sincs a payload-ban (üres update) → engedélyezve (nincs változás)
|
||||
- Ha mindkettő None explicit → hiba (nem lehet mindkettőt elvenni)
|
||||
- Ha legalább az egyik meg van adva → OK
|
||||
"""
|
||||
# model_fields_set tartalmazza az explicit megadott mezőket
|
||||
if 'license_plate' not in self.model_fields_set and 'vin' not in self.model_fields_set:
|
||||
return self
|
||||
|
||||
if not self.license_plate and not self.vin:
|
||||
raise ValueError('Legalább egy azonosítót meg kell adni: rendszám VAGY VIN szám.')
|
||||
return self
|
||||
|
||||
# === CLASSIFICATION ===
|
||||
brand: Optional[str] = Field(None, max_length=100, description="Márka")
|
||||
|
||||
Reference in New Issue
Block a user