Complete CarPass product flows

This commit is contained in:
VPN SaaS Dev
2026-05-14 21:19:37 +09:00
parent a83f55c646
commit c0014ab4ea
28 changed files with 3006 additions and 159 deletions

View File

@@ -46,6 +46,7 @@ from app.schemas.service_center import (
VehicleSearchRequest,
VehicleSearchResult,
)
from app.services.odometer import validate_odometer_change
from app.services.vehicle_identity import mask_license_plate, mask_vin
router = APIRouter(prefix="/service-centers", tags=["service-centers"])
@@ -81,6 +82,18 @@ async def create_service_center(
)
session.add(center)
await session.flush()
session.add(
ServiceCenterVerification(
service_center_id=center.id,
submitted_documents=[
{"type": "registration", "urls": payload.document_photo_urls or []},
{"type": "facade", "url": payload.facade_photo_url},
{"type": "additional", "urls": payload.additional_photo_urls or []},
],
comment="Initial service center application",
status="pending",
)
)
employee = ServiceEmployee(
service_center_id=center.id,
user_id=current_user.id,
@@ -94,6 +107,44 @@ async def create_service_center(
return center
@router.patch("/{service_center_id}", response_model=ServiceCenterRead)
async def update_service_center_application(
service_center_id: int,
payload: ServiceCenterCreate,
session: AsyncSession = Depends(get_session),
current_user: User = Depends(get_current_telegram_user),
) -> ServiceCenter:
await ensure_service_employee(session, service_center_id, current_user, {"owner", "manager"})
center = await session.get(ServiceCenter, service_center_id)
if center is None:
raise HTTPException(status_code=404, detail="Service center not found")
data = payload.model_dump(exclude_unset=True)
for field, value in data.items():
if field == "display_name":
center.display_name = value
center.name = value
elif hasattr(center, field):
setattr(center, field, value)
if center.verification_status in {"draft", "needs_changes", "rejected"}:
center.verification_status = "pending"
session.add(
ServiceCenterVerification(
service_center_id=center.id,
submitted_documents=[
{"type": "registration", "urls": center.document_photo_urls or []},
{"type": "facade", "url": center.facade_photo_url},
{"type": "additional", "urls": center.additional_photo_urls or []},
],
comment="Resubmitted service center application",
status="pending",
)
)
await log_audit(session, actor=current_user, action="service_center.update", target_type="service_center", target_id=center.id)
await session.commit()
await session.refresh(center)
return center
@router.get("/my", response_model=list[ServiceCenterRead])
async def my_service_centers(
session: AsyncSession = Depends(get_session),
@@ -287,6 +338,7 @@ async def create_visit(
vehicle = await session.get(Car, payload.vehicle_id)
if vehicle is None:
raise HTTPException(status_code=404, detail="Vehicle not found")
validate_odometer_change(vehicle, payload.odometer, source_record_type="service_visit")
await ensure_service_center_approved(session, service_center_id)
await ensure_center_vehicle_access(session, service_center_id, vehicle, current_user)
visit = ServiceVisit(