Skip to content

Commit 7f59064

Browse files
committed
feat: add current, next and previous device endpoints
1 parent 97b45ca commit 7f59064

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

app/spotify/router.py

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,63 @@
22
from fastapi import APIRouter, Depends
33

44
from app.container import Container
5-
from app.spotify.schemas import Device
5+
from app.spotify.schemas import Device, CurrentDevice
66
from app.spotify.service import SpotifyService
77

88
spotify_router = APIRouter()
99

1010

11-
@spotify_router.get("/devices")
11+
@spotify_router.get("/device")
1212
@inject
13-
def get_devices(
14-
spotify_service: SpotifyService = Depends(Provide[Container.spotify_service]),
15-
) -> list[Device]:
16-
return spotify_service.refresh_devices()
13+
def get_current_device(
14+
spotify_service: SpotifyService = Depends(Provide[Container.spotify_service])
15+
) -> CurrentDevice | dict:
16+
spotify_service.refresh_devices()
17+
current_device = spotify_service.get_current_device()
18+
19+
if current_device is None:
20+
return {}
21+
22+
return CurrentDevice(
23+
device=current_device,
24+
index=spotify_service.get_current_device_index(),
25+
total=spotify_service.get_devices_count()
26+
)
27+
28+
29+
@spotify_router.get("/device/next")
30+
@inject
31+
def next_device(
32+
spotify_service: SpotifyService = Depends(Provide[Container.spotify_service])
33+
) -> CurrentDevice | dict:
34+
spotify_service.refresh_devices()
35+
spotify_service.next_device()
36+
current_device = spotify_service.get_current_device()
37+
38+
if current_device is None:
39+
return {}
40+
41+
return CurrentDevice(
42+
device=current_device,
43+
index=spotify_service.get_current_device_index(),
44+
total=spotify_service.get_devices_count()
45+
)
46+
47+
48+
@spotify_router.get("/device/previous")
49+
@inject
50+
def previous_device(
51+
spotify_service: SpotifyService = Depends(Provide[Container.spotify_service])
52+
) -> CurrentDevice | dict:
53+
spotify_service.refresh_devices()
54+
spotify_service.previous_device()
55+
current_device = spotify_service.get_current_device()
56+
57+
if current_device is None:
58+
return {}
59+
60+
return CurrentDevice(
61+
device=current_device,
62+
index=spotify_service.get_current_device_index(),
63+
total=spotify_service.get_devices_count()
64+
)

0 commit comments

Comments
 (0)