Initial commit: Robot ökoszisztéma v2.0 - Stabilizált jármű és szerviz robotok
This commit is contained in:
58
backend/app/api/v1/endpoints/services.py
Executable file
58
backend/app/api/v1/endpoints/services.py
Executable file
@@ -0,0 +1,58 @@
|
||||
from fastapi import APIRouter, Depends, Form, Query, HTTPException
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select, and_, text
|
||||
from typing import List, Optional
|
||||
from app.db.session import get_db
|
||||
from app.services.gamification_service import GamificationService
|
||||
from app.models.service import ServiceProfile, ExpertiseTag, ServiceExpertise
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# --- 🎯 SZERVIZ VADÁSZAT (Service Hunt) ---
|
||||
@router.post("/hunt")
|
||||
async def register_service_hunt(
|
||||
name: str = Form(...),
|
||||
lat: float = Form(...),
|
||||
lng: float = Form(...),
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
""" Új szerviz-jelölt rögzítése a staging táblába jutalompontért. """
|
||||
# Új szerviz-jelölt rögzítése
|
||||
await db.execute(text("""
|
||||
INSERT INTO data.service_staging (name, fingerprint, status, raw_data)
|
||||
VALUES (:n, :f, 'pending', jsonb_build_object('lat', :lat, 'lng', :lng))
|
||||
"""), {"n": name, "f": f"{name}-{lat}-{lng}", "lat": lat, "lng": lng})
|
||||
|
||||
# MB 2.0 Gamification: 50 pont a felfedezésért
|
||||
# TODO: A 1-es ID helyett a bejelentkezett felhasználót kell használni (current_user.id)
|
||||
await GamificationService.award_points(db, 1, 50, f"Service Hunt: {name}")
|
||||
await db.commit()
|
||||
return {"status": "success", "message": "Discovery registered and points awarded."}
|
||||
|
||||
# --- 🔍 SZERVIZ KERESŐ (Service Search) ---
|
||||
@router.get("/search")
|
||||
async def search_services(
|
||||
expertise_key: Optional[str] = Query(None, description="Szakmai címke (pl. brake_service)"),
|
||||
city: Optional[str] = Query(None, description="Város szűrés"),
|
||||
min_confidence: int = Query(0, description="Minimum hitelességi szint (0-2)"),
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
""" Szakmai szempontú keresőmotor, ami a validált címkék alapján szűr. """
|
||||
# Alap lekérdezés: Szervizek, akiknek van szakértelmük
|
||||
query = select(ServiceProfile).join(ServiceProfile.expertises).join(ServiceExpertise.tag)
|
||||
|
||||
filters = []
|
||||
if expertise_key:
|
||||
filters.append(ExpertiseTag.key == expertise_key)
|
||||
if city:
|
||||
filters.append(ServiceProfile.city.ilike(f"%{city}%"))
|
||||
if min_confidence > 0:
|
||||
filters.append(ServiceExpertise.confidence_level >= min_confidence)
|
||||
|
||||
if filters:
|
||||
query = query.where(and_(*filters))
|
||||
|
||||
result = await db.execute(query.distinct())
|
||||
services = result.scalars().all()
|
||||
|
||||
return services
|
||||
Reference in New Issue
Block a user