Renamed Id to ID, following GoLang convention

This commit is contained in:
Deluan
2020-01-09 23:33:01 -05:00
committed by Deluan Quintão
parent 018352463f
commit 40904b220e
35 changed files with 122 additions and 122 deletions
+4 -4
View File
@@ -116,7 +116,7 @@ func (b *browser) GetSong(id string) (*Entry, error) {
func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *DirectoryInfo {
dir := &DirectoryInfo{
Id: a.Id,
Id: a.ID,
Name: a.Name,
AlbumCount: a.AlbumCount,
}
@@ -131,14 +131,14 @@ func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *Direct
func (b *browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *DirectoryInfo {
dir := &DirectoryInfo{
Id: al.Id,
Id: al.ID,
Name: al.Name,
Parent: al.ArtistId,
Parent: al.ArtistID,
PlayCount: int32(al.PlayCount),
UserRating: al.Rating,
Starred: al.StarredAt,
Artist: al.Artist,
ArtistId: al.ArtistId,
ArtistId: al.ArtistID,
SongCount: al.SongCount,
Duration: al.Duration,
Created: al.CreatedAt,
+10 -10
View File
@@ -45,7 +45,7 @@ type Entries []Entry
func FromArtist(ar *domain.Artist) Entry {
e := Entry{}
e.Id = ar.Id
e.Id = ar.ID
e.Title = ar.Name
e.AlbumCount = ar.AlbumCount
e.IsDir = true
@@ -54,10 +54,10 @@ func FromArtist(ar *domain.Artist) Entry {
func FromAlbum(al *domain.Album) Entry {
e := Entry{}
e.Id = al.Id
e.Id = al.ID
e.Title = al.Name
e.IsDir = true
e.Parent = al.ArtistId
e.Parent = al.ArtistID
e.Album = al.Name
e.Year = al.Year
e.Artist = al.AlbumArtist
@@ -66,8 +66,8 @@ func FromAlbum(al *domain.Album) Entry {
e.Starred = al.StarredAt
e.PlayCount = int32(al.PlayCount)
e.Created = al.CreatedAt
e.AlbumId = al.Id
e.ArtistId = al.ArtistId
e.AlbumId = al.ID
e.ArtistId = al.ArtistID
e.UserRating = al.Rating
e.Duration = al.Duration
e.SongCount = al.SongCount
@@ -76,10 +76,10 @@ func FromAlbum(al *domain.Album) Entry {
func FromMediaFile(mf *domain.MediaFile) Entry {
e := Entry{}
e.Id = mf.Id
e.Id = mf.ID
e.Title = mf.Title
e.IsDir = false
e.Parent = mf.AlbumId
e.Parent = mf.AlbumID
e.Album = mf.Album
e.Year = mf.Year
e.Artist = mf.Artist
@@ -91,7 +91,7 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
e.BitRate = mf.BitRate
e.Starred = mf.StarredAt
if mf.HasCoverArt {
e.CoverArt = mf.Id
e.CoverArt = mf.ID
}
e.ContentType = mf.ContentType()
// Creates a "pseudo" path, to avoid sending absolute paths to the client
@@ -101,8 +101,8 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
e.PlayCount = int32(mf.PlayCount)
e.DiscNumber = mf.DiscNumber
e.Created = mf.CreatedAt
e.AlbumId = mf.AlbumId
e.ArtistId = mf.ArtistId
e.AlbumId = mf.AlbumID
e.ArtistId = mf.ArtistID
e.Type = "music" // TODO Hardcoded for now
e.UserRating = mf.Rating
return e
+5 -5
View File
@@ -32,7 +32,7 @@ func TestCover(t *testing.T) {
})
})
Convey("When id is found", func() {
mockMediaFileRepo.SetData(`[{"Id":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
mockMediaFileRepo.SetData(`[{"ID":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
err := cover.Get("2", 0, out)
Convey("Then it should return the cover from the file", func() {
@@ -41,7 +41,7 @@ func TestCover(t *testing.T) {
})
})
Convey("When there is an error accessing the database", func() {
mockMediaFileRepo.SetData(`[{"Id":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
mockMediaFileRepo.SetData(`[{"ID":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
mockMediaFileRepo.SetError(true)
err := cover.Get("2", 0, out)
@@ -50,7 +50,7 @@ func TestCover(t *testing.T) {
})
})
Convey("When id is found but file is not present", func() {
mockMediaFileRepo.SetData(`[{"Id":"2","HasCoverArt":true,"Path":"tests/fixtures/NOT_FOUND.mp3"}]`, 1)
mockMediaFileRepo.SetData(`[{"ID":"2","HasCoverArt":true,"Path":"tests/fixtures/NOT_FOUND.mp3"}]`, 1)
err := cover.Get("2", 0, out)
Convey("Then it should return DatNotFound error", func() {
@@ -58,7 +58,7 @@ func TestCover(t *testing.T) {
})
})
Convey("When specifying a size", func() {
mockMediaFileRepo.SetData(`[{"Id":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
mockMediaFileRepo.SetData(`[{"ID":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
err := cover.Get("2", 100, out)
Convey("Then image returned should be 100x100", func() {
@@ -71,7 +71,7 @@ func TestCover(t *testing.T) {
})
})
Convey("When id is for an album", func() {
mockAlbumRepo.SetData(`[{"Id":"1","CoverArtPath":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
mockAlbumRepo.SetData(`[{"ID":"1","CoverArtPath":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
err := cover.Get("al-1", 0, out)
Convey("Then it should return the cover for the album", func() {
+1 -1
View File
@@ -138,7 +138,7 @@ func (g *listGenerator) GetNowPlaying() (Entries, error) {
}
entries := make(Entries, len(npInfo))
for i, np := range npInfo {
mf, err := g.mfRepository.Get(np.TrackId)
mf, err := g.mfRepository.Get(np.TrackID)
if err != nil {
return nil, err
}
+3 -3
View File
@@ -67,7 +67,7 @@ func (p *playlists) Update(playlistId string, name *string, idsToAdd []string, i
}
if name != nil {
pl.Name = *name
err := p.itunes.RenamePlaylist(pl.Id, pl.Name)
err := p.itunes.RenamePlaylist(pl.ID, pl.Name)
if err != nil {
return err
}
@@ -78,7 +78,7 @@ func (p *playlists) Update(playlistId string, name *string, idsToAdd []string, i
pl.Tracks, pl.Tracks[len(pl.Tracks)-1] = append(pl.Tracks[:i], pl.Tracks[i+1:]...), ""
}
pl.Tracks = append(pl.Tracks, idsToAdd...)
err := p.itunes.UpdatePlaylist(pl.Id, pl.Tracks)
err := p.itunes.UpdatePlaylist(pl.ID, pl.Tracks)
if err != nil {
return err
}
@@ -94,7 +94,7 @@ func (p *playlists) Get(id string) (*PlaylistInfo, error) {
}
pinfo := &PlaylistInfo{
Id: pl.Id,
Id: pl.ID,
Name: pl.Name,
SongCount: len(pl.Tracks),
Duration: pl.Duration,
+4 -4
View File
@@ -33,7 +33,7 @@ func (r ratings) SetRating(ctx context.Context, id string, rating int) error {
mfs, _ := r.mfRepo.FindByAlbum(id)
if len(mfs) > 0 {
log.Debug(ctx, "Set Rating", "value", rating, "album", mfs[0].Album)
if err := r.itunes.SetAlbumRating(mfs[0].Id, rating); err != nil {
if err := r.itunes.SetAlbumRating(mfs[0].ID, rating); err != nil {
return err
}
}
@@ -46,7 +46,7 @@ func (r ratings) SetRating(ctx context.Context, id string, rating int) error {
}
if mf != nil {
log.Debug(ctx, "Set Rating", "value", rating, "song", mf.Title)
if err := r.itunes.SetTrackRating(mf.Id, rating); err != nil {
if err := r.itunes.SetTrackRating(mf.ID, rating); err != nil {
return err
}
return nil
@@ -61,7 +61,7 @@ func (r ratings) SetStar(ctx context.Context, star bool, ids ...string) error {
mfs, _ := r.mfRepo.FindByAlbum(id)
if len(mfs) > 0 {
log.Debug(ctx, "Set Star", "value", star, "album", mfs[0].Album)
if err := r.itunes.SetAlbumLoved(mfs[0].Id, star); err != nil {
if err := r.itunes.SetAlbumLoved(mfs[0].ID, star); err != nil {
return err
}
}
@@ -74,7 +74,7 @@ func (r ratings) SetStar(ctx context.Context, star bool, ids ...string) error {
}
if mf != nil {
log.Debug(ctx, "Set Star", "value", star, "song", mf.Title)
if err := r.itunes.SetTrackLoved(mf.Id, star); err != nil {
if err := r.itunes.SetTrackLoved(mf.ID, star); err != nil {
return err
}
continue
+9 -9
View File
@@ -38,14 +38,14 @@ func (s *scrobbler) detectSkipped(ctx context.Context, playerId int, trackId str
return
case 1:
np, _ := s.npRepo.Tail(playerId)
if np.TrackId != trackId {
if np.TrackID != trackId {
return
}
s.npRepo.Dequeue(playerId)
default:
prev, _ := s.npRepo.Dequeue(playerId)
for {
if prev.TrackId == trackId {
if prev.TrackID == trackId {
break
}
np, err := s.npRepo.Dequeue(playerId)
@@ -54,15 +54,15 @@ func (s *scrobbler) detectSkipped(ctx context.Context, playerId int, trackId str
}
diff := np.Start.Sub(prev.Start)
if diff < minSkipped || diff > maxSkipped {
log.Debug(ctx, fmt.Sprintf("-- Playtime for track %s was %v. Not skipping.", prev.TrackId, diff))
log.Debug(ctx, fmt.Sprintf("-- Playtime for track %s was %v. Not skipping.", prev.TrackID, diff))
prev = np
continue
}
err = s.itunes.MarkAsSkipped(prev.TrackId, prev.Start.Add(1*time.Minute))
err = s.itunes.MarkAsSkipped(prev.TrackID, prev.Start.Add(1*time.Minute))
if err != nil {
log.Warn(ctx, "Error skipping track", "id", prev.TrackId)
log.Warn(ctx, "Error skipping track", "id", prev.TrackID)
} else {
log.Debug(ctx, "-- Skipped track "+prev.TrackId)
log.Debug(ctx, "-- Skipped track "+prev.TrackID)
}
}
}
@@ -77,7 +77,7 @@ func (s *scrobbler) Register(ctx context.Context, playerId int, trackId string,
}
if mf == nil {
return nil, errors.New(fmt.Sprintf(`Id "%s" not found`, trackId))
return nil, errors.New(fmt.Sprintf(`ID "%s" not found`, trackId))
}
if err := s.itunes.MarkAsPlayed(trackId, playTime); err != nil {
@@ -93,9 +93,9 @@ func (s *scrobbler) NowPlaying(ctx context.Context, playerId int, playerName, tr
}
if mf == nil {
return nil, errors.New(fmt.Sprintf(`Id "%s" not found`, trackId))
return nil, errors.New(fmt.Sprintf(`ID "%s" not found`, trackId))
}
info := &domain.NowPlayingInfo{TrackId: trackId, Username: username, Start: time.Now(), PlayerId: playerId, PlayerName: playerName}
info := &domain.NowPlayingInfo{TrackID: trackId, Username: username, Start: time.Now(), PlayerId: playerId, PlayerName: playerName}
return mf, s.npRepo.Enqueue(info)
}
+9 -9
View File
@@ -23,7 +23,7 @@ func TestScrobbler(t *testing.T) {
scrobbler := engine.NewScrobbler(itCtrl, mfRepo, npRepo)
Convey("Given a DB with one song", t, func() {
mfRepo.SetData(`[{"Id":"2","Title":"Hands Of Time"}]`, 1)
mfRepo.SetData(`[{"ID":"2","Title":"Hands Of Time"}]`, 1)
Convey("When I scrobble an existing song", func() {
now := time.Now()
@@ -63,7 +63,7 @@ func TestScrobbler(t *testing.T) {
Convey("And it saves the song as the one current playing", func() {
info, _ := npRepo.Head(1)
So(info.TrackId, ShouldEqual, "2")
So(info.TrackID, ShouldEqual, "2")
// Commenting out time sensitive test, due to flakiness
// So(info.Start, ShouldHappenBefore, time.Now())
So(info.Username, ShouldEqual, "deluan")
@@ -95,7 +95,7 @@ func TestSkipping(t *testing.T) {
scrobbler := engine.NewScrobbler(itCtrl, mfRepo, npRepo)
Convey("Given a DB with three songs", t, func() {
mfRepo.SetData(`[{"Id":"1","Title":"Femme Fatale"},{"Id":"2","Title":"Here She Comes Now"},{"Id":"3","Title":"Lady Godiva's Operation"}]`, 3)
mfRepo.SetData(`[{"ID":"1","Title":"Femme Fatale"},{"ID":"2","Title":"Here She Comes Now"},{"ID":"3","Title":"Lady Godiva's Operation"}]`, 3)
itCtrl.skipped = make(map[string]time.Time)
npRepo.ClearAll()
Convey("When I skip 2 songs", func() {
@@ -109,7 +109,7 @@ func TestSkipping(t *testing.T) {
np, err := npRepo.GetAll()
So(err, ShouldBeNil)
So(np, ShouldHaveLength, 1)
So(np[0].TrackId, ShouldEqual, "2")
So(np[0].TrackID, ShouldEqual, "2")
})
})
Convey("When I play one song", func() {
@@ -120,7 +120,7 @@ func TestSkipping(t *testing.T) {
scrobbler.NowPlaying(nil, 1, "DSub", "2", "deluan")
Convey("Then the first song should be marked as skipped", func() {
mf, err := scrobbler.Register(nil, 1, "2", aPointInTime.Add(3*time.Minute))
So(mf.Id, ShouldEqual, "2")
So(mf.ID, ShouldEqual, "2")
So(itCtrl.skipped, ShouldContainKey, "1")
So(err, ShouldBeNil)
})
@@ -130,7 +130,7 @@ func TestSkipping(t *testing.T) {
scrobbler.NowPlaying(nil, 1, "DSub", "2", "deluan")
Convey("Then the first song should be marked as skipped", func() {
mf, err := scrobbler.Register(nil, 1, "2", aPointInTime.Add(3*time.Minute))
So(mf.Id, ShouldEqual, "2")
So(mf.ID, ShouldEqual, "2")
So(itCtrl.skipped, ShouldBeEmpty)
So(err, ShouldBeNil)
})
@@ -140,7 +140,7 @@ func TestSkipping(t *testing.T) {
scrobbler.NowPlaying(nil, 1, "DSub", "2", "deluan")
Convey("Then the first song should be marked as skipped", func() {
mf, err := scrobbler.Register(nil, 1, "2", aPointInTime.Add(3*time.Minute))
So(mf.Id, ShouldEqual, "2")
So(mf.ID, ShouldEqual, "2")
So(itCtrl.skipped, ShouldBeEmpty)
So(err, ShouldBeNil)
})
@@ -148,7 +148,7 @@ func TestSkipping(t *testing.T) {
Convey("And I scrobble it before starting to play the other song", func() {
mf, err := scrobbler.Register(nil, 1, "1", time.Now())
Convey("Then the first song should NOT marked as skipped", func() {
So(mf.Id, ShouldEqual, "1")
So(mf.ID, ShouldEqual, "1")
So(itCtrl.skipped, ShouldBeEmpty)
So(err, ShouldBeNil)
})
@@ -163,7 +163,7 @@ func TestSkipping(t *testing.T) {
Convey("Then the NowPlaying song should be the last one", func() {
np, _ := npRepo.GetAll()
So(np, ShouldHaveLength, 1)
So(np[0].TrackId, ShouldEqual, "2")
So(np[0].TrackID, ShouldEqual, "2")
})
})
})
+4 -4
View File
@@ -62,15 +62,15 @@ func (s *search) ClearAll() error {
}
func (s *search) IndexArtist(ar *domain.Artist) error {
return s.idxArtist.Index(ar.Id, sanitize.Accents(strings.ToLower(ar.Name)))
return s.idxArtist.Index(ar.ID, sanitize.Accents(strings.ToLower(ar.Name)))
}
func (s *search) IndexAlbum(al *domain.Album) error {
return s.idxAlbum.Index(al.Id, sanitize.Accents(strings.ToLower(al.Name)))
return s.idxAlbum.Index(al.ID, sanitize.Accents(strings.ToLower(al.Name)))
}
func (s *search) IndexMediaFile(mf *domain.MediaFile) error {
return s.idxSong.Index(mf.Id, sanitize.Accents(strings.ToLower(mf.Title)))
return s.idxSong.Index(mf.ID, sanitize.Accents(strings.ToLower(mf.Title)))
}
func (s *search) RemoveArtist(ids ...string) error {
@@ -153,7 +153,7 @@ func criticalError(ctx context.Context, kind, id string, err error) bool {
case err != nil:
return true
case err == domain.ErrNotFound:
log.Warn(ctx, kind+"Id not in DB. Need a reindex?", "id", id)
log.Warn(ctx, kind+"ID not in DB. Need a reindex?", "id", id)
}
return false
}