diff --git a/main.go b/main.go index d5002ed..6726ed0 100644 --- a/main.go +++ b/main.go @@ -357,6 +357,34 @@ func main() { sendJSON(w, podcasts, 200) }) + mux.HandleFunc("GET /podcasts/{id}", func(w http.ResponseWriter, r *http.Request) { + id, err := strconv.Atoi(r.PathValue("id")) + if err != nil { + http.Error(w, err.Error(), 404) + return + } + + podcast, err := getPodcastById(db, int64(id)) + if err != nil { + http.Error(w, err.Error(), 404) + return + } + + episodes, err := getPodcastEpisodes(db, podcast.ID) + if err != nil { + http.Error(w, err.Error(), 404) + return + } + + tmpl.ExecuteTemplate(w, "podcast.html", struct { + Podcast *Podcast + Episodes []*Episode + }{ + Podcast: podcast, + Episodes: episodes, + }) + }) + mux.HandleFunc("POST /podcasts", func(w http.ResponseWriter, r *http.Request) { var body struct { Feed string `json:"feed"` diff --git a/views/podcast.html b/views/podcast.html new file mode 100644 index 0000000..a853b67 --- /dev/null +++ b/views/podcast.html @@ -0,0 +1,67 @@ + + +
+ + +{{.Podcast.Description}}
+