feat(api): finish Group A stubbed endpoints
Implements previously-stubbed /api/v1 endpoints (hexagonal: ports -> repos
-> services -> routers wired in deps):
- playlists: GET /{id}/cover (serves stored cover, 404 when absent)
- settings: GET/PATCH /settings + GET/PUT /settings/scrobbling — lazy
per-user row, write-only Fernet-encrypted scrobble session key; adds
user_settings table + migration (chains off dc126696f5a6)
- storage: GET /duplicates, /broken, /missing-metadata + admin POST
/cleanup (arq cleanup_storage worker; reconciles local refs only,
guarded against a storage-outage mass delete)
- admin: GET /services, /sources, /settings + POST /reindex; PATCH
/settings and /sources/{source} return 501 (config is env-managed)
Adds NotSupportedError (-> HTTP 501). Integration tests for each surface.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,23 +1,67 @@
|
||||
"""User settings endpoints, including scrobbling configuration."""
|
||||
"""User settings endpoints, including scrobbling configuration.
|
||||
|
||||
from typing import Any
|
||||
Settings are per-caller and created lazily, so a first read returns defaults.
|
||||
The scrobbler session key is write-only — accepted on ``PUT`` but never returned.
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api.deps import CurrentUser, UserSettingsServiceDep
|
||||
from app.api.schemas.settings import (
|
||||
ScrobblingOut,
|
||||
ScrobblingUpdate,
|
||||
SettingsOut,
|
||||
SettingsUpdate,
|
||||
)
|
||||
from app.domain.entities.settings import UserSettings
|
||||
|
||||
router = APIRouter(prefix="/settings", tags=["settings"])
|
||||
|
||||
|
||||
def _to_settings_out(settings: UserSettings) -> SettingsOut:
|
||||
return SettingsOut(theme=settings.theme, stream_quality=settings.stream_quality)
|
||||
|
||||
|
||||
def _to_scrobbling_out(settings: UserSettings) -> ScrobblingOut:
|
||||
return ScrobblingOut(
|
||||
enabled=settings.scrobble_enabled,
|
||||
provider=settings.scrobble_provider,
|
||||
username=settings.scrobble_username,
|
||||
configured=settings.scrobble_session_key_enc is not None,
|
||||
)
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def get_settings() -> Any: ...
|
||||
async def get_settings(user: CurrentUser, service: UserSettingsServiceDep) -> SettingsOut:
|
||||
return _to_settings_out(await service.get(user.id))
|
||||
|
||||
|
||||
@router.patch("")
|
||||
async def update_settings() -> Any: ...
|
||||
async def update_settings(
|
||||
body: SettingsUpdate, user: CurrentUser, service: UserSettingsServiceDep
|
||||
) -> SettingsOut:
|
||||
settings = await service.update_general(
|
||||
user.id, theme=body.theme, stream_quality=body.stream_quality
|
||||
)
|
||||
return _to_settings_out(settings)
|
||||
|
||||
|
||||
@router.get("/scrobbling")
|
||||
async def get_scrobbling_settings() -> Any: ...
|
||||
async def get_scrobbling_settings(
|
||||
user: CurrentUser, service: UserSettingsServiceDep
|
||||
) -> ScrobblingOut:
|
||||
return _to_scrobbling_out(await service.get(user.id))
|
||||
|
||||
|
||||
@router.put("/scrobbling")
|
||||
async def set_scrobbling_settings() -> Any: ...
|
||||
async def set_scrobbling_settings(
|
||||
body: ScrobblingUpdate, user: CurrentUser, service: UserSettingsServiceDep
|
||||
) -> ScrobblingOut:
|
||||
settings = await service.set_scrobbling(
|
||||
user.id,
|
||||
enabled=body.enabled,
|
||||
provider=body.provider,
|
||||
username=body.username,
|
||||
session_key=body.session_key,
|
||||
)
|
||||
return _to_scrobbling_out(settings)
|
||||
|
||||
Reference in New Issue
Block a user