sprechstunden-go/controllers/deleteOfficeHourHandler.go
2022-09-05 20:10:35 +02:00

29 lines
840 B
Go

// deleteOfficeHourHandler
package controllers
import (
"html/template"
"net/http"
"sprechstundentool/models"
"strconv"
)
func (b *BaseHandler) DeleteOfficeHourHandler(w http.ResponseWriter, req *http.Request) {
if req.FormValue("id") != "" {
id, err := strconv.Atoi(req.FormValue("id"))
if err != nil {
w.WriteHeader(http.StatusBadRequest)
}
officeHour, err := b.officeHourRepo.FindById(id)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
}
_, err = b.requestRepo.Add(officeHour, models.RequestDelete)
tmpl, _ := template.New("deleteSuccess.html").ParseFiles("templates/deleteSuccess.html")
tmpl.Execute(w, struct{}{})
} else {
officeHours, _ := b.officeHourRepo.GetAll(true)
timetable, slots := GetTimetable(officeHours)
b.writeTimetablePage(w, req, printTimetable(timetable, slots, true))
}
}