feat: Enhance WebSocket sound playback with credit validation and refactor related methods
Some checks failed
Backend CI / lint (push) Has been cancelled
Backend CI / test (push) Has been cancelled

This commit is contained in:
JSC
2025-08-19 22:28:54 +02:00
parent a82acfae50
commit b808cfaddf
3 changed files with 100 additions and 135 deletions

View File

@@ -6,6 +6,7 @@ from collections.abc import Callable
from pathlib import Path
from typing import Any
from fastapi import HTTPException, status
from sqlmodel.ext.asyncio.session import AsyncSession
from app.core.logging import get_logger
@@ -14,6 +15,7 @@ from app.models.sound import Sound
from app.models.sound_played import SoundPlayed
from app.repositories.sound import SoundRepository
from app.repositories.user import UserRepository
from app.services.credit import CreditService, InsufficientCreditsError
from app.services.socket import socket_manager
from app.utils.audio import get_sound_file_path
@@ -309,7 +311,9 @@ class VLCPlayerService:
await session.close()
async def play_sound_with_credits(
self, sound_id: int, user_id: int
self,
sound_id: int,
user_id: int,
) -> dict[str, str | int | bool]:
"""Play sound with VLC with credit validation and deduction.
@@ -326,11 +330,8 @@ class VLCPlayerService:
Raises:
HTTPException: For various error conditions (sound not found,
insufficient credits, VLC failure)
"""
from fastapi import HTTPException, status
from app.services.credit import CreditService, InsufficientCreditsError
if not self.db_session_factory:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,