átlagos kiegészítséek jó sok
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# /opt/docker/dev/service_finder/backend/app/api/v1/endpoints/assets.py
|
||||
import uuid
|
||||
import logging
|
||||
from typing import Any, Dict, List
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@@ -8,11 +9,12 @@ from sqlalchemy.orm import selectinload
|
||||
|
||||
from app.db.session import get_db
|
||||
from app.api.deps import get_current_user
|
||||
from app.models.asset import Asset, AssetCost
|
||||
from app.models import Asset, AssetCost
|
||||
from app.models.identity import User
|
||||
from app.services.cost_service import cost_service
|
||||
from app.services.asset_service import AssetService
|
||||
from app.schemas.asset_cost import AssetCostCreate, AssetCostResponse
|
||||
from app.schemas.asset import AssetResponse
|
||||
from app.schemas.asset import AssetResponse, AssetCreate
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -51,4 +53,39 @@ async def list_asset_costs(
|
||||
.limit(limit)
|
||||
)
|
||||
res = await db.execute(stmt)
|
||||
return res.scalars().all()
|
||||
return res.scalars().all()
|
||||
|
||||
|
||||
@router.post("/vehicles", response_model=AssetResponse, status_code=status.HTTP_201_CREATED)
|
||||
async def create_or_claim_vehicle(
|
||||
payload: AssetCreate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""
|
||||
Új jármű hozzáadása vagy meglévő jármű igénylése a flottához.
|
||||
|
||||
A végpont a következőket végzi:
|
||||
- Ellenőrzi a felhasználó járműlimitjét
|
||||
- Ha a VIN már létezik, tulajdonjog-átvitelt kezdeményez
|
||||
- Ha új, létrehozza a járművet és a kapcsolódó digitális ikreket
|
||||
- XP jutalom adása a felhasználónak
|
||||
"""
|
||||
try:
|
||||
asset = await AssetService.create_or_claim_vehicle(
|
||||
db=db,
|
||||
user_id=current_user.id,
|
||||
org_id=payload.organization_id,
|
||||
vin=payload.vin,
|
||||
license_plate=payload.license_plate,
|
||||
catalog_id=payload.catalog_id
|
||||
)
|
||||
return asset
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.error(f"Vehicle creation error: {e}")
|
||||
raise HTTPException(status_code=500, detail="Belső szerverhiba a jármű létrehozásakor")
|
||||
Reference in New Issue
Block a user