fix: Add missing commas in function calls and improve code formatting
This commit is contained in:
@@ -17,7 +17,7 @@ logger = get_logger(__name__)
|
||||
|
||||
class SoundSortField(str, Enum):
|
||||
"""Sound sort field enumeration."""
|
||||
|
||||
|
||||
NAME = "name"
|
||||
FILENAME = "filename"
|
||||
DURATION = "duration"
|
||||
@@ -30,7 +30,7 @@ class SoundSortField(str, Enum):
|
||||
|
||||
class SortOrder(str, Enum):
|
||||
"""Sort order enumeration."""
|
||||
|
||||
|
||||
ASC = "asc"
|
||||
DESC = "desc"
|
||||
|
||||
@@ -144,18 +144,18 @@ class SoundRepository(BaseRepository[Sound]):
|
||||
"""Search and sort sounds with optional filtering."""
|
||||
try:
|
||||
statement = select(Sound)
|
||||
|
||||
|
||||
# Apply type filter
|
||||
if sound_types:
|
||||
statement = statement.where(col(Sound.type).in_(sound_types))
|
||||
|
||||
|
||||
# Apply search filter
|
||||
if search_query and search_query.strip():
|
||||
search_pattern = f"%{search_query.strip().lower()}%"
|
||||
statement = statement.where(
|
||||
func.lower(Sound.name).like(search_pattern)
|
||||
func.lower(Sound.name).like(search_pattern),
|
||||
)
|
||||
|
||||
|
||||
# Apply sorting
|
||||
if sort_by:
|
||||
sort_column = getattr(Sound, sort_by.value)
|
||||
@@ -166,19 +166,19 @@ class SoundRepository(BaseRepository[Sound]):
|
||||
else:
|
||||
# Default sorting by name ascending
|
||||
statement = statement.order_by(Sound.name.asc())
|
||||
|
||||
|
||||
# Apply pagination
|
||||
if offset > 0:
|
||||
statement = statement.offset(offset)
|
||||
if limit is not None:
|
||||
statement = statement.limit(limit)
|
||||
|
||||
|
||||
result = await self.session.exec(statement)
|
||||
return list(result.all())
|
||||
except Exception:
|
||||
logger.exception(
|
||||
"Failed to search and sort sounds: query=%s, types=%s, sort_by=%s, sort_order=%s",
|
||||
search_query, sound_types, sort_by, sort_order
|
||||
search_query, sound_types, sort_by, sort_order,
|
||||
)
|
||||
raise
|
||||
|
||||
@@ -189,17 +189,17 @@ class SoundRepository(BaseRepository[Sound]):
|
||||
func.count(Sound.id).label("count"),
|
||||
func.sum(Sound.play_count).label("total_plays"),
|
||||
func.sum(Sound.duration).label("total_duration"),
|
||||
func.sum(Sound.size + func.coalesce(Sound.normalized_size, 0)).label("total_size")
|
||||
func.sum(Sound.size + func.coalesce(Sound.normalized_size, 0)).label("total_size"),
|
||||
).where(Sound.type == "SDB")
|
||||
|
||||
|
||||
result = await self.session.exec(statement)
|
||||
row = result.first()
|
||||
|
||||
|
||||
return {
|
||||
"count": row.count if row.count is not None else 0,
|
||||
"total_plays": row.total_plays if row.total_plays is not None else 0,
|
||||
"total_duration": row.total_duration if row.total_duration is not None else 0,
|
||||
"total_size": row.total_size if row.total_size is not None else 0
|
||||
"total_size": row.total_size if row.total_size is not None else 0,
|
||||
}
|
||||
except Exception:
|
||||
logger.exception("Failed to get soundboard statistics")
|
||||
@@ -212,17 +212,17 @@ class SoundRepository(BaseRepository[Sound]):
|
||||
func.count(Sound.id).label("count"),
|
||||
func.sum(Sound.play_count).label("total_plays"),
|
||||
func.sum(Sound.duration).label("total_duration"),
|
||||
func.sum(Sound.size + func.coalesce(Sound.normalized_size, 0)).label("total_size")
|
||||
func.sum(Sound.size + func.coalesce(Sound.normalized_size, 0)).label("total_size"),
|
||||
).where(Sound.type == "EXT")
|
||||
|
||||
|
||||
result = await self.session.exec(statement)
|
||||
row = result.first()
|
||||
|
||||
|
||||
return {
|
||||
"count": row.count if row.count is not None else 0,
|
||||
"total_plays": row.total_plays if row.total_plays is not None else 0,
|
||||
"total_duration": row.total_duration if row.total_duration is not None else 0,
|
||||
"total_size": row.total_size if row.total_size is not None else 0
|
||||
"total_size": row.total_size if row.total_size is not None else 0,
|
||||
}
|
||||
except Exception:
|
||||
logger.exception("Failed to get track statistics")
|
||||
@@ -244,20 +244,20 @@ class SoundRepository(BaseRepository[Sound]):
|
||||
Sound.type,
|
||||
Sound.duration,
|
||||
Sound.created_at,
|
||||
func.count(SoundPlayed.id).label("play_count")
|
||||
func.count(SoundPlayed.id).label("play_count"),
|
||||
)
|
||||
.select_from(SoundPlayed)
|
||||
.join(Sound, SoundPlayed.sound_id == Sound.id)
|
||||
)
|
||||
|
||||
|
||||
# Apply sound type filter
|
||||
if sound_type != "all":
|
||||
statement = statement.where(Sound.type == sound_type.upper())
|
||||
|
||||
|
||||
# Apply date filter if provided
|
||||
if date_filter:
|
||||
statement = statement.where(SoundPlayed.created_at >= date_filter)
|
||||
|
||||
|
||||
# Group by sound and order by play count descending
|
||||
statement = (
|
||||
statement
|
||||
@@ -266,15 +266,15 @@ class SoundRepository(BaseRepository[Sound]):
|
||||
Sound.name,
|
||||
Sound.type,
|
||||
Sound.duration,
|
||||
Sound.created_at
|
||||
Sound.created_at,
|
||||
)
|
||||
.order_by(func.count(SoundPlayed.id).desc())
|
||||
.limit(limit)
|
||||
)
|
||||
|
||||
|
||||
result = await self.session.exec(statement)
|
||||
rows = result.all()
|
||||
|
||||
|
||||
# Convert to dictionaries with the play count from the period
|
||||
return [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user