refactor: Update player seek functionality to use consistent position field across schemas and services
All checks were successful
Backend CI / test (push) Successful in 4m5s
All checks were successful
Backend CI / test (push) Successful in 4m5s
This commit is contained in:
@@ -137,10 +137,10 @@ async def seek(
|
||||
"""Seek to specific position in current track."""
|
||||
try:
|
||||
player = get_player_service()
|
||||
await player.seek(request.position_ms)
|
||||
return MessageResponse(message=f"Seeked to position {request.position_ms}ms")
|
||||
await player.seek(request.position)
|
||||
return MessageResponse(message=f"Seeked to position {request.position}ms")
|
||||
except Exception as e:
|
||||
logger.exception("Error seeking to position %s", request.position_ms)
|
||||
logger.exception("Error seeking to position %s", request.position)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to seek",
|
||||
|
||||
@@ -10,7 +10,7 @@ from app.services.player import PlayerMode
|
||||
class PlayerSeekRequest(BaseModel):
|
||||
"""Request model for seek operation."""
|
||||
|
||||
position_ms: int = Field(ge=0, description="Position in milliseconds")
|
||||
position: int = Field(ge=0, description="Position in milliseconds")
|
||||
|
||||
|
||||
class PlayerVolumeRequest(BaseModel):
|
||||
@@ -35,8 +35,8 @@ class PlayerStateResponse(BaseModel):
|
||||
playlist: dict[str, Any] | None = Field(
|
||||
None, description="Current playlist information"
|
||||
)
|
||||
position_ms: int = Field(description="Current position in milliseconds")
|
||||
duration_ms: int | None = Field(
|
||||
position: int = Field(description="Current position in milliseconds")
|
||||
duration: int | None = Field(
|
||||
None, description="Total duration in milliseconds",
|
||||
)
|
||||
volume: int = Field(description="Current volume (0-100)")
|
||||
|
||||
@@ -64,8 +64,8 @@ class PlayerState:
|
||||
"status": self.status.value,
|
||||
"mode": self.mode.value,
|
||||
"volume": self.volume,
|
||||
"position_ms": self.current_sound_position or 0,
|
||||
"duration_ms": self.current_sound_duration,
|
||||
"position": self.current_sound_position or 0,
|
||||
"duration": self.current_sound_duration,
|
||||
"index": self.current_sound_index,
|
||||
"current_sound": self._serialize_sound(self.current_sound),
|
||||
"playlist": {
|
||||
|
||||
@@ -278,17 +278,17 @@ class TestPlayerEndpoints:
|
||||
mock_player_service,
|
||||
):
|
||||
"""Test seeking to position successfully."""
|
||||
position_ms = 5000
|
||||
position = 5000
|
||||
response = await authenticated_client.post(
|
||||
"/api/v1/player/seek",
|
||||
json={"position_ms": position_ms},
|
||||
json={"position": position},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["message"] == f"Seeked to position {position_ms}ms"
|
||||
assert data["message"] == f"Seeked to position {position}ms"
|
||||
|
||||
mock_player_service.seek.assert_called_once_with(position_ms)
|
||||
mock_player_service.seek.assert_called_once_with(position)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_seek_invalid_position(
|
||||
@@ -300,7 +300,7 @@ class TestPlayerEndpoints:
|
||||
"""Test seeking with invalid position."""
|
||||
response = await authenticated_client.post(
|
||||
"/api/v1/player/seek",
|
||||
json={"position_ms": -1000}, # Negative position
|
||||
json={"position": -1000}, # Negative position
|
||||
)
|
||||
|
||||
assert response.status_code == 422 # Validation error
|
||||
@@ -310,7 +310,7 @@ class TestPlayerEndpoints:
|
||||
"""Test seeking without authentication."""
|
||||
response = await client.post(
|
||||
"/api/v1/player/seek",
|
||||
json={"position_ms": 5000},
|
||||
json={"position": 5000},
|
||||
)
|
||||
assert response.status_code == 401
|
||||
|
||||
@@ -326,7 +326,7 @@ class TestPlayerEndpoints:
|
||||
|
||||
response = await authenticated_client.post(
|
||||
"/api/v1/player/seek",
|
||||
json={"position_ms": 5000},
|
||||
json={"position": 5000},
|
||||
)
|
||||
|
||||
assert response.status_code == 500
|
||||
@@ -516,8 +516,8 @@ class TestPlayerEndpoints:
|
||||
"status": PlayerStatus.PLAYING.value,
|
||||
"mode": PlayerMode.CONTINUOUS.value,
|
||||
"volume": 50,
|
||||
"position_ms": 5000,
|
||||
"duration_ms": 30000,
|
||||
"position": 5000,
|
||||
"duration": 30000,
|
||||
"index": 0,
|
||||
"current_sound": {
|
||||
"id": 1,
|
||||
@@ -625,7 +625,7 @@ class TestPlayerEndpoints:
|
||||
"""Test seeking to position zero."""
|
||||
response = await authenticated_client.post(
|
||||
"/api/v1/player/seek",
|
||||
json={"position_ms": 0},
|
||||
json={"position": 0},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
@@ -65,14 +65,13 @@ class TestPlayerState:
|
||||
assert result["status"] == "playing"
|
||||
assert result["mode"] == "loop"
|
||||
assert result["volume"] == 75
|
||||
assert result["current_sound_id"] == 1
|
||||
assert result["current_sound_index"] == 0
|
||||
assert result["current_sound_position"] == 5000
|
||||
assert result["current_sound_duration"] == 30000
|
||||
assert result["playlist_id"] == 1
|
||||
assert result["playlist_name"] == "Test Playlist"
|
||||
assert result["playlist_length"] == 5
|
||||
assert result["playlist_duration"] == 150000
|
||||
assert result["position"] == 5000
|
||||
assert result["duration"] == 30000
|
||||
assert result["index"] == 0
|
||||
assert result["playlist"]["id"] == 1
|
||||
assert result["playlist"]["name"] == "Test Playlist"
|
||||
assert result["playlist"]["length"] == 5
|
||||
assert result["playlist"]["duration"] == 150000
|
||||
|
||||
def test_serialize_sound_with_sound_object(self):
|
||||
"""Test serializing a sound object."""
|
||||
|
||||
Reference in New Issue
Block a user