mirror of
https://git.sr.ht/~phw/scotty
synced 2025-05-01 14:17:06 +02:00
Reduced redundancy in model conversions and consistent naming
This commit is contained in:
parent
e29d8e2a63
commit
cac88f316b
10 changed files with 107 additions and 107 deletions
|
@ -108,7 +108,7 @@ func (b *SpotifyApiBackend) ExportListens(oldestTimestamp time.Time, results cha
|
|||
listens := make(models.ListensList, 0, len(result.Items))
|
||||
|
||||
for _, listen := range result.Items {
|
||||
l := listen.ToListen()
|
||||
l := listen.AsListen()
|
||||
if l.ListenedAt.Unix() > oldestTimestamp.Unix() {
|
||||
listens = append(listens, l)
|
||||
} else {
|
||||
|
@ -168,7 +168,7 @@ out:
|
|||
|
||||
loves := make(models.LovesList, 0, perPage)
|
||||
for _, track := range result.Items {
|
||||
love := track.ToLove()
|
||||
love := track.AsLove()
|
||||
if love.Created.Unix() > oldestTimestamp.Unix() {
|
||||
loves = append(loves, love)
|
||||
} else {
|
||||
|
@ -196,27 +196,27 @@ out:
|
|||
progress <- p.Complete()
|
||||
}
|
||||
|
||||
func (l Listen) ToListen() models.Listen {
|
||||
func (l Listen) AsListen() models.Listen {
|
||||
listenedAt, _ := time.Parse(time.RFC3339, l.PlayedAt)
|
||||
listen := models.Listen{
|
||||
ListenedAt: listenedAt,
|
||||
Track: l.Track.ToTrack(),
|
||||
Track: l.Track.AsTrack(),
|
||||
}
|
||||
|
||||
return listen
|
||||
}
|
||||
|
||||
func (t SavedTrack) ToLove() models.Love {
|
||||
func (t SavedTrack) AsLove() models.Love {
|
||||
addedAt, _ := time.Parse(time.RFC3339, t.AddedAt)
|
||||
love := models.Love{
|
||||
Created: addedAt,
|
||||
Track: t.Track.ToTrack(),
|
||||
Track: t.Track.AsTrack(),
|
||||
}
|
||||
|
||||
return love
|
||||
}
|
||||
|
||||
func (t Track) ToTrack() models.Track {
|
||||
func (t Track) AsTrack() models.Track {
|
||||
track := models.Track{
|
||||
TrackName: t.Name,
|
||||
ReleaseName: t.Album.Name,
|
||||
|
|
|
@ -28,13 +28,13 @@ import (
|
|||
"go.uploadedlobster.com/scotty/backends/spotify"
|
||||
)
|
||||
|
||||
func TestSpotifyListenToListen(t *testing.T) {
|
||||
func TestSpotifyListenAsListen(t *testing.T) {
|
||||
data, err := os.ReadFile("testdata/listen.json")
|
||||
require.NoError(t, err)
|
||||
spListen := spotify.Listen{}
|
||||
err = json.Unmarshal(data, &spListen)
|
||||
require.NoError(t, err)
|
||||
listen := spListen.ToListen()
|
||||
listen := spListen.AsListen()
|
||||
listenedAt, _ := time.Parse(time.RFC3339, "2023-11-21T15:24:33.361Z")
|
||||
assert.Equal(t, listenedAt, listen.ListenedAt)
|
||||
assert.Equal(t, time.Duration(413826*time.Millisecond), listen.Duration)
|
||||
|
@ -53,13 +53,13 @@ func TestSpotifyListenToListen(t *testing.T) {
|
|||
assert.Equal(t, []string{"https://open.spotify.com/artist/101HSR6JTJqe3DBh6rb8kz"}, info["spotify_album_artist_ids"])
|
||||
}
|
||||
|
||||
func TestSavedTrackToLove(t *testing.T) {
|
||||
func TestSavedTrackAsLove(t *testing.T) {
|
||||
data, err := os.ReadFile("testdata/track.json")
|
||||
require.NoError(t, err)
|
||||
track := spotify.SavedTrack{}
|
||||
err = json.Unmarshal(data, &track)
|
||||
require.NoError(t, err)
|
||||
love := track.ToLove()
|
||||
love := track.AsLove()
|
||||
created, _ := time.Parse(time.RFC3339, "2022-02-13T21:46:08Z")
|
||||
assert.Equal(t, created, love.Created)
|
||||
assert.Equal(t, time.Duration(187680*time.Millisecond), love.Duration)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue