2018-03-13 00:49:54 +00:00
|
|
|
package soundtracks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-03-13 00:49:54 +00:00
|
|
|
)
|
|
|
|
|
2018-03-14 03:57:08 +00:00
|
|
|
// FilterByTag renders the best soundtracks filtered by tag.
|
2019-06-01 04:55:49 +00:00
|
|
|
func FilterByTag(ctx aero.Context) error {
|
2018-03-13 00:49:54 +00:00
|
|
|
tag := ctx.Get("tag")
|
|
|
|
|
2018-03-14 03:57:08 +00:00
|
|
|
// Fetch all eligible tracks
|
2018-03-14 17:07:58 +00:00
|
|
|
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
2018-03-13 00:49:54 +00:00
|
|
|
return !track.IsDraft && len(track.Media) > 0 && track.HasTag(tag)
|
|
|
|
})
|
|
|
|
|
2018-03-14 03:57:08 +00:00
|
|
|
// Sort the tracks by number of likes
|
2018-03-14 17:07:58 +00:00
|
|
|
arn.SortSoundTracksPopularFirst(tracks)
|
2018-03-13 00:49:54 +00:00
|
|
|
|
2018-03-14 17:07:58 +00:00
|
|
|
// Render
|
|
|
|
return render(ctx, tracks)
|
2018-03-13 00:49:54 +00:00
|
|
|
}
|