szolgáltatók beálltásai, szerkesztése , létrehozása

This commit is contained in:
Roo
2026-06-17 11:52:25 +00:00
parent 213ba3b0f1
commit bf3a971ff1
56 changed files with 14421 additions and 1512 deletions

View File

@@ -1,13 +1,13 @@
# /opt/docker/dev/service_finder/backend/app/api/v1/endpoints/billing.py
from fastapi import APIRouter, Depends, HTTPException, status, Request, Header
from fastapi import APIRouter, Depends, HTTPException, status, Request, Header, Query
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from typing import Optional, Dict, Any
from sqlalchemy import select, func, and_
from typing import Optional, Dict, Any, List
import logging
import uuid
from app.api.deps import get_db, get_current_user
from app.models.identity import User, Wallet, UserRole
from app.models import FinancialLedger, WalletType
from app.models import FinancialLedger, WalletType, LedgerEntryType, LedgerStatus
from app.models.marketplace.payment import PaymentIntent, PaymentIntentStatus
from app.services.config_service import config
from app.services.payment_router import PaymentRouter
@@ -311,4 +311,99 @@ async def get_wallet_balance(
except Exception as e:
logger.error(f"Pénztárca egyenleg lekérdezési hiba: {e}")
raise HTTPException(status_code=500, detail=f"Belső hiba: {str(e)}")
raise HTTPException(status_code=500, detail=f"Belső hiba: {str(e)}")
@router.get("/wallet/transactions")
async def get_wallet_transactions(
db: AsyncSession = Depends(get_db),
current_user: User = Depends(get_current_user),
page: int = Query(1, ge=1, description="Oldalszám"),
page_size: int = Query(20, ge=1, le=100, description="Elemek száma oldalanként"),
wallet_type: Optional[str] = Query(None, description="Szűrés pénztárca típusra (EARNED, PURCHASED, SERVICE_COINS, VOUCHER)"),
entry_type: Optional[str] = Query(None, description="Szűrés bejegyzés típusra (DEBIT, CREDIT)"),
):
"""
Bejelentkezett felhasználó tranzakciótörténetének lekérdezése (FinancialLedger).
Visszaadja a főkönyvi bejegyzéseket lapozható formában, időrendben csökkenő sorrendben.
"""
try:
# Base query
conditions = [FinancialLedger.user_id == current_user.id]
# Optional wallet_type filter
if wallet_type:
try:
wt = WalletType(wallet_type.upper())
conditions.append(FinancialLedger.wallet_type == wt)
except ValueError:
raise HTTPException(
status_code=400,
detail=f"Érvénytelen wallet_type: {wallet_type}. Használd: {[wt.value for wt in WalletType]}"
)
# Optional entry_type filter
if entry_type:
try:
et = LedgerEntryType(entry_type.upper())
conditions.append(FinancialLedger.entry_type == et)
except ValueError:
raise HTTPException(
status_code=400,
detail=f"Érvénytelen entry_type: {entry_type}. Használd: {[et.value for et in LedgerEntryType]}"
)
# Count total matching records
count_stmt = select(func.count(FinancialLedger.id)).where(and_(*conditions))
count_result = await db.execute(count_stmt)
total_count = count_result.scalar() or 0
# Fetch paginated results
offset = (page - 1) * page_size
stmt = (
select(FinancialLedger)
.where(and_(*conditions))
.order_by(FinancialLedger.created_at.desc())
.offset(offset)
.limit(page_size)
)
result = await db.execute(stmt)
entries = result.scalars().all()
# Build response
transactions = []
for entry in entries:
description = ""
if entry.details and isinstance(entry.details, dict):
description = entry.details.get("description", "")
transactions.append({
"id": entry.id,
"transaction_id": str(entry.transaction_id),
"amount": float(entry.amount),
"entry_type": entry.entry_type.value,
"wallet_type": entry.wallet_type.value if entry.wallet_type else None,
"transaction_type": entry.transaction_type,
"description": description,
"status": entry.status.value if entry.status else None,
"balance_after": float(entry.balance_after) if entry.balance_after else None,
"currency": entry.currency or "EUR",
"created_at": entry.created_at.isoformat() if entry.created_at else None,
})
return {
"success": True,
"data": transactions,
"pagination": {
"page": page,
"page_size": page_size,
"total_count": total_count,
"total_pages": max(1, (total_count + page_size - 1) // page_size),
},
}
except HTTPException:
raise
except Exception as e:
logger.error(f"Tranzakció történet lekérdezési hiba: {e}")
raise HTTPException(status_code=500, detail=f"Belső hiba: {str(e)}")