API Cleanup

This commit is contained in:
2017-11-18 11:37:29 +01:00
parent bd293de4be
commit c5cb497722
7 changed files with 37 additions and 31 deletions

View File

@ -16,14 +16,10 @@ const maxTracks = 12
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
tracks, err := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
return !track.IsDraft && len(track.Media) > 0
})
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Error fetching soundtracks", err)
}
arn.SortSoundTracksLatestFirst(tracks)
if len(tracks) > maxTracks {
@ -42,14 +38,10 @@ func From(ctx *aero.Context) string {
return ctx.Error(http.StatusBadRequest, "Invalid start index", err)
}
allTracks, err := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
allTracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
return !track.IsDraft && len(track.Media) > 0
})
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Error fetching soundtracks", err)
}
if index < 0 || index >= len(allTracks) {
return ctx.Error(http.StatusBadRequest, "Invalid start index (maximum is "+strconv.Itoa(len(allTracks))+")", nil)
}