feat: implement hybrid address system and premium search logic
- 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
This commit is contained in:
@@ -1,40 +1,26 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select, text
|
||||
from app.models.gamification import UserStats, PointsLedger
|
||||
from sqlalchemy import select
|
||||
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 és a UserStats frissítése"""
|
||||
|
||||
# 1. Bejegyzés a naplóba (Mezőnevek szinkronizálva a modellel)
|
||||
"""Pontok jóváírása (SQL szinkronizált points mezővel)."""
|
||||
new_entry = PointsLedger(
|
||||
user_id=user_id,
|
||||
points_change=points,
|
||||
points=points, # Javítva: points_change helyett points
|
||||
reason=reason
|
||||
)
|
||||
db.add(new_entry)
|
||||
|
||||
# 2. Összesített statisztika lekérése/létrehozása
|
||||
result = await db.execute(select(UserStats).where(UserStats.user_id == user_id))
|
||||
stats = result.scalar_one_or_none()
|
||||
|
||||
if not stats:
|
||||
# Ha új a user, létrehozzuk az alap statisztikát
|
||||
stats = UserStats(
|
||||
user_id=user_id,
|
||||
total_points=0,
|
||||
current_level=1
|
||||
)
|
||||
stats = UserStats(user_id=user_id, total_points=0, current_level=1)
|
||||
db.add(stats)
|
||||
|
||||
# 3. Pontok hozzáadása
|
||||
stats.total_points += points
|
||||
|
||||
# Itt fogjuk később meghívni a szintlépési logikát
|
||||
# await GamificationService._check_level_up(stats)
|
||||
|
||||
# Fontos: Nem commitolunk itt, hanem hagyjuk, hogy a hívó (SocialService)
|
||||
# egy tranzakcióban mentse el a szolgáltatót és a pontokat!
|
||||
await db.flush()
|
||||
return stats.total_points
|
||||
Reference in New Issue
Block a user