- Added centralized, self-learning GeoService (ZIP, City, Street) - Implemented Hybrid Address Management (Centralized table + Denormalized fields) - Fixed Gamification logic (PointsLedger field names & filtering) - Added address autocomplete and two-tier (Free/Premium) search API - Synchronized UserStats and PointsLedger schemas
26 lines
967 B
Python
Executable File
26 lines
967 B
Python
Executable File
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy import select, text
|
|
from app.models.gamification import UserStats, PointsLedger
|
|
from app.models.identity import User
|
|
|
|
class GamificationService:
|
|
@staticmethod
|
|
async def award_points(db: AsyncSession, user_id: int, points: int, reason: str):
|
|
"""Pontok jóváírása (SQL szinkronizált points mezővel)."""
|
|
new_entry = PointsLedger(
|
|
user_id=user_id,
|
|
points=points, # Javítva: points_change helyett points
|
|
reason=reason
|
|
)
|
|
db.add(new_entry)
|
|
|
|
result = await db.execute(select(UserStats).where(UserStats.user_id == user_id))
|
|
stats = result.scalar_one_or_none()
|
|
|
|
if not stats:
|
|
stats = UserStats(user_id=user_id, total_points=0, current_level=1)
|
|
db.add(stats)
|
|
|
|
stats.total_points += points
|
|
await db.flush()
|
|
return stats.total_points |