Phase 2 UI Adjustments/Edits by bonamin
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Dict, List, Optional
|
||||
from enum import Enum
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@ class MelodyTone(str, Enum):
|
||||
|
||||
|
||||
class MelodyInfo(BaseModel):
|
||||
name: str
|
||||
description: str = ""
|
||||
name: Dict[str, str] = {}
|
||||
description: Dict[str, str] = {}
|
||||
melodyTone: MelodyTone = MelodyTone.normal
|
||||
customTags: List[str] = []
|
||||
minSpeed: int = 0
|
||||
maxSpeed: int = 0
|
||||
totalNotes: int = 1
|
||||
totalNotes: int = Field(default=1, ge=1, le=16)
|
||||
steps: int = 0
|
||||
color: str = ""
|
||||
isTrueRing: bool = False
|
||||
@@ -32,7 +32,7 @@ class MelodyInfo(BaseModel):
|
||||
|
||||
|
||||
class MelodyAttributes(BaseModel):
|
||||
speed: int = 0
|
||||
speed: int = 50
|
||||
duration: int = 0
|
||||
totalRunDuration: int = 0
|
||||
pauseDuration: int = 0
|
||||
|
||||
@@ -8,6 +8,13 @@ COLLECTION = "melodies"
|
||||
def _doc_to_melody(doc) -> MelodyInDB:
|
||||
"""Convert a Firestore document snapshot to a MelodyInDB model."""
|
||||
data = doc.to_dict()
|
||||
# Backward compat: if name/description are plain strings, wrap as dict
|
||||
info = data.get("information", {})
|
||||
if isinstance(info.get("name"), str):
|
||||
info["name"] = {"en": info["name"]} if info["name"] else {}
|
||||
if isinstance(info.get("description"), str):
|
||||
info["description"] = {"en": info["description"]} if info["description"] else {}
|
||||
data["information"] = info
|
||||
return MelodyInDB(id=doc.id, **data)
|
||||
|
||||
|
||||
@@ -41,8 +48,16 @@ def list_melodies(
|
||||
continue
|
||||
if search:
|
||||
search_lower = search.lower()
|
||||
name_match = search_lower in melody.information.name.lower()
|
||||
desc_match = search_lower in melody.information.description.lower()
|
||||
name_match = any(
|
||||
search_lower in v.lower()
|
||||
for v in melody.information.name.values()
|
||||
if isinstance(v, str)
|
||||
)
|
||||
desc_match = any(
|
||||
search_lower in v.lower()
|
||||
for v in melody.information.description.values()
|
||||
if isinstance(v, str)
|
||||
)
|
||||
tag_match = any(search_lower in t.lower() for t in melody.information.customTags)
|
||||
if not (name_match or desc_match or tag_match):
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user