-
Notifications
You must be signed in to change notification settings - Fork 9
/
on_demand.go
61 lines (47 loc) · 1.55 KB
/
on_demand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package controllers
import (
"log"
"net/http"
"github.com/UniversityRadioYork/2016-site/models"
"github.com/UniversityRadioYork/2016-site/structs"
"github.com/UniversityRadioYork/2016-site/utils"
"github.com/UniversityRadioYork/myradio-go"
)
// OnDemandController is the controller for the URY On demand (URY on Tap) pages.
type OnDemandController struct {
Controller
}
// NewOnDemandController returns a new OnDemandController with the MyRadio session s
// and configuration context c.
func NewOnDemandController(s *myradio.Session, c *structs.Config) *OnDemandController {
return &OnDemandController{Controller{session: s, config: c}}
}
// Get handles the HTTP GET request r for the page, writing to w.
func (onDemandC *OnDemandController) Get(w http.ResponseWriter, r *http.Request) {
PodcastsM := models.NewPodcastModel(onDemandC.session)
latestPodcasts, err := PodcastsM.GetAllPodcasts(10, 0)
if err != nil {
log.Println(err)
utils.RenderTemplate(w, onDemandC.config.PageContext, err, "404.tmpl")
return
}
OnDemandM := models.NewOnDemandModel(onDemandC.session)
latestTimeslots, err := OnDemandM.GetLastMixcloudTimeslots()
if err != nil {
log.Println(err)
utils.RenderTemplate(w, onDemandC.config.PageContext, err, "404.tmpl")
return
}
data := struct {
LatestPodcasts []myradio.Podcast
LatestTimeslots []myradio.Timeslot
}{
LatestPodcasts: latestPodcasts,
LatestTimeslots: latestTimeslots,
}
err = utils.RenderTemplate(w, onDemandC.config.PageContext, data, "on_demand.tmpl")
if err != nil {
log.Println(err)
return
}
}