Files

45 lines
1.2 KiB
Go

package web
import (
"net/http"
"git.noroutes.net/NoRoutes/vibetunes/internal/database"
)
func (h *Web) handleRadio(w http.ResponseWriter, r *http.Request) {
stations, err := database.ListRadioStations(h.DB)
if err != nil {
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
h.page(w, r, "radio", "radio", "Internet Radio", stations)
}
func (h *Web) handleRadioCreate(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
name := r.FormValue("name")
streamURL := r.FormValue("stream_url")
homepage := r.FormValue("homepage_url")
if name == "" || streamURL == "" {
http.Redirect(w, r, "/radio", http.StatusFound)
return
}
if _, err := database.CreateRadioStation(h.DB, name, streamURL, homepage); err != nil {
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/radio", http.StatusFound)
}
func (h *Web) handleRadioDelete(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
if err := database.DeleteRadioStation(h.DB, id); err != nil {
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/radio", http.StatusFound)
}