sprechstunden-go/controllers/deleteOfficeHourHandler.go

31 lines
936 B
Go
Raw Normal View History

2022-09-05 18:10:35 +00:00
// deleteOfficeHourHandler
package controllers
import (
"net/http"
"officeHours/models"
"officeHours/templating"
2022-09-05 18:10:35 +00:00
"strconv"
)
func (b *BaseHandler) DeleteOfficeHourHandler(w http.ResponseWriter, req *http.Request) {
// TODO: error handling here is by no means sufficient, furthermore
// 400 BadRequest is for technically wrong stuff (most promimently GET instead of POST)
2022-09-05 18:10:35 +00:00
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)
templating.ServeTemplate(w, "deleteSuccess", nil)
2022-09-05 18:10:35 +00:00
} else {
officeHours, _ := b.officeHourRepo.GetAll(true)
timetable, slots := b.GetTimetable(officeHours)
b.writeTimetablePage(w, req, b.printTimetable(timetable, slots, true))
2022-09-05 18:10:35 +00:00
}
}